List of usage examples for java.io File isHidden
public boolean isHidden()
From source file:org.wso2.balana.finder.impl.FileBasedPolicyFinderModule.java
/** * Re-sets the policies known to this module to those contained in the * given files.// w w w . ja va2s . c o m * */ public void loadPolicies() { policies.clear(); for (String policyLocation : policyLocations) { File file = new File(policyLocation); if (!file.exists()) { continue; } if (file.isDirectory()) { String[] files = file.list(); if (files != null) { for (String policyFileLocation : files) { File policyFile = new File(policyLocation + File.separator + policyFileLocation); // we check for hidden files to avoid hidden OS files. if (!policyFile.isDirectory() && !policyFile.isHidden()) { loadPolicy(policyLocation + File.separator + policyFileLocation, finder); } } } } else { loadPolicy(policyLocation, finder); } } }
From source file:ome.services.scripts.ScriptRepoHelper.java
/** * Returns the number of files which match {@link #SCRIPT_FILTER} in * {@link #dir}. Uses {@link #iterate()} internally. *///ww w. ja v a2 s .co m public int countOnDisk() { int size = 0; Iterator<File> it = iterate(); while (it.hasNext()) { File f = it.next(); if (f.canRead() && f.isFile() && !f.isHidden()) { size++; } } return size; }
From source file:com.antelink.sourcesquare.client.scan.SourceSquareFSWalker.java
private TreemapNode reccursiveIdentifyFiles(File directory, TreeSet<File> fileSet, int depth) { if (this.levels.size() < depth + 1) { this.levels.add(0); }//from ww w .j av a2 s . c o m logger.trace("Counting going down to directory : " + directory.getAbsolutePath()); if (directory.isHidden()) { this.eventBus.fireEvent(new HiddenFileFoundEvent(directory)); return null; } if (directory.isFile()) { fileSet.add(directory); return null; } if (!directory.isDirectory()) { return null; } // Protection if the directory forbids listing if (directory.listFiles() == null) { return null; } Set<TreemapNode> children = new HashSet<TreemapNode>(); int nbFiles = 0; int nbDirs = 0; for (File child : directory.listFiles()) { if (child.isDirectory() || !child.isHidden()) { if (child.isDirectory()) { nbDirs++; TreemapNode childNode = reccursiveIdentifyFiles(child, fileSet, depth + 1); if (childNode != null) { children.add(childNode); } } else if (child.isFile()) { nbFiles++; fileSet.add(child); } } } this.total = this.total + nbFiles; ScanStatus.INSTANCE.setNbFilesToScan((int) this.total); this.levels.set(depth, this.levels.get(depth) + nbDirs); return this.treemap.createTreeMapNode(directory.getAbsolutePath(), children, nbFiles); }
From source file:org.apache.taverna.commandline.TavernaCommandLineTest.java
private void assertFilesEqual(File file1, File file2, boolean checkFileContents) { if (file1.isHidden()) { assertTrue(String.format("%s is hidden but %s is not", file1, file2), file2.isHidden()); } else {/* w w w .j a va2 s . c om*/ assertFalse(String.format("%s is not hidden but %s is", file1, file2), file2.isHidden()); assertEquals(file1.getName(), file2.getName()); if (file1.isDirectory()) { assertTrue(String.format("%s is a directory but %s is not", file1, file2), file2.isDirectory()); assertDirectoriesEquals(file1, file2, checkFileContents); } else { assertFalse(String.format("%s is not a directory but %s is", file1, file2), file2.isDirectory()); if (isZipFile(file1)) { assertZipFilesEqual(file1, file2); } else if (checkFileContents) { assertEquals(String.format("%s is a different length to %s", file1, file2), file1.length(), file2.length()); try { byte[] byteArray1 = IOUtils.toByteArray(new FileReader(file1)); byte[] byteArray2 = IOUtils.toByteArray(new FileReader(file2)); assertArrayEquals(String.format("%s != %s", file1, file2), byteArray1, byteArray2); } catch (FileNotFoundException e) { fail(e.getMessage()); } catch (IOException e) { fail(e.getMessage()); } } } } }
From source file:dk.defxws.fgssolrremote.OperationsImpl.java
private void indexDocs(File file, String repositoryName, String indexName, StringBuffer resultXml, String indexDocXslt) throws java.rmi.RemoteException { if (file.isHidden()) return;/*from w w w . j a v a2 s . co m*/ if (file.isDirectory()) { String[] files = file.list(); for (int i = 0; i < files.length; i++) { if (i % 100 == 0) logger.info("updateIndex fromFoxmlFiles " + file.getAbsolutePath() + " docCount=" + docCount); indexDocs(new File(file, files[i]), repositoryName, indexName, resultXml, indexDocXslt); } } else { try { indexDoc(getPidFromObjectFilename(file.getName()), repositoryName, indexName, new FileInputStream(file), resultXml, indexDocXslt); } catch (RemoteException | FileNotFoundException e) { String message = String.format("<warning no=\"%d\">file=%s exception=%s</warning>", ++warnCount, escapeXml11(file.getAbsolutePath()), escapeXml11(e.toString())); resultXml.append(message); logger.warn(message); } } }
From source file:org.chililog.server.workbench.StaticFileRequestHandler.java
/** * Process the message/* w ww . j ava 2 s . c o m*/ */ @Override public void processMessage(ChannelHandlerContext ctx, MessageEvent e) throws Exception { HttpRequest request = (HttpRequest) e.getMessage(); // We don't handle 100 Continue because we only allow GET method. if (request.getMethod() != HttpMethod.GET) { sendError(ctx, e, METHOD_NOT_ALLOWED, null); return; } // Check final String filePath = convertUriToPhysicalFilePath(request.getUri()); if (filePath == null) { sendError(ctx, e, FORBIDDEN, null); return; } File file = new File(filePath); if (file.isHidden() || !file.exists()) { sendError(ctx, e, NOT_FOUND, String.format("%s not exist", file.getCanonicalPath())); return; } if (!file.isFile()) { sendError(ctx, e, FORBIDDEN, String.format("%s not a file", file.getCanonicalPath())); return; } // Cache Validation String ifModifiedSince = request.getHeader(HttpHeaders.Names.IF_MODIFIED_SINCE); if (!StringUtils.isBlank(ifModifiedSince)) { SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US); Date ifModifiedSinceDate = dateFormatter.parse(ifModifiedSince); // Only compare up to the second because the datetime format we send to the client does not have milliseconds long ifModifiedSinceDateSeconds = ifModifiedSinceDate.getTime() / 1000; long fileLastModifiedSeconds = file.lastModified() / 1000; if (ifModifiedSinceDateSeconds == fileLastModifiedSeconds) { sendNotModified(ctx, e); return; } } // Open file for sending back RandomAccessFile raf; try { raf = new RandomAccessFile(file, "r"); } catch (FileNotFoundException fnfe) { sendError(ctx, e, NOT_FOUND, null); return; } long fileLength = raf.length(); // Log writeLogEntry(e, OK, null); // Create the response HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK); setContentLength(response, fileLength); setContentTypeHeader(response, file); setDateAndCacheHeaders(response, file); // Write the content. Channel ch = e.getChannel(); ChannelFuture writeFuture; if (AppProperties.getInstance().getWorkbenchSslEnabled()) { // Cannot use zero-copy with HTTPS // Write the initial line and the header. ch.write(response); // Write chunks writeFuture = ch.write(new ChunkedFile(raf, 0, fileLength, 8192)); } else { // Now that we are using Execution Handlers, we cannot do zero-copy. // Do as per with compression (which is what most browser will ask for) byte[] buffer = new byte[(int) fileLength]; raf.readFully(buffer); raf.close(); response.setContent(ChannelBuffers.copiedBuffer(buffer)); writeFuture = ch.write(response); /* * // No encryption - use zero-copy. // However zero-copy does not seem to work with compression // Only use * zero-copy for large files like movies and music // Write the initial line and the header. * ch.write(response); // Zero-copy final FileRegion region = new DefaultFileRegion(raf.getChannel(), 0, * fileLength); writeFuture = ch.write(region); writeFuture.addListener(new ChannelFutureProgressListener() * { public void operationComplete(ChannelFuture future) { region.releaseExternalResources(); } public void * operationProgressed(ChannelFuture future, long amount, long current, long total) { * _logger.debug("Zero-Coping file %s: %d / %d (+%d) bytes", filePath, current, total, amount); } }); */ } // Decide whether to close the connection or not. if (!isKeepAlive(request)) { // Close the connection when the whole content is written out. writeFuture.addListener(ChannelFutureListener.CLOSE); } }
From source file:net.landora.videoplayer.files.GeneralDirectoryMenu.java
@Override protected void refreshImpl() { links = new ArrayList<MenuLink>(); File[] children = dir.listFiles((FileFilter) FileFilterUtils.directoryFileFilter()); if (children != null && children.length > 0) { Arrays.sort(children, new FileSorter()); for (File child : children) { links.add(new MenuLink(Icon.Folder, child.getName(), new GeneralDirectoryMenu(child))); }/* w ww .j av a2 s .co m*/ } children = dir.listFiles((FileFilter) FileFilterUtils.notFileFilter(FileFilterUtils.directoryFileFilter())); if (children != null & children.length != 0) { Arrays.sort(children, new FileSorter()); for (File child : children) { if (child.isHidden() || !child.isFile() || !ExtensionUtils.isVideoExtension(child)) { continue; } links.add(new MenuLink(Icon.File, child.getName(), new PlayFileAction(child))); } } }
From source file:org.codice.ddf.commands.catalog.IngestCommand.java
private void buildQueue(Stream<Path> ingestStream, ArrayBlockingQueue<Metacard> metacardQueue, long start) { ingestStream.filter(a -> !a.toFile().isDirectory()).forEach(a -> { File file = a.toFile(); if (file.isHidden()) { ignoreCount.incrementAndGet(); } else {//w w w . j a v a 2 s .c o m String extension = file.getName(); if (extension.contains(".")) { int x = extension.indexOf('.'); extension = extension.substring(x); } if (ignoreList != null && (ignoreList.contains(extension) || ignoreList.contains(file.getName()))) { ignoreCount.incrementAndGet(); printProgressAndFlush(start, fileCount.get(), ingestCount.get() + ignoreCount.get()); } else { Metacard result; try { result = readMetacard(file); } catch (IngestException e) { result = null; logIngestException(e, file); if (failedIngestDirectory != null) { moveToFailedIngestDirectory(file); } printErrorMessage("Failed to ingest file [" + file.getAbsolutePath() + "]."); if (INGEST_LOGGER.isWarnEnabled()) { INGEST_LOGGER.warn("Failed to ingest file [{}].", file.getAbsolutePath()); } } if (result != null) { try { metacardQueue.put(result); } catch (InterruptedException e) { INGEST_LOGGER.error("Thread interrupted while waiting to 'put' metacard: {}", e); } } } } }); doneBuildingQueue.set(true); }
From source file:com.appspresso.api.fs.DefaultFile.java
/** * {@inheritDoc}//from w ww . j a v a2 s .c o m * */ @Override public AxFile[] listFiles(AxFileFilter filter) { if (isHiddenFile(peer)) return null; String[] fileArray = peer.list(); if (null == fileArray) return null; int length = fileArray.length; ArrayList<AxFile> axFileList = new ArrayList<AxFile>(); File newFile; AxFile newAxFile; if (filter == null) { for (int i = 0; i < length; i++) { newFile = new File(peer, fileArray[i]); if (newFile.isHidden()) continue; newAxFile = fileSystem.createDefaultFile(newFile); axFileList.add(newAxFile); } } else { for (int i = 0; i < length; i++) { newFile = new File(peer, fileArray[i]); if (newFile.isHidden()) continue; newAxFile = fileSystem.createDefaultFile(newFile); if (filter.acceptFile(newAxFile)) axFileList.add(newAxFile); } } return axFileList.toArray(new AxFile[axFileList.size()]); }
From source file:com.appeligo.showfiles.ShowFile.java
/** * @param request/*from ww w. j a va2 s .c o m*/ * @param out * @param path * @param f */ private void listFiles(HttpServletRequest request, PrintWriter out, String path, File f) { header(out, path); String[] filenames = f.list(); Arrays.sort(filenames); for (int i = 0; i < filenames.length; i++) { String filename = filenames[i]; String fullPathname = documentRoot + path + "/" + filename; File child = new File(fullPathname); if (child.isHidden()) { continue; } if (filename.endsWith(".flv")) { if (new File(fullPathname.replace(".flv", ".html.gz")).exists()) { continue; } } filename = filename.replace(":", "%3a"); if (!path.endsWith("/")) { path = path + "/"; } String displayName = filenames[i]; if (child.isDirectory()) { displayName += "/"; if (!filename.endsWith("/")) { filename = filename + "/"; } } if (filename.endsWith(".html.gz")) { if (new File(fullPathname.replace(".html.gz", ".flv")).exists()) { out.println("<a href=\"" + request.getContextPath() + "/ShowFlv" + //request.getServletPath()+ path + filename.replace(".html.gz", ".flv") + "\">" + "<img src=\"" + request.getContextPath() + "/skins/default/videoIcon.gif\" alt=\"video\"/>" + "</a>"); } String tsString = filename.substring(0, filename.indexOf('.')); try { long timestamp = Long.parseLong(tsString); DateFormat df = DateFormat.getTimeInstance(DateFormat.SHORT); df.setTimeZone(TimeZone.getTimeZone("GMT")); String time = df.format(new Date(timestamp)) + " - "; if (time.indexOf(':') == 1) { time = "0" + time; } out.print(time); } catch (NumberFormatException e) { } } else if (filename.endsWith(".flv") && (filename.indexOf(",") > 0)) { showPreview(request, out, path, filename); } out.print("<a href=\"" + request.getContextPath() + request.getServletPath() + path + filename + "\">" + displayName + "</a>"); if (filename.endsWith(".html.gz")) { BufferedReader r; try { r = new BufferedReader( new InputStreamReader(new GZIPInputStream(new FileInputStream(fullPathname)))); String line; while ((line = r.readLine()) != null) { if (line.startsWith("<title>")) { int nextLT = line.indexOf('<', 7); String title = line.substring(7, nextLT); out.print(" " + title); break; } } r.close(); } catch (FileNotFoundException e) { } catch (IOException e) { } } out.println("<br/>"); } footer(out); }