List of usage examples for org.apache.commons.io FilenameUtils getExtension
public static String getExtension(String filename)
From source file:extractcode.TraversalFiles.java
public static void fileList(File inputFile, int node, ArrayList<String> path, String folderPath) { node++;/*ww w.j a v a 2s. c o m*/ File[] files = inputFile.listFiles(); if (!inputFile.exists()) { System.out.println("File doesn't exist!"); } else if (inputFile.isDirectory()) { path.add(inputFile.getName()); for (File f : files) { for (int i = 0; i < node - 1; i++) { System.out.print(" "); } System.out.print("|-" + f.getPath()); String ext = FilenameUtils.getExtension(f.getName()); if (ext.equals("java")) { try { System.out.println(" => extracted"); //Get extracted file location and add it to output file name, //in order to avoid files in different folder //have the same name. String fileLocation = ""; for (String tmpPath : path) { fileLocation += "-" + tmpPath; } String outFilePath = folderPath + "/" + f.getName() + fileLocation + "-allcode.txt"; //create output file File outputFile = new File(outFilePath); if (outputFile.createNewFile()) { System.out.println("Create successful: " + outputFile.getName()); } //extract comments ExtractCode.extractCode(f, outputFile); } catch (IOException ex) { Logger.getLogger(TraversalFiles.class.getName()).log(Level.SEVERE, null, ex); } } else { System.out.println(); } fileList(f, node, path, folderPath); } path.remove(node - 1); } }
From source file:extractcomments.TraversalFiles.java
public static void fileList(File inputFile, int node, ArrayList<String> path, String folderPath) { node++;//from ww w.j av a 2 s . co m File[] files = inputFile.listFiles(); if (!inputFile.exists()) { System.out.println("File doesn't exist!"); } else if (inputFile.isDirectory()) { path.add(inputFile.getName()); for (File f : files) { for (int i = 0; i < node - 1; i++) { System.out.print(" "); } System.out.print("|-" + f.getPath()); String ext = FilenameUtils.getExtension(f.getName()); if (ext.equals("java")) { try { System.out.println(" => extracted"); //Get extracted file location and add it to output file name, //in order to avoid files in different folder //have the same name. String fileLocation = ""; for (String tmpPath : path) { fileLocation += "-" + tmpPath; } String outFilePath = folderPath + "/" + f.getName() + fileLocation + "-all.txt"; //create output file File outputFile = new File(outFilePath); if (outputFile.createNewFile()) { System.out.println("Create successful: " + outputFile.getName()); } //extract comments ExtractComments.extractComments(f, outputFile); } catch (IOException ex) { Logger.getLogger(TraversalFiles.class.getName()).log(Level.SEVERE, null, ex); } } else { System.out.println(" isn't a java file."); } fileList(f, node, path, folderPath); } path.remove(node - 1); } }
From source file:extractsomecomments.TraversalFiles.java
public static void fileList(File inputFile, int node, ArrayList<String> path, String folderPath) { node++;// w w w. j a v a 2s . com File[] files = inputFile.listFiles(); if (!inputFile.exists()) { System.out.println("File doesn't exist!"); } else if (inputFile.isDirectory()) { path.add(inputFile.getName()); for (File f : files) { for (int i = 0; i < node - 1; i++) { System.out.print(" "); } System.out.print("|-" + f.getPath()); String ext = FilenameUtils.getExtension(f.getName()); if (ext.equals("java")) { try { System.out.println(" => extracted"); //Get extracted file location and add it to output file name, //in order to avoid files in different folder //have the same name. String fileLocation = ""; for (String tmpPath : path) { fileLocation += "-" + tmpPath; } String outFilePath = folderPath + "/" + f.getName() + fileLocation + "-all.txt"; //create output file File outputFile = new File(outFilePath); if (outputFile.createNewFile()) { System.out.println("Create successful: " + outputFile.getName()); } //extract comments ExtractSomeComments.extractComments(f, outputFile); } catch (IOException ex) { Logger.getLogger(TraversalFiles.class.getName()).log(Level.SEVERE, null, ex); } } else { System.out.println(); } fileList(f, node, path, folderPath); } path.remove(node - 1); } }
From source file:javacommon.excel.ExcelUtils.java
/** * ????Excel// w w w.j a va2 s . com * @param fileName * @return */ public static int getVersionByFileName(String fileName) { String extension = FilenameUtils.getExtension(fileName); if ("xls".equalsIgnoreCase(extension)) return ExcelConstants.EXCEL_XLS_VERSION; else if ("xlsx".equalsIgnoreCase(extension)) return ExcelConstants.EXCEL_XLSX_VERSION; else throw new IllegalArgumentException("??"); }
From source file:biomesoplenty.common.config.ModConfiguration.java
private static void loadBiomes() { for (BiomeGenBase biome : BiomeGenBase.getBiomeGenArray()) { if (biome != null) { BiomeConfiguration biomeConfiguration = BiomeConfiguration.getInstance(biome); biomeConfiguration.update(); BiomeConfigUtil.configureBiome(biome, biomeConfiguration); }//from ww w. j a v a2 s. co m } for (File file : BiomeConfigUtil.getBiomeConfigDirectory().listFiles()) { if (FilenameUtils.getExtension(file.getName()).equals("cfg")) { System.out.println("Found custom config: " + file.getName()); } } }
From source file:extractjavadoc.TraversalFiles.java
public static void fileList(File inputFile, int node, ArrayList<String> path, String folderPath, boolean ifGeneral, Map<String, Boolean> libraryTypeCondition) { node++;/* w w w. j av a 2 s . co m*/ File[] files = inputFile.listFiles(); if (!inputFile.exists()) { System.out.println("File doesn't exist!"); } else if (inputFile.isDirectory()) { path.add(inputFile.getName()); for (File f : files) { for (int i = 0; i < node - 1; i++) { System.out.print(" "); } System.out.print("|-" + f.getPath()); String ext = FilenameUtils.getExtension(f.getName()); if (ext.equals("html")) { try { System.out.println(" => extracted"); //Get extracted file location and add it to output file name, //in order to avoid files in different folder //have the same name. String fileLocation = ""; for (String tmpPath : path) { fileLocation += "-" + tmpPath; } String usefulJavadocFilePath = folderPath + "/" + "javadoc-" + f.getName() + fileLocation + ".txt"; // String usefulJavadocFilePath = folderPath + "/" + "javadoc-" + f.getName() + ".txt"; //create output file for usefuljavadoc File usefulJavadocFile = new File(usefulJavadocFilePath); if (usefulJavadocFile.createNewFile()) { System.out.println("Create successful: " + usefulJavadocFile.getName()); } //extract useful javadoc ExtractHTMLContent extractJavadoc = new ExtractHTMLContent(f, usefulJavadocFile, ifGeneral, libraryTypeCondition); extractJavadoc.extractHTMLContent(); } catch (IOException ex) { Logger.getLogger(TraversalFiles.class.getName()).log(Level.SEVERE, null, ex); } } else { // System.out.println(" isn't a java file or html file."); System.out.println(" isn't a html file."); } fileList(f, node, path, folderPath, ifGeneral, libraryTypeCondition); } path.remove(node - 1); } }
From source file:mp1.include.me.Sabsalon1.java
private static String readH(String filelocation) throws wrongFileNameException, FileNotFoundException, IOException { String ext = FilenameUtils.getExtension(filelocation); if ("h".equals(ext) || "H".equals(ext)) { System.out.println("Is right header, contents of " + filelocation); BufferedReader buff = null; try {//w w w . j a v a 2 s . co m String sCurrentLine; buff = new BufferedReader(new FileReader(filelocation)); while ((sCurrentLine = buff.readLine()) != null) { System.out.println(sCurrentLine); checkValidAndInclude(sCurrentLine); finaloutput.add(sCurrentLine); } } catch (IOException e) { e.printStackTrace(); } finally { try { if (buff != null) buff.close(); } catch (IOException ex) { ex.printStackTrace(); } } } else { throw new wrongFileNameException("Is not a valid header (must be a .h file)"); } return "unfinished"; }
From source file:com.cpjit.swagger4j.support.internal.FileTypeMap.java
public final static String getContentType(String file) { String extension = FilenameUtils.getExtension(file); String mime = extension2mime.get(extension); if (StringUtils.isBlank(mime)) { mime = "application/octet-stream"; }// ww w. jav a2s.c o m return mime; }
From source file:edu.harvard.med.screensaver.util.FileUtils.java
/** * Returns a File object with a new parent directory and/or a new file * extension.//from www . j av a 2s . co m * * @param file the File object to be modified * @param newDirectory the output directory; if null the file original * file directory is used. * @param newExtension the extension to use when saving the file, * replacing the file's original filename extension; if null * original filename extension is used. A leading period will be * added if it does not exist. * @return the modified File object */ public static File modifyFileDirectoryAndExtension(File file, File newDirectory, String newExtension) { if (newExtension == null) { newExtension = FilenameUtils.getExtension(file.getName()); } else { if (newExtension.startsWith(".")) { newExtension = newExtension.substring(1); } } if (newDirectory == null) { newDirectory = file.getParentFile(); } File outputFile = new File(newDirectory, FilenameUtils.getBaseName(file.getName()) + "." + newExtension); return outputFile; }
From source file:com.technofovea.packbsp.PackbspUtil.java
/** * Efficiently copies a given file, returning a temporary copy which will be * removed when execution finishes./*w w w . j a v a 2s .com*/ * * @param source Source file to copy. * @return The copied file. * @throws IOException */ public static final File createTempCopy(File source) throws IOException { String ext = FilenameUtils.getExtension(source.getName()); File dest = File.createTempFile("packbsp_temp_", "." + ext); dest.deleteOnExit(); FileInputStream fis = new FileInputStream(source); FileOutputStream fos = new FileOutputStream(dest); IOUtils.copy(fis, fos); fis.close(); fos.close(); return dest; }