List of usage examples for java.io File isHidden
public boolean isHidden()
From source file:com.github.fritaly.dualcommander.DirectoryBrowser.java
public void setDirectory(File directory) { Validate.notNull(directory, "The given directory is null"); Validate.isTrue(directory.exists(),//w ww. j a va2s. co m String.format("The given directory '%s' doesn't exist", directory.getAbsolutePath())); Validate.isTrue(directory.isDirectory(), String.format("The given path '%s' doesn't denote a directory", directory.getAbsolutePath())); final File oldDir = this.directory; this.directory = directory; // Refresh the UI // Display the (normalized) canonical path directoryButton.setText(getCanonicalPath(directory)); this.tableModel.clear(); // Populate the list with the directory's entries for (File file : directory.listFiles()) { if (!file.isHidden() || preferences.isShowHidden()) { tableModel.add(file); } } updateSummary(tableModel.getAll()); // If there's a parent directory, add an entry rendered as ".." final File parentDir = getCanonicalFile(directory).getParentFile(); if ((parentDir != null) && parentDir.exists()) { tableModel.add(parentDir); } // Sort the entries tableModel.sort(); // Notify the listeners that all the entries changed tableModel.fireTableDataChanged(); if ((oldDir != null) && tableModel.contains(oldDir)) { // Auto-select the directory we just left final int index = tableModel.indexOf(oldDir); table.getSelectionModel().setSelectionInterval(index, index); } else { // Auto-select the 1st entry (if there's one) if (tableModel.size() > 1) { table.getSelectionModel().setSelectionInterval(1, 1); } } if (logger.isDebugEnabled()) { logger.debug( String.format("[%s] Set directory to %s", getComponentLabel(), directory.getAbsolutePath())); } // Fire an event to ensure listeners are notified of the directory // change fireChangeEvent(); }
From source file:com.andrada.sitracker.ui.fragment.DirectoryChooserFragment.java
/** * Change the directory that is currently being displayed. * * @param dir The file the activity should switch to. This File must be * non-null and a directory, otherwise the displayed directory * will not be changed//from w w w .j av a2 s .c o m */ private void changeDirectory(@Nullable File dir) { if (dir == null) { debug("Could not change folder: dir was null"); } else if (!dir.isDirectory() && !mIsDirectoryChooser) { debug("Could not change folder: dir is no directory, selecting file"); //Selecting file mSelectedFile = dir; mTxtvSelectedFolder.setText(dir.getAbsolutePath()); if (isAdded()) { mTxtvSelectedFolderLabel.setText(getResources().getString(R.string.fp_selected_file_label)); } if (isValidFile(mSelectedFile)) { returnSelectedFile(); } } else { File[] contents = dir.listFiles(new FileFilter() { @Override public boolean accept(@NotNull File file) { return !file.isHidden(); } }); if (contents != null) { int numDirectories = 0; if (mIsDirectoryChooser) { for (File f : contents) { if (f.isDirectory()) { numDirectories++; } } } else { numDirectories = contents.length; } mFilesInDir = new File[numDirectories]; mFilenames.clear(); for (int i = 0, counter = 0; i < numDirectories; counter++) { if ((mIsDirectoryChooser && contents[counter].isDirectory()) || !mIsDirectoryChooser) { mFilesInDir[i] = contents[counter]; mFilenames.add( new FileDescriptor(contents[counter].getName(), contents[counter].isDirectory())); i++; } } Arrays.sort(mFilesInDir, new Comparator<File>() { @Override public int compare(@NotNull File aThis, @Nullable File aThat) { final int BEFORE = -1; final int EQUAL = 0; final int AFTER = 1; if (aThis == aThat) { return EQUAL; } if (aThat == null) { return BEFORE; } //Compare by type first if (aThis.isDirectory() && !aThat.isDirectory()) { return BEFORE; } if (!aThis.isDirectory() && aThat.isDirectory()) { return AFTER; } //Compare by filename int comparison = aThis.getName().compareTo(aThat.getName()); if (comparison != EQUAL) { return comparison; } return EQUAL; } }); Collections.sort(mFilenames); mSelectedDir = dir; mSelectedFile = null; if (isAdded()) { mTxtvSelectedFolderLabel.setText(getResources().getString(R.string.fp_selected_folder_label)); } mTxtvSelectedFolder.setText(dir.getAbsolutePath()); mListDirectoriesAdapter.notifyDataSetChanged(); mFileObserver = createFileObserver(dir.getAbsolutePath()); mFileObserver.startWatching(); debug("Changed directory to %s", dir.getAbsolutePath()); } else { debug("Could not change folder: contents of dir were null"); } } refreshButtonState(); }
From source file:com.peppe130.fireinstaller.core.CustomFileChooser.java
File[] listFiles(String mimeType) { File[] contents = parentFolder.listFiles(new FileFilter() { @Override//from w w w . j a va 2 s .co m public boolean accept(File file) { return getShowHiddenFiles() || !file.isHidden(); } }); List<File> results = new ArrayList<>(); if (contents != null) { MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton(); for (File fi : contents) { if (fi.isDirectory()) { results.add(fi); } else { if (fileIsMimeType(fi, mimeType, mimeTypeMap)) { results.add(fi); } } } Collections.sort(results, new FileSorter()); return results.toArray(new File[results.size()]); } return null; }
From source file:com.tulskiy.musique.library.Library.java
public void rescan(Map<String, Object> progress) { List<String> folders = LibraryConfiguration.getFolders(); if (CollectionUtils.isEmpty(folders)) { return;/*from w w w . j a v a 2s . c o m*/ } progress.put("processing.file", ""); data.removeDeadItems(); HashMap<TrackData, Track> trackDatas = new HashMap<TrackData, Track>(); for (Track track : data) { trackDatas.put(track.getTrackData(), track); } LinkedList<File> queue = new LinkedList<File>(); for (String path : folders) { File f = new File(path); if (f.exists()) queue.add(f); } HashSet<Track> processed = new HashSet<Track>(); final Set<String> formats = Codecs.getFormats(); ArrayList<Track> temp = new ArrayList<Track>(); while (!queue.isEmpty()) { try { File file = queue.pop(); if (progress != null) { if (progress.get("processing.stop") != null) { break; } progress.put("processing.file", file.getAbsolutePath()); } if (file.isDirectory()) { queue.addAll(0, Arrays.asList(file.listFiles(new FileFilter() { @Override public boolean accept(File file) { if (file.isHidden() || !file.canRead()) { return false; } if (file.isDirectory()) return true; String ext = Util.getFileExt(file).toLowerCase(); if (formats.contains(ext)) { String name = Util.removeExt(file.getAbsolutePath()) + ".cue"; return !new File(name).exists(); } return ext.equals("cue"); } }))); } else { TrackData trackData = new TrackData(file.toURI(), 0); Track track = trackDatas.get(trackData); if (track != null) { if (track.getTrackData().getLastModified() != file.lastModified()) { track.getTrackData().clearTags(); TrackIO.getAudioFileReader(file.getName()).reload(track); } processed.add(track); } else { temp.clear(); TrackIO.getAudioFileReader(file.getName()).read(file, temp); for (Track newTrack : temp) { trackData = newTrack.getTrackData(); if (trackDatas.containsKey(trackData)) { // it must be the cue file, so merge the track data trackData.merge(newTrack.getTrackData()); } processed.add(newTrack); } } } } catch (Exception e) { e.printStackTrace(); } } data.clear(); data.addAll(processed); processed.clear(); trackDatas.clear(); rebuildTree(); }
From source file:org.egov.android.view.activity.ComplaintDetailActivity.java
/** * Function called after getting success api response to download the images * under the complaints After downloading the images, the images will be * updated in detail screen/*w w w. j ava2 s .c om*/ * * @param totalFiles * => total files attached in a complaint */ private void _addDownloadJobs(int totalFiles) { JSONObject jo = null; try { File complaintDir = new File(complaintFolderName); int hiddenfilecount = 0; for (File file : complaintDir.listFiles()) { if (file.isHidden()) { hiddenfilecount++; } } //delete old cache images if (totalFiles != hiddenfilecount) { for (File file : complaintDir.listFiles()) file.delete(); } for (int i = 1; i <= totalFiles; i++) { if (!new File(complaintFolderName + "/.thumb_photo_" + i + ".jpg").exists()) { jo = new JSONObject(); jo.put("url", AndroidLibrary.getInstance().getConfig().getString("api.baseUrl") + "/api/v1.0/complaint/" + complaintId + "/downloadSupportDocument"); jo.put("fileNo", i); jo.put("type", "complaint"); jo.put("isThumbnail", true); jo.put("destPath", complaintFolderName + "/.thumb_photo_" + i + ".jpg"); downloadThumbImages.put(jo); } /* * SQLiteHelper.getInstance().execSQL( * "INSERT INTO tbl_jobs(data, status, type, triedCount) values ('" * + jo.toString() + "', 'waiting', 'download', 0)"); */ } // ServiceController.getInstance().startJobs(); } catch (JSONException e) { e.printStackTrace(); } }
From source file:jp.massbank.spectrumsearch.logic.MassBankRecordLogic.java
private void syncFolderInfo(String pathname) { long s = System.currentTimeMillis(); List<Instrument> instruments = new ArrayList<Instrument>(); List<MsType> msTypes = new ArrayList<MsType>(); File f = new File(pathname); File[] listfiles = f.listFiles(); for (int i = 0; i < listfiles.length; i++) { File item = listfiles[i]; if (!item.isHidden()) { if (item.isDirectory()) { String name = item.getAbsolutePath(); syncFolderInfo(name);//from w w w .j ava 2s . c o m // File[] internalFiles = item.listFiles(); //// for (int j = 0; j < 1; j++) { // for (int j = 0; j < internalFiles.length; j++) { // File item2 = internalFiles[j]; // if (! item2.isHidden()) { // if (item2.isDirectory()) { // String name = item2.getAbsolutePath(); // syncFolderInfo(name); // } else { // // read the file content // mergeMassBankRecordIntoDb(item2, instruments, msTypes); // } // } // } } else { // read the file content long s1 = System.currentTimeMillis(); mergeMassBankRecordIntoDb(item, instruments, msTypes); LOGGER.debug("merge massbank record : " + item.getName() + "(" + (System.currentTimeMillis() - s1) + ")"); } } } LOGGER.debug("time duration to read files : " + (System.currentTimeMillis() - s) / 1000 + "s"); }
From source file:com.veniosg.dir.android.dialog.DetailsDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { final File f = mFileHolder.getFile(); final View v = from(getActivity()).inflate(R.layout.dialog_details, null); final ViewGroup container = (ViewGroup) v.findViewById(R.id.details_container); boolean isDirectory = f.isDirectory(); String folderStr = getString(R.string.details_type_folder); String otherStr = getString(R.string.details_type_other); String perms = (f.canRead() ? "R" : "-") + (f.canWrite() ? "W" : "-") + (canExecute(f) ? "X" : "-"); String mimeType = mFileHolder.getMimeType(); String typeValue = isDirectory ? folderStr : (f.isFile() ? mimeType : otherStr); String hiddenValue = getString(f.isHidden() ? R.string.yes : R.string.no); String lastModifiedValue = mFileHolder.getFormattedModificationDate(getActivity()).toString(); addSizeDetailsItem(container);//w w w . jav a 2s . co m addDetailsItem(container, R.string.details_type, typeValue); if (isDirectory) { String[] fList = f.list(); if (fList != null) { addDetailsItem(container, R.string.details_items, valueOf(fList.length)); } } else if (isImage(mimeType)) { addResolutionDetailsItem(container); } addDetailsItem(container, R.string.details_lastmodified, lastModifiedValue); addDetailsItem(container, R.string.details_hidden, hiddenValue); addDetailsItem(container, R.string.details_permissions, perms); AlertDialog dialog = new AlertDialog.Builder(getActivity()).setTitle(mFileHolder.getName()).setView(v) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dismiss(); } }).create(); return dialog; }
From source file:me.neatmonster.spacertk.actions.FileActions.java
/** * Gets information about a File//from w w w . j a v a 2 s . c o m * @param file File to get information about * @return Information about a file */ @Action(aliases = { "getFileInformations", "fileInformations", "informations" }) public TreeMap<String, Object> getFileInformations(final String file) { final TreeMap<String, Object> fileInformations = new TreeMap<String, Object>(); final File file_ = new File(file); if (file_.exists()) { fileInformations.put("Name", file_.getName()); fileInformations.put("Path", file_.getPath()); fileInformations.put("Size", file_.length()); fileInformations.put("Execute", file_.canExecute()); fileInformations.put("Read", file_.canRead()); fileInformations.put("Write", file_.canWrite()); fileInformations.put("IsDirectory", file_.isDirectory()); fileInformations.put("IsFile", file_.isFile()); fileInformations.put("IsHidden", file_.isHidden()); final FileNameMap fileNameMap = URLConnection.getFileNameMap(); fileInformations.put("Mime", fileNameMap.getContentTypeFor("file://" + file_.getPath())); return fileInformations; } return new TreeMap<String, Object>(); }
From source file:org.geoserver.config.GeoServerLoader.java
protected void readConfiguration(GeoServer geoServer, XStreamPersister xp) throws Exception { //look for services.xml, if it exists assume we are dealing with // an old data directory File f = resourceLoader.find("services.xml"); if (f == null) { //assume 2.x style f = resourceLoader.find("global.xml"); if (f != null) { GeoServerInfo global = depersist(xp, f, GeoServerInfo.class); geoServer.setGlobal(global); }// w w w . j a va2 s . com //load logging f = resourceLoader.find("logging.xml"); if (f != null) { LoggingInfo logging = depersist(xp, f, LoggingInfo.class); geoServer.setLogging(logging); } // load workspace specific settings File workspaces = resourceLoader.find("workspaces"); if (workspaces != null) { for (File dir : workspaces.listFiles()) { if (!dir.isDirectory() && !dir.isHidden()) continue; f = resourceLoader.find(dir, "settings.xml"); if (f != null) { SettingsInfo settings = depersist(xp, f, SettingsInfo.class); geoServer.add(settings); } } } //load services final List<XStreamServiceLoader> loaders = GeoServerExtensions.extensions(XStreamServiceLoader.class); loadServices(null, loaders, geoServer); //load services specific to workspace if (workspaces != null) { for (File dir : workspaces.listFiles()) { if (!dir.isDirectory() && !dir.isHidden()) continue; loadServices(dir, loaders, geoServer); } } } else { //add listener now as a converter which will convert from the old style // data directory to the new GeoServerPersister p = new GeoServerPersister(resourceLoader, xp); geoServer.addListener(p); //import old style services.xml new LegacyConfigurationImporter(geoServer).imprt(resourceLoader.getBaseDirectory()); geoServer.removeListener(p); //rename the services.xml file f.renameTo(new File(f.getParentFile(), "services.xml.old")); } }
From source file:org.geoserver.catalog.util.LegacyCatalogImporter.java
/** * Imports configuration from a geoserver data directory into the catalog. * /* w w w .ja va2 s. com*/ * @param dir * The root of the data directory. * */ public void imprt(File dir) throws Exception { CatalogFactory factory = catalog.getFactory(); // first off, import the main catalog so that namespaces, workspaces, styles, // datastores and coveragestores are read File catalogFile = new File(dir, "catalog.xml"); if (!catalogFile.exists()) { throw new FileNotFoundException("Could not find catalog.xml under:" + dir.getAbsolutePath()); } importCatalog(catalogFile); // for each feature type file, load the info.xml into a FeatureTypeInfo File featureTypes = new File(dir, "featureTypes"); if (!featureTypes.exists()) featureTypes.mkdir(); File[] featureTypeDirectories = featureTypes.listFiles(); for (int i = 0; i < featureTypeDirectories.length; i++) { File featureTypeDirectory = featureTypeDirectories[i]; if (!featureTypeDirectory.isDirectory() || featureTypeDirectory.isHidden()) continue; // load info.xml File ftInfoFile = new File(featureTypeDirectory, "info.xml"); if (!ftInfoFile.exists()) { LOGGER.fine("No info.xml found in directory: '" + featureTypeDirectory.getName() + "', ignoring"); continue; } LegacyFeatureTypeInfoReader ftInfoReader = new LegacyFeatureTypeInfoReader(); try { ftInfoReader.read(ftInfoFile); FeatureTypeInfo featureType = readFeatureType(ftInfoReader, featureTypeDirectory); if (featureType == null) { continue; } catalog.add(featureType); LOGGER.info("Loaded feature type '" + featureType.getPrefixedName() + "'"); // create a wms layer for the feature type LayerInfo layer = factory.createLayer(); layer.setResource(featureType); layer.setName(featureType.getName()); layer.setPath(ftInfoReader.wmsPath()); if (layer.getPath() == null) { layer.setPath("/"); } layer.setType(LayerInfo.Type.VECTOR); String defaultStyleName = ftInfoReader.defaultStyle(); if (defaultStyleName != null) { StyleInfo style = catalog.getStyleByName(defaultStyleName); if (style != null) { layer.setDefaultStyle(style); } } List<String> styles = ftInfoReader.styles(); if (styles != null) { for (String styleName : styles) { StyleInfo style = catalog.getStyleByName(styleName); if (style != null) { layer.getStyles().add(style); } } } Map legendURL = ftInfoReader.legendURL(); if (legendURL != null) { LegendInfo legend = factory.createLegend(); legend.setHeight((Integer) legendURL.get("height")); legend.setWidth((Integer) legendURL.get("width")); legend.setFormat((String) legendURL.get("format")); legend.setOnlineResource((String) legendURL.get("onlineResource")); layer.setLegend(legend); } layer.setEnabled(featureType.isEnabled()); catalog.add(layer); } catch (Exception e) { LOGGER.warning("Error loadin '" + featureTypeDirectory.getName() + "/info.xml', ignoring"); LOGGER.log(Level.INFO, "", e); continue; } } // for each coverage definition in coverage, read it File coverages = new File(dir, "coverages"); if (!coverages.exists()) coverages.mkdir(); File[] coverageDirectories = coverages.listFiles(); for (int i = 0; i < coverageDirectories.length; i++) { File coverageDirectory = coverageDirectories[i]; if (!coverageDirectory.isDirectory() || coverageDirectory.isHidden()) continue; // load info.xml File cInfoFile = new File(coverageDirectory, "info.xml"); if (!cInfoFile.exists()) { LOGGER.fine("No info.xml found in directory: '" + coverageDirectory.getName() + "', ignoring"); continue; } LegacyCoverageInfoReader cInfoReader = new LegacyCoverageInfoReader(); try { cInfoReader.read(cInfoFile); CoverageInfo coverage = readCoverage(cInfoReader); if (coverage == null) { continue; } catalog.add(coverage); // create a wms layer for the feature type LayerInfo layer = factory.createLayer(); layer.setResource(coverage); layer.setName(coverage.getName()); layer.setPath(cInfoReader.wmsPath()); if (layer.getPath() == null) { layer.setPath("/"); } layer.setType(LayerInfo.Type.RASTER); String defaultStyleName = cInfoReader.defaultStyle(); if (defaultStyleName != null) { StyleInfo style = catalog.getStyleByName(defaultStyleName); if (style != null) { layer.setDefaultStyle(style); } } List<String> styles = cInfoReader.styles(); if (styles != null) { for (String styleName : styles) { StyleInfo style = catalog.getStyleByName(styleName); if (style != null) { layer.getStyles().add(style); } } } layer.setEnabled(coverage.isEnabled()); catalog.add(layer); } catch (Exception e) { LOGGER.warning("Error loading '" + coverageDirectory.getName() + "/info.xml', ignoring"); LOGGER.log(Level.INFO, "", e); continue; } } }