List of usage examples for java.io FileFilter getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:com.adaptris.core.fs.FsHelper.java
public static FileFilter logWarningIfRequired(FileFilter f) { try {/*from w w w . j av a 2 s. c om*/ Class clz = Class.forName("org.apache.oro.io.RegexFilenameFilter"); if (clz.isAssignableFrom(f.getClass())) { log.warn("{} is deprecated, use a java.util.regex.Pattern based filter instead", f.getClass().getCanonicalName()); } } catch (Exception e) { } return f; }
From source file:com.adaptris.core.fs.CompositeFileFilter.java
/** * @see java.io.FileFilter#accept(java.io.File) *///ww w . ja v a 2 s . c om @Override public boolean accept(File pathname) { int result = 0; for (FileFilter f : filters) { if (!quietMode) { log.trace("Checking {} is acceptable for {}", pathname.getAbsolutePath(), f.getClass().getSimpleName()); } result += f.accept(pathname) ? 1 : 0; } return result == filters.size(); }
From source file:com.adaptris.core.fs.FsHelperTest.java
@Test public void testCreateFilter() throws Exception { FileFilter filter = createFilter("", RegexFileFilter.class.getCanonicalName()); // no op filter. assertTrue(filter.accept(new File("build.gradle"))); assertNotEquals(RegexFileFilter.class, filter.getClass()); filter = createFilter(".*", RegexFileFilter.class.getCanonicalName()); assertEquals(RegexFileFilter.class, filter.getClass()); assertTrue(filter.accept(new File("build.gradle"))); // Just to fire the warning. assertEquals(AwkFilenameFilter.class, createFilter(".*", AwkFilenameFilter.class.getCanonicalName()).getClass()); }
From source file:hudson.FilePath.java
/** * List up files in this directory, just like {@link File#listFiles(FileFilter)}. * * @param filter//from ww w .java2s . c o m * The optional filter used to narrow down the result. * If non-null, must be {@link Serializable}. * If this {@link FilePath} represents a remote path, * the filter object will be executed on the remote machine. */ public List<FilePath> list(final FileFilter filter) throws IOException, InterruptedException { if (filter != null && !(filter instanceof Serializable)) { throw new IllegalArgumentException("Non-serializable filter of " + filter.getClass()); } return act(new FileCallable<List<FilePath>>() { public List<FilePath> invoke(File f, VirtualChannel channel) throws IOException { File[] children = f.listFiles(filter); if (children == null) return null; ArrayList<FilePath> r = new ArrayList<FilePath>(children.length); for (File child : children) r.add(new FilePath(child)); return r; } }, (filter != null ? filter : this).getClass().getClassLoader()); }
From source file:org.kawanfw.file.api.client.RemoteFileListExecutor.java
/** * // www .j a v a 2s .c o m * Executes a File.listFiles() or File.listFiles(FileFilter) on remote host. * * @param remoteFile * the file name of the directory on the host * @param filenameFilter * @param callerClassName * the class name that calls this method * @return the list of files or directories in the remote directory. Will be * <code>null</code> if the remote directory does not exists. Will * be empty if the remote directory exists but is empty. * * @throws IllegalArgumentException * if remoteFile is null * @throws InvalidLoginException * if the username is refused by the remote host * * @throws UnknownHostException * if host URL (http://www.acme.org) does not exists or no * Internet Connection. * @throws ConnectException * if the Host is correct but the {@code ServerFileManager} * Servlet is not reachable * (http://www.acme.org/ServerFileManager) and access failed * with a status != OK (200). (If the host is incorrect, or is * impossible to connect to - Tomcat down - the * {@code ConnectException} will be the sub exception * {@code HttpHostConnectException}.) * @throws SocketException * if network failure during transmission * @throws RemoteException * an exception has been thrown on the server side * @throws SecurityException * the url is not secured with https (SSL) * @throws IOException * for all other IO / Network / System Error * @throws IllegalAccessException * @throws InstantiationException */ public RemoteFile[] listFiles(String remoteFile, FilenameFilter filenameFilter, FileFilter fileFilter, String callerClassName) throws IllegalArgumentException, InvalidLoginException, UnknownHostException, ConnectException, SocketException, RemoteException, IOException, InstantiationException, IllegalAccessException { if (remoteFile == null) { throw new IllegalArgumentException("remoteFile can not be null!"); } if (username == null || authenticationToken == null) { throw new InvalidLoginException(FILE_SESSION_IS_CLOSED); } String filenameFilterFilename = null; String filenameFilterClassname = null; String base64SerialFilenameFilter = null; if (filenameFilter != null) { filenameFilterClassname = filenameFilter.getClass().getName(); base64SerialFilenameFilter = RemoteFileUtil.SerializeBase64FilenameFilter(filenameFilter, filenameFilterClassname); filenameFilterFilename = RemoteFileUtil.uploadFilterIfShortSize(base64SerialFilenameFilter, remoteSession); } String fileFilterFilename = null; String fileFilterClassname = null; String base64SerialFileFilter = null; if (fileFilter != null) { debug("after fileFilter() :" + fileFilter); fileFilterClassname = fileFilter.getClass().getName(); base64SerialFileFilter = RemoteFileUtil.SerializeBase64FileFilter(fileFilter, fileFilterClassname); fileFilterFilename = RemoteFileUtil.uploadFilterIfShortSize(base64SerialFileFilter, remoteSession); debug("after uploadFilter() :" + fileFilterFilename); } // Launch the Servlet // Prepare the request parameters List<SimpleNameValuePair> requestParams = new Vector<SimpleNameValuePair>(); requestParams.add(new SimpleNameValuePair(Parameter.ACTION, Action.FILE_LIST_FILES_ACTION)); requestParams.add(new SimpleNameValuePair(Parameter.USERNAME, username)); requestParams.add(new SimpleNameValuePair(Parameter.TOKEN, authenticationToken)); requestParams.add(new SimpleNameValuePair(Parameter.FILENAME, remoteFile)); requestParams.add(new SimpleNameValuePair(Parameter.FILENAME_FILTER_CLASSNAME, filenameFilterClassname)); requestParams.add(new SimpleNameValuePair(Parameter.FILENAME_FILTER_FILENAME, filenameFilterFilename)); if (RemoteFileUtil.isFilterShortSize(base64SerialFileFilter)) { requestParams.add( new SimpleNameValuePair(Parameter.BASE64_SERIAL_FILENAME_FILTER, base64SerialFilenameFilter)); } requestParams.add(new SimpleNameValuePair(Parameter.FILE_FILTER_CLASSNAME, fileFilterClassname)); requestParams.add(new SimpleNameValuePair(Parameter.FILE_FILTER_FILENAME, fileFilterFilename)); debug("fileFilterFilename: " + fileFilterFilename); if (RemoteFileUtil.isFilterShortSize(base64SerialFileFilter)) { requestParams.add(new SimpleNameValuePair(Parameter.BASE64_SERIAL_FILE_FILTER, base64SerialFileFilter)); } httpTransfer.setReceiveInFile(true); // To say we get the result into a // file httpTransfer.send(requestParams); // If everything is OK, we have in our protocol a response that // 1) starts with "OK". 2) Is followed by the authenticaiton token // else: response starts with "INVALID_LOGIN_OR_PASSWORD". File receiveFile = httpTransfer.getReceiveFile(); String receive = FrameworkFileUtil.getFirstLineOfFile(receiveFile); debug("receiveFile: " + receiveFile); // Content is OK if (receive.startsWith(ReturnCode.INVALID_LOGIN_OR_PASSWORD)) { if (!DEBUG && !KeepTempFilePolicyParms.KEEP_TEMP_FILE) { receiveFile.delete(); } throw new InvalidLoginException(FILE_SESSION_IS_CLOSED); } try { if (receive.equals("null")) { return null; } else if (receive.equals("[]")) { return new RemoteFile[0]; } else { List<String> listPathnames = getFilesListFromFile(receiveFile); List<RemoteFile> remoteFiles = new ArrayList<RemoteFile>(); for (String pathname : listPathnames) { // debug("pathname: " + pathname); RemoteFile theRemoteFile = new RemoteFile(this.remoteFile.getRemoteSession(), pathname); remoteFiles.add(theRemoteFile); } RemoteFile[] remoteFilearray = remoteFiles.toArray(new RemoteFile[listPathnames.size()]); return remoteFilearray; } } catch (Exception e) { throw new IOException(e.getMessage(), e); } finally { if (!DEBUG && !KeepTempFilePolicyParms.KEEP_TEMP_FILE) { receiveFile.delete(); } } }