/** * Returns the extension of the given file using {@link AbstractFile#getExtension()}. If the extension is * <code>null</code>, the empty string <code>""</code> is returned, making the returned extension safe for use * in a hash map where null keys are forbidden. * * @param file file on which to call {@link AbstractFile#getExtension} * @return the file's extension, may be the empty string but never <code>null</code> */ private static String getCheckedExtension(AbstractFile file) { String extension = file.getExtension(); return extension==null?"":extension; }
@Override public String getExtension() { if(!getExtensionSet) { getExtension = file.getExtension(); getExtensionSet = true; } return getExtension; }
@Override public String getExtension() { return file.getExtension(); }
public boolean accept(String name) {return AbstractFile.getExtension(name) == null;} };
/** * Returns <code>true</code> if the specified file should be displayed in the chooser. */ @Override public boolean accept(java.io.File file) { String ext; // Directories are always displayed. if(file.isDirectory()) return true; // If the file has an extension, and it matches .xml, return true. // Otherwise, return false. if((ext = AbstractFile.getExtension(file.getName())) != null) return extension.equalsIgnoreCase(ext); return false; }
/** * Returns the specified file's extension, or <code>""</code> if it doesn't have one. * @return the specified file's extension. */ private String getExtension(AbstractFile file) { String ext; if((ext = file.getExtension()) == null) return ""; return ext; }
/** * Returns this file's extension, <code>null</code> if this file's name doesn't have an extension. * * <p>A filename has an extension if and only if:<br/> * - it contains at least one <code>.</code> character<br/> * - the last <code>.</code> is not the last character of the filename<br/> * - the last <code>.</code> is not the first character of the filename</p> * * @return this file's extension, <code>null</code> if this file's name doesn't have an extension */ public String getExtension() { return getExtension(getName()); }
/** * Returns <code>true</code> for directories with an <code>app</code> extension (case-insensitive comparison). * * @param file the file to test * @return <code>true</code> for directories with an <code>app</code> extension (case-insensitive comparison). */ @Override public boolean isApplication(AbstractFile file) { String extension = file.getExtension(); // the isDirectory() test comes last as it is I/O bound return extension!=null && extension.equalsIgnoreCase("app") && file.isDirectory(); } }
/** * Returns <code>true</code> for regular files (not directories) with an <code>exe</code> extension * (case-insensitive comparison). * * @param file the file to test * @return <code>true</code> for regular files (not directories) with an <code>exe</code> extension * (case-insensitive comparison). */ @Override public boolean isApplication(AbstractFile file) { String extension = file.getExtension(); // the isDirectory() test comes last as it is I/O bound return extension!=null && extension.equalsIgnoreCase("exe") && !file.isDirectory(); } }
/** * Gets the value from <code>file</code> that should be used to replace <code>keyword</code>. * @param keyword character to replace. * @param file file from which to retrieve the replacement value. * @return the requested replacement value. */ private static String getKeywordReplacement(char keyword, AbstractFile file) { switch(keyword) { case KEYWORD_PATH: return file.getAbsolutePath(); case KEYWORD_NAME: return file.getName(); case KEYWORD_PARENT: AbstractFile parentFile = file.getParent(); return parentFile==null?"":parentFile.getAbsolutePath(); case KEYWORD_VM_PATH: return new File(System.getProperty("user.dir")).getAbsolutePath(); case KEYWORD_EXTENSION: String extension; if((extension = file.getExtension()) == null) return ""; return extension; case KEYWORD_NAME_WITHOUT_EXTENSION: return file.getNameWithoutExtension(); } throw new IllegalArgumentException(); }
if ("nrg".equals(file.getExtension())) { return NrgParser.getEntries(buffer, file, rais);
if((ext = file.getExtension()) == null) return new AbstractFilenameFilter() { public boolean accept(String name) {return AbstractFile.getExtension(name) == null;}
return; String ext = part1.getExtension(); int firstIndex; try { AbstractFile[] otherParts = parent.ls(filter); for (AbstractFile otherPart : otherParts) { String ext2 = otherPart.getExtension(); try { int partIdx = Integer.parseInt(ext2);
/** * Resolves an AbstractFile instance corresponding to the file named <code>filename</code> within the temporary * folder and asserts its {@link AbstractFile#getName() name}, {@link AbstractFile#getExtension() extension} and * {@link AbstractFile#getNameWithoutExtension() name without extension} match the specified values. * * @param tempFolder the temporary folder which will be the parent of the resolved AbstractFile instance * @param filename filename of the AbstractFile to resolved * @param expectedExtension the expected file's extension * @param expectedNameWOExt the expected file's name without extension * @throws IOException if an error occurred while resolving the file */ protected void assertNameAndExtension(AbstractFile tempFolder, String filename, String expectedExtension, String expectedNameWOExt) throws IOException { AbstractFile file = tempFolder.getChild(filename); assert filename.equals(file.getName()); assert StringUtils.equals(expectedExtension, file.getExtension(), true); assert StringUtils.equals(expectedNameWOExt, expectedNameWOExt, true); }
/** * Looks for XML files in the specified folder recursively and tests them for well-formedness. * A <code>org.xml.sax.SAXException</code> is thrown when an error is encountered in one of the XML files, * even a recoverable one. Any archive contained in the folder will be searched for XML files. * * @param folder the folder in which to look for XML files recursively. * @throws IOException if a file or a folder couldn't be accessed * @throws SAXException if an error was found in one of the XML documents * @throws ParserConfigurationException if 'a serious configuration error' occurred in the XML parser */ private void testXMLFiles(AbstractFile folder) throws SAXException, IOException, ParserConfigurationException { AbstractFile children[] = folder.ls(); for (AbstractFile bhild : children) { if (bhild.isBrowsable()) testXMLFiles(bhild); else if ("xml".equals(bhild.getExtension())) testXMLDocument(bhild); } }
assert !temporaryFile2.exists(); assert !temporaryFile2.getName().equals(desiredName); assert temporaryFile1.getExtension().equals(temporaryFile2.getExtension());
&&(parent=parent.getParent())!=null && parent.getName().equals("Resources") &&(parent=parent.getParent())!=null && parent.getName().equals("Contents") &&(parent=parent.getParent())!=null && "app".equals(parent.getExtension())) {
/** * It is possible to add several files with same name to the Trash. These files are distinguished * by _N appended to the name, where _N is rising int number. <br/> * This method tries to find first empty <code>filename_N.ext</code>. * * @param file File to be deleted * @return Suitable filename in trash (without .trashinfo extension) */ private String getUniqueFilename(AbstractFile file) throws IOException { // try if no previous file in trash exists if (!TRASH_FILES_SUBFOLDER.getChild(file.getName()).exists()) return file.getName(); String rawName = file.getNameWithoutExtension(); String extension = file.getExtension(); // find first empty filename in format filename_N.ext String filename; int count = 1; while(true) { filename = rawName + "_" + count++; if(extension!=null) filename += "." + extension; if(!TRASH_FILES_SUBFOLDER.getChild(filename).exists()) return filename; } } }
/** * It is possible to add several files with same name to the Trash. These files are distinguished * by _N appended to the name, where _N is rising int number. <br/> * This method tries to find first empty <code>filename_N.ext</code>. * * @param file File to be deleted * @return Suitable filename in trash (without .trashinfo extension) */ private String getUniqueFilename(AbstractFile file) throws IOException { // try if no previous file in trash exists if (!TRASH_FILES_SUBFOLDER.getChild(file.getName()).exists()) return file.getName(); String rawName = file.getNameWithoutExtension(); String extension = file.getExtension(); // find first empty filename in format filename_N.ext String filename; int count = 1; while(true) { filename = rawName + "_" + count++; if(extension!=null) filename += "." + extension; if(!TRASH_FILES_SUBFOLDER.getChild(filename).exists()) return filename; } } }
if(!"xml".equalsIgnoreCase(file.getExtension())) // Note: getExtension() may return null if no extension file = lastSelectedFolder.getDirectChild(file.getName()+".xml");