List of usage examples for java.io File isHidden
public boolean isHidden()
From source file:org.ow2.mind.doc.DocumentationIndexGenerator.java
private void exploreDirectory(final File rootDirectory, final File directory) throws IOException { if (directory.isHidden()) return;/*www .ja va 2 s . c o m*/ final List<IndexEntry> packageADLDefinition = new LinkedList<IndexEntry>(); final List<IndexEntry> packageITFDefinition = new LinkedList<IndexEntry>(); for (final File file : directory.listFiles((FileFilter) FileFilterUtils.suffixFileFilter(".adl"))) { final IndexEntry entry = IndexEntry.createADLEntry(rootDirectory, file); adlDefinitionEntries.add(entry); packageADLDefinition.add(entry); } for (final File file : directory.listFiles((FileFilter) FileFilterUtils.suffixFileFilter(".itf"))) { final IndexEntry entry = IndexEntry.createITFEntry(rootDirectory, file); itfDefinitionEntries.add(entry); packageITFDefinition.add(entry); } if (!packageADLDefinition.isEmpty() || !packageITFDefinition.isEmpty()) { packages.add(IndexEntry.createPackageEntry(rootDirectory, directory, packageADLDefinition, packageITFDefinition)); Collections.sort(packageADLDefinition, new IndexEntryComparatorNoPackage()); Collections.sort(packageITFDefinition, new IndexEntryComparatorNoPackage()); } for (final File subDirectory : directory.listFiles(new FileFilter() { public boolean accept(final File pathname) { return pathname.isDirectory(); } })) { exploreDirectory(rootDirectory, subDirectory); } }
From source file:eu.esdihumboldt.util.resource.scavenger.AbstractResourceScavenger.java
/** * @see ResourceScavenger#triggerScan()//from w w w . j av a2 s . co m */ @Override public void triggerScan() { synchronized (resources) { if (huntingGrounds != null) { if (huntingGrounds.isDirectory()) { // scan for sub-directories Set<String> foundIds = new HashSet<String>(); File[] resourceDirs = huntingGrounds.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { // accept non-hidden directories return pathname.isDirectory() && !pathname.isHidden(); } }); for (File resourceDir : resourceDirs) { String resourceId = resourceDir.getName(); foundIds.add(resourceId); if (!resources.containsKey(resourceId)) { // resource reference not loaded yet T handler; try { handler = loadReference(resourceDir, null, resourceId); resources.put(resourceId, handler); } catch (IOException e) { log.error("Error creating resource reference", e); } } else { // update existing resource updateResource(resources.get(resourceId), resourceId); } } Set<String> removed = new HashSet<String>(resources.keySet()); removed.removeAll(foundIds); // deal with resources that have been removed for (String resourceId : removed) { T reference = resources.remove(resourceId); if (reference != null) { // remove active environment onRemove(reference, resourceId); } } } else { // one project mode if (!resources.containsKey(DEFAULT_RESOURCE_ID)) { // project configuration not loaded yet T handler; try { handler = loadReference(huntingGrounds.getParentFile(), huntingGrounds.getName(), DEFAULT_RESOURCE_ID); resources.put(DEFAULT_RESOURCE_ID, handler); } catch (IOException e) { log.error("Error creating project handler", e); } } else { // update existing project updateResource(resources.get(DEFAULT_RESOURCE_ID), DEFAULT_RESOURCE_ID); } } } } }
From source file:com.psaravan.filebrowserview.lib.FileBrowserEngine.FileBrowserEngine.java
/** * Loads the specified folder./* www. j a va 2 s. com*/ * * @param directory The file object to points to the directory to load. * @return An {@link AdapterData} object that holds the data of the specified directory. */ public AdapterData loadDir(File directory) { mCurrentDir = directory; //Init the directory's data arrays. ArrayList<String> namesList = new ArrayList<String>(); ArrayList<String> pathsList = new ArrayList<String>(); ArrayList<Integer> typesList = new ArrayList<Integer>(); ArrayList<String> sizesList = new ArrayList<String>(); //Grab a list of all files/subdirs within the specified directory. File[] files = directory.listFiles(); if (files != null) { //Sort the files/subdirs by name. Arrays.sort(files, NameFileComparator.NAME_INSENSITIVE_COMPARATOR); for (int i = 0; i < files.length; i++) { File file = files[i]; if ((!file.isHidden() || mFileBrowserView.shouldShowHiddenFiles()) && file.canRead()) { if (file.isDirectory() && mFileBrowserView.shouldShowFolders()) { /* * Starting with Android 4.2, /storage/emulated/legacy/... * is a symlink that points to the actual directory where * the user's files are stored. We need to detect the * actual directory's file path here. */ String filePath; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) filePath = getRealFilePath(file.getAbsolutePath()); else filePath = file.getAbsolutePath(); pathsList.add(filePath); namesList.add(file.getName()); File[] listOfFiles = file.listFiles(); if (listOfFiles != null) { typesList.add(FOLDER); if (listOfFiles.length == 1) { sizesList.add("" + listOfFiles.length + " item"); } else { sizesList.add("" + listOfFiles.length + " items"); } } else { typesList.add(FOLDER); sizesList.add("Unknown items"); } } else { try { String path = file.getCanonicalPath(); //Check if the file ends with an excluded extension. String[] splits = path.split("."); if (mFileBrowserView.getFileExtensionFilter().getFilterMap() .containsKey("." + splits[splits.length - 1])) continue; pathsList.add(path); } catch (IOException e) { continue; } namesList.add(file.getName()); String fileName = ""; try { fileName = file.getCanonicalPath(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } //Add the file element to typesList based on the file type. if (getFileExtension(fileName).equalsIgnoreCase("mp3") || getFileExtension(fileName).equalsIgnoreCase("3gp") || getFileExtension(fileName).equalsIgnoreCase("mp4") || getFileExtension(fileName).equalsIgnoreCase("m4a") || getFileExtension(fileName).equalsIgnoreCase("aac") || getFileExtension(fileName).equalsIgnoreCase("ts") || getFileExtension(fileName).equalsIgnoreCase("flac") || getFileExtension(fileName).equalsIgnoreCase("mid") || getFileExtension(fileName).equalsIgnoreCase("xmf") || getFileExtension(fileName).equalsIgnoreCase("mxmf") || getFileExtension(fileName).equalsIgnoreCase("midi") || getFileExtension(fileName).equalsIgnoreCase("rtttl") || getFileExtension(fileName).equalsIgnoreCase("rtx") || getFileExtension(fileName).equalsIgnoreCase("ota") || getFileExtension(fileName).equalsIgnoreCase("imy") || getFileExtension(fileName).equalsIgnoreCase("ogg") || getFileExtension(fileName).equalsIgnoreCase("mkv") || getFileExtension(fileName).equalsIgnoreCase("wav")) { //The file is an audio file. typesList.add(FILE_AUDIO); sizesList.add("" + getFormattedFileSize(file.length())); } else if (getFileExtension(fileName).equalsIgnoreCase("jpg") || getFileExtension(fileName).equalsIgnoreCase("gif") || getFileExtension(fileName).equalsIgnoreCase("png") || getFileExtension(fileName).equalsIgnoreCase("bmp") || getFileExtension(fileName).equalsIgnoreCase("webp")) { //The file is a picture file. typesList.add(FILE_PICTURE); sizesList.add("" + getFormattedFileSize(file.length())); } else if (getFileExtension(fileName).equalsIgnoreCase("3gp") || getFileExtension(fileName).equalsIgnoreCase("mp4") || getFileExtension(fileName).equalsIgnoreCase("3gp") || getFileExtension(fileName).equalsIgnoreCase("ts") || getFileExtension(fileName).equalsIgnoreCase("webm") || getFileExtension(fileName).equalsIgnoreCase("mkv")) { //The file is a video file. typesList.add(FILE_VIDEO); sizesList.add("" + getFormattedFileSize(file.length())); } else { //We don't have an icon for this file type so give it the generic file flag. typesList.add(FILE_GENERIC); sizesList.add("" + getFormattedFileSize(file.length())); } } } } } return new AdapterData(namesList, typesList, pathsList, sizesList); }
From source file:org.hashsplit4j.api.BerkeleyDbBlobStore.java
/** * Import any files into blob store//from w w w .j a v a 2 s. c o m * * @param file * the give file * @return * number of file have been imported */ private int importFile(File file) { if (!file.exists()) { logger.warn("No such directory " + file.getAbsolutePath()); } int total = 0; if (!file.isHidden()) { String hash = file.getName(); if (hash.matches("[a-fA-F0-9]{40}")) { try { logger.info("Importing contents of file " + file.getName() + " into BerkeleyDB"); byte[] contents = FileUtils.readFileToByteArray(file); // Put its contents into BerkeleyDB setBlob(hash, contents); // Only one Blob has been imported to BerkeleyDB total += 1; return total; } catch (IOException ex) { logger.error("Could not read contents for the give file " + file.getAbsolutePath()); } } else { logger.warn("The text " + hash + " is not SHA1 or MD5 string, " + "It should get SHA1 of its contents."); } } return total; }
From source file:com.sangupta.httpd.HttpdHandler.java
/** * Send file contents back to client/* w ww . java2s .c om*/ * * @param request * @param response * @param uri * @throws IOException */ private void sendFileContents(HttpServletRequest request, HttpServletResponse response, String uri) throws IOException { File file = new File(documentRoot, uri); if (!file.exists() || file.isHidden()) { response.sendError(HttpStatusCode.NOT_FOUND); return; } if (file.isDirectory()) { response.sendRedirect("/" + uri + "/"); return; } if (!file.isFile()) { response.sendError(HttpStatusCode.FORBIDDEN); return; } String etag = null; if (!this.httpdConfig.noEtag) { // compute the weak ETAG based on file time and size final long time = file.lastModified(); final long size = file.length(); final String name = file.getName(); etag = "w/" + HashUtils.getMD5Hex(name + ":" + size + ":" + time); } // check for if-modified-since header name String ifModifiedSince = request.getHeader("If-Modified-Since"); if (ifModifiedSince != null && !ifModifiedSince.isEmpty()) { Date ifModifiedSinceDate = parseDateHeader(ifModifiedSince); if (ifModifiedSinceDate != null) { // 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) { response.setStatus(HttpStatusCode.NOT_MODIFIED); return; } } } // add mime-header - based on the file extension response.setContentType(MimeUtils.getMimeTypeForFileExtension(FilenameUtils.getExtension(file.getName()))); response.setDateHeader("Last-Modified", file.lastModified()); // check for no cache if (this.httpdConfig.noCache) { response.addHeader("Cache-Control", "no-store, no-cache, must-revalidate"); } // check for no-sniff if (this.httpdConfig.noSniff) { response.addHeader("X-Content-Type-Options", "nosniff"); } // etag if (!this.httpdConfig.noEtag) { response.addHeader("Etag", etag); } // send back file contents response.setContentLength((int) file.length()); IOUtils.copyLarge(FileUtils.openInputStream(file), response.getOutputStream()); }
From source file:org.saiku.web.rest.resources.BasicTagRepositoryResource.java
@GET @Path("/{cubeIdentifier}") @Produces({ "application/json" }) public List<SaikuTag> getSavedTags(@PathParam("cubeIdentifier") String cubeIdentifier) { List<SaikuTag> allTags = new ArrayList<SaikuTag>(); try {//w w w . j a v a2s. c o m if (repo != null) { File[] files = new File(repo.getName().getPath()).listFiles(); for (File file : files) { if (!file.isHidden()) { String filename = file.getName(); if (filename.endsWith(".tag")) { filename = filename.substring(0, filename.length() - ".tag".length()); if (filename.equals(cubeIdentifier)) { FileReader fi = new FileReader(file); BufferedReader br = new BufferedReader(fi); ObjectMapper om = new ObjectMapper(); om.setVisibilityChecker( om.getVisibilityChecker().withFieldVisibility(Visibility.ANY)); List<SaikuTag> tags = om.readValue(file, TypeFactory.collectionType(ArrayList.class, SaikuTag.class)); allTags.addAll(tags); } } } } } else { throw new Exception("repo URL is null"); } } catch (Exception e) { log.error(this.getClass().getName(), e); e.printStackTrace(); } Collections.sort(allTags); return allTags; }
From source file:com.fer.hr.service.datasource.ClassPathResourceDatasourceManager.java
public void load() { datasources.clear();//from www . j a va 2s .co m try { if (repoURL != null) { File[] files = new File(repoURL.getFile()).listFiles(); for (File file : files) { if (!file.isHidden()) { Properties props = new Properties(); props.load(new FileInputStream(file)); String name = props.getProperty("name"); String type = props.getProperty("type"); if (name != null && type != null) { Type t = SaikuDatasource.Type.valueOf(type.toUpperCase()); SaikuDatasource ds = new SaikuDatasource(name, t, props); datasources.put(name, ds); } } } } else { throw new Exception("repo URL is null"); } } catch (Exception e) { throw new SaikuServiceException(e.getMessage(), e); } }
From source file:com.Duo.music.player.SettingsActivity.SettingsMusicFoldersDialog.java
/** * Retrieves the folder hierarchy for the specified folder * (this method is NOT recursive and doesn't go into the parent * folder's subfolders. // w ww . j a va2 s . co m */ private void getDir(String dirPath) { mFileFolderNamesList = new ArrayList<String>(); mFileFolderPathsList = new ArrayList<String>(); mFileFolderSizesList = new ArrayList<String>(); File f = new File(dirPath); File[] files = f.listFiles(); Arrays.sort(files); if (files != null) { for (int i = 0; i < files.length; i++) { File file = files[i]; if (!file.isHidden() && file.canRead()) { if (file.isDirectory()) { /* * Starting with Android 4.2, /storage/emulated/legacy/... * is a symlink that points to the actual directory where * the user's files are stored. We need to detect the * actual directory's file path here. */ String filePath; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) filePath = getRealFilePath(file.getAbsolutePath()); else filePath = file.getAbsolutePath(); mFileFolderPathsList.add(filePath); mFileFolderNamesList.add(file.getName()); File[] listOfFiles = file.listFiles(); if (listOfFiles != null) { if (listOfFiles.length == 1) { mFileFolderSizesList.add("" + listOfFiles.length + " item"); } else { mFileFolderSizesList.add("" + listOfFiles.length + " items"); } } } } } } boolean dirChecked = false; //Get the directory and the parent dir. String concatatedString = ""; int secondSlashIndex = dirPath.lastIndexOf("/", dirPath.lastIndexOf("/") - 1); if ((secondSlashIndex < dirPath.length()) && secondSlashIndex != -1) concatatedString = dirPath.substring(secondSlashIndex, dirPath.length()); if (getMusicFoldersHashMap().get(concatatedString) != null) dirChecked = getMusicFoldersHashMap().get(concatatedString); SettingsMultiselectAdapter mFoldersListViewAdapter = new SettingsMultiselectAdapter(getActivity(), this, mWelcomeSetup, dirChecked); mFoldersListView.setAdapter(mFoldersListViewAdapter); mFoldersListViewAdapter.notifyDataSetChanged(); mCurrentDir = dirPath; setCurrentDirText(); }
From source file:com.otway.picasasync.syncutil.AlbumSync.java
private void updateFolderTimeStamp(File localFolder) { long maxDate = 0; File[] files = localFolder.listFiles(new FilenameFilter() { public boolean accept(File current, String name) { File file = new File(current, name); return file.isFile() && !file.isHidden(); }/*from w w w . java 2 s. co m*/ }); if (files != null) { for (File file : files) if (file.lastModified() > maxDate) maxDate = file.lastModified(); if (!localFolder.setLastModified(maxDate)) log.debug("Unable to set modification date for " + localFolder); } }
From source file:io.proleap.cobol.asg.runner.impl.CobolParserRunnerImpl.java
protected void parseFile(final File inputFile, final Program program, final CobolSourceFormat format, final CobolDialect dialect) throws IOException { if (!inputFile.isFile()) { LOG.warn("Could not find file {}", inputFile.getAbsolutePath()); } else if (inputFile.isHidden()) { LOG.warn("Ignoring hidden file {}", inputFile.getAbsolutePath()); } else if (!isCobolFile(inputFile)) { LOG.info("Ignoring file {} because of file extension.", inputFile.getAbsolutePath()); } else {/*from w w w .jav a2 s .c om*/ final File libDirectory = inputFile.getParentFile(); // preprocess input stream final String preProcessedInput = CobolGrammarContext.getInstance().getCobolPreprocessor() .process(inputFile, libDirectory, format, dialect); LOG.info("Parsing file {}.", inputFile.getName()); // run the lexer final Cobol85Lexer lexer = new Cobol85Lexer(new ANTLRInputStream(preProcessedInput)); // get a list of matched tokens final CommonTokenStream tokens = new CommonTokenStream(lexer); // pass the tokens to the parser final Cobol85Parser parser = new Cobol85Parser(tokens); // specify our entry point final StartRuleContext ctx = parser.startRule(); // determine the copy book name final String compilationUnitName = getCompilationUnitName(inputFile); // analyze contained copy books final ParserVisitor visitor = new CobolCompilationUnitVisitorImpl(program, compilationUnitName); LOG.info("Collecting units in file {}.", inputFile.getName()); visitor.visit(ctx); } }