/** * Opens zip entry or plain file and returns its input stream. */ public InputStream openInputStream() { if (zipFile != null) { try { inputStream = zipFile.getInputStream(zipEntry); return inputStream; } catch (IOException ioex) { throw new FindFileException("Input stream error: '" + zipFile.getName() + "', entry: '" + zipEntry.getName() + "'." , ioex); } } try { inputStream = new FileInputStream(file); return inputStream; } catch (FileNotFoundException fnfex) { throw new FindFileException("Unable to open: " + file.getAbsolutePath(), fnfex); } }
/** * Specifies the search path. Throws an exception if URI is invalid. */ public T searchPath(URI searchPath) { File file; try { file = new File(searchPath); } catch (Exception ex) { throw new FindFileException("URI error: " + searchPath, ex); } addPath(file); return (T) this; }
/** * Specifies the search path. Throws an exception if URI is invalid. */ public FindFile searchPath(final URI searchPath) { File file; try { file = new File(searchPath); } catch (Exception ex) { throw new FindFileException("URI error: " + searchPath, ex); } addPath(file); return this; }
/** * Opens zip entry or plain file and returns its input stream. */ public InputStream openInputStream() { if (inputStream != null) { return inputStream; } if (zipFile != null && zipEntry != null) { try { inputStream = zipFile.getInputStream(zipEntry); return inputStream; } catch (IOException ioex) { throw new FindFileException("Input stream error: '" + zipFile.getName() + "', entry: '" + zipEntry.getName() + "'." , ioex); } } if (file != null) { try { inputStream = new FileInputStream(file); return inputStream; } catch (FileNotFoundException fnfex) { throw new FindFileException("Unable to open: " + file.getAbsolutePath(), fnfex); } } throw new FindFileException("Unable to open stream: " + name()); }
/** * Specifies the search path. Throws an exception if URL is invalid. */ public T searchPath(URL searchPath) { File file = FileUtil.toFile(searchPath); if (file == null) { throw new FindFileException("URL error: " + searchPath); } addPath(file); return (T) this; }
/** * Scans URLs. If (#ignoreExceptions} is set, exceptions * per one URL will be ignored and loops continues. */ public ClassScanner scan(final URL... urls) { for (final URL url : urls) { final File file = FileUtil.toContainerFile(url); if (file == null) { if (!ignoreException) { throw new FindFileException("URL is not a valid file: " + url); } } else { filesToScan.add(file); } } return this; }
/** * Returns <code>true</code> if class contains {@link #getTypeSignatureBytes(Class) type signature}. * It searches the class content for bytecode signature. This is the fastest way of finding if come * class uses some type. Please note that if signature exists it still doesn't means that class uses * it in expected way, therefore, class should be loaded to complete the scan. */ protected boolean isTypeSignatureInUse(InputStream inputStream, byte[] bytes) { try { byte[] data = StreamUtil.readBytes(inputStream); int index = ArraysUtil.indexOf(data, bytes); return index != -1; } catch (IOException ioex) { throw new FindFileException("Read error", ioex); } }
/** * Scans single URL for classes and jar files. * Callback {@link #onEntry(EntryData)} is called on * each class name. */ protected void scanUrl(URL url) { File file = FileUtil.toFile(url); if (file == null) { if (!ignoreException) { throw new FindFileException("URL is not a valid file: " + url); } } scanPath(file); }
/** * Specifies the search path. Throws an exception if URL is invalid. */ public FindFile searchPath(final URL searchPath) { File file = FileUtil.toContainerFile(searchPath); if (file == null) { throw new FindFileException("URL error: " + searchPath); } addPath(file); return this; }
/** * Returns <code>true</code> if class contains {@link #bytecodeSignatureOfType(Class) type signature}. * It searches the class content for bytecode signature. This is the fastest way of finding if come * class uses some type. Please note that if signature exists it still doesn't means that class uses * it in expected way, therefore, class should be loaded to complete the scan. */ public boolean isTypeSignatureInUse(final byte[] bytes) { try { final byte[] data = readBytes(); final int index = ArraysUtil.indexOf(data, bytes); return index != -1; } catch (IOException ioex) { throw new FindFileException("Read error", ioex); } }
/** * If entry name is {@link #acceptEntry(String) accepted} invokes {@link #onEntry(EntryData)} a callback}. */ protected void scanEntry(EntryData entryData) { if (!acceptEntry(entryData.getName())) { return; } try { onEntry(entryData); } catch (Exception ex) { throw new FindFileException("Scan entry error: " + entryData, ex); } }
/** * If entry name is {@link #acceptEntry(String) accepted} invokes {@link #onEntry(ClassPathEntry)} a callback}. */ protected void scanEntry(final ClassPathEntry classPathEntry) { if (!acceptEntry(classPathEntry.name())) { return; } try { onEntry(classPathEntry); } catch (Exception ex) { throw new FindFileException("Scan entry error: " + classPathEntry, ex); } }
} catch (IOException ioex) { if (!ignoreException) { throw new FindFileException("Invalid zip: " + file.getName(), ioex);
} catch (IOException ioex) { if (!ignoreException) { throw new FindFileException("Invalid zip: " + file.getName(), ioex);
/** * Specifies the search path. Throws an exception if URI is invalid. */ public FindFile searchPath(final URI searchPath) { File file; try { file = new File(searchPath); } catch (Exception ex) { throw new FindFileException("URI error: " + searchPath, ex); } addPath(file); return this; }
/** * Opens zip entry or plain file and returns its input stream. */ public InputStream openInputStream() { if (inputStream != null) { return inputStream; } if (zipFile != null && zipEntry != null) { try { inputStream = zipFile.getInputStream(zipEntry); return inputStream; } catch (IOException ioex) { throw new FindFileException("Input stream error: '" + zipFile.getName() + "', entry: '" + zipEntry.getName() + "'." , ioex); } } if (file != null) { try { inputStream = new FileInputStream(file); return inputStream; } catch (FileNotFoundException fnfex) { throw new FindFileException("Unable to open: " + file.getAbsolutePath(), fnfex); } } throw new FindFileException("Unable to open stream: " + name()); }
/** * Scans URLs. If (#ignoreExceptions} is set, exceptions * per one URL will be ignored and loops continues. */ public ClassScanner scan(final URL... urls) { for (final URL url : urls) { final File file = FileUtil.toContainerFile(url); if (file == null) { if (!ignoreException) { throw new FindFileException("URL is not a valid file: " + url); } } else { filesToScan.add(file); } } return this; }
/** * Specifies the search path. Throws an exception if URL is invalid. */ public FindFile searchPath(final URL searchPath) { File file = FileUtil.toContainerFile(searchPath); if (file == null) { throw new FindFileException("URL error: " + searchPath); } addPath(file); return this; }
/** * Returns <code>true</code> if class contains {@link #bytecodeSignatureOfType(Class) type signature}. * It searches the class content for bytecode signature. This is the fastest way of finding if come * class uses some type. Please note that if signature exists it still doesn't means that class uses * it in expected way, therefore, class should be loaded to complete the scan. */ public boolean isTypeSignatureInUse(final byte[] bytes) { try { final byte[] data = readBytes(); final int index = ArraysUtil.indexOf(data, bytes); return index != -1; } catch (IOException ioex) { throw new FindFileException("Read error", ioex); } }
/** * If entry name is {@link #acceptEntry(String) accepted} invokes {@link #onEntry(ClassPathEntry)} a callback}. */ protected void scanEntry(final ClassPathEntry classPathEntry) { if (!acceptEntry(classPathEntry.name())) { return; } try { onEntry(classPathEntry); } catch (Exception ex) { throw new FindFileException("Scan entry error: " + classPathEntry, ex); } }