List of usage examples for org.apache.commons.io FilenameUtils isExtension
public static boolean isExtension(String filename, Collection<String> extensions)
From source file:net.przemkovv.sphinx.compiler.GXXCompiler.java
private CompilationResult compile(ArrayList<String> cmd, List<File> files, File output_file) throws IOException, ExecutionException, InterruptedException { if (files != null) { for (File file : files) { if (FilenameUtils.isExtension(file.getName(), "cpp") || FilenameUtils.isExtension(file.getName(), "c")) { cmd.add(file.getAbsolutePath()); }//from w ww . ja va 2 s . c om } } logger.debug("Compiler command line: {}", cmd); final Process process = Runtime.getRuntime().exec(cmd.toArray(new String[cmd.size()]), null, output_file.getParentFile()); Future<String> output_error_result = pool.submit(new Callable<String>() { @Override public String call() throws Exception { return Utils.readAllFromInputStream(process.getErrorStream()); } }); Future<String> output_result = pool.submit(new Callable<String>() { @Override public String call() throws Exception { return Utils.readAllFromInputStream(process.getInputStream()); } }); process.waitFor(); CompilationResult result = new CompilationResult(); result.output_errror = output_error_result.get(); result.output = output_result.get(); result.exit_value = process.exitValue(); result.executable_file = output_file; result.prepare_env = prepare_env_cmd; return result; }
From source file:com.orange.ocara.model.RuleSetLoaderImpl.java
private boolean isJsonFile(String asset) { return FilenameUtils.isExtension(asset, "json"); }
From source file:com.orange.ocara.model.RuleSetLoaderImpl.java
private boolean isPngFile(String asset) { return FilenameUtils.isExtension(asset, "png"); }
From source file:com.orange.ocara.model.RuleSetLoaderImpl.java
private boolean isJpgFile(String asset) { return FilenameUtils.isExtension(asset, "jpg"); }
From source file:com.orange.ocara.model.RuleSetLoaderImpl.java
private boolean isGifFile(String asset) { return FilenameUtils.isExtension(asset, "gif"); }
From source file:hu.bme.mit.sette.common.validator.FileValidator.java
/** * Sets the allowed extensions for the file. * * @param allowedExtensions// w w w . j av a 2s.c om * the allowed extensions * @return this object */ public FileValidator extension(final String... allowedExtensions) { if (getSubject() != null) { File file = getSubject(); if (!FilenameUtils.isExtension(file.getName(), allowedExtensions)) { this.addException( String.format("The file has an inappropriate extension\n" + "(allowedExtensions: [%s])", ArrayUtils.toString(allowedExtensions))); } } return this; }
From source file:com.moviejukebox.tools.DOMHelper.java
/** * Get a DOM document from the supplied file * * @param xmlFile// w ww.j a v a 2 s . c o m * @return * @throws IOException * @throws ParserConfigurationException * @throws SAXException */ public static Document getDocFromFile(File xmlFile) throws ParserConfigurationException, SAXException, IOException { URL url = xmlFile.toURI().toURL(); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc; // Custom error handler db.setErrorHandler(new SaxErrorHandler()); try (InputStream in = url.openStream()) { doc = db.parse(in); } catch (SAXParseException ex) { if (FilenameUtils.isExtension(xmlFile.getName().toLowerCase(), "xml")) { throw new SAXParseException("Failed to process file as XML", null, ex); } // Try processing the file a different way doc = null; } if (doc == null) { try ( // try wrapping the file in a root StringReader sr = new StringReader(wrapInXml(FileTools.readFileToString(xmlFile)))) { doc = db.parse(new InputSource(sr)); } } if (doc != null) { doc.getDocumentElement().normalize(); } return doc; }
From source file:com.esminis.server.library.service.server.installpackage.InstallerPackage.java
private void uninstall(File directory) throws Throwable { final File list[] = directory.listFiles(); if (list != null) { for (File file : list) { if (file.isDirectory()) { uninstall(file);// ww w . java2 s .c o m } else if (!FilenameUtils.isExtension(file.getAbsolutePath(), "sqlite") && !file.delete()) { throw new Exception("Cannot uninstall file: " + file); } } } }
From source file:com.chingo247.structureapi.blockstore.BlockStore.java
public Iterator<File> regionFileIterator() { List<File> regionFiles = Lists.newArrayList(); for (File f : directory.listFiles()) { if (FilenameUtils.isExtension(f.getName(), "blockstore") && f.getName().startsWith(makePrefix(name))) { regionFiles.add(f);//from w ww . j ava2 s .c om } } return regionFiles.iterator(); }
From source file:com.fujitsu.dc.engine.extension.support.ExtensionJarLoader.java
/** * ExtensionJarDirectory?? jar?URL??./*from w w w. j ava 2 s . c o m*/ * ???? "jar"???? * @param extJarDir Extensionjar?? * @param searchDescend true: ?, false: ???? * @return jar? URL. */ private List<URL> getJarPaths(Path extJarDir, boolean searchDescend) throws DcEngineException { try { // ?? List<URL> uriList = new ArrayList<URL>(); // jar????? uriList.add(new URL("file", "", extJarDir.toFile().getAbsolutePath() + "/")); // jar? File[] jarFiles = extJarDir.toFile().listFiles(new FileFilter() { @Override public boolean accept(File pathname) { if (!pathname.exists() || !pathname.canRead() || pathname.isDirectory()) { return false; } return FilenameUtils.isExtension(pathname.getName(), JAR_SUFFIX); } }); if (null != jarFiles) { for (File jarFile : jarFiles) { try { uriList.add(new URL("file", "", jarFile.getCanonicalPath())); log.info(String.format("Info: Adding extension jar file %s to classloader.", jarFile.toURI())); } catch (MalformedURLException e) { // ############################################################################3 // ????????? jar???????? jar???? // ? Extension????????? Extension????? UserScript?? // ???????????? // ?? Extension?????Script??? // ############################################################################3 log.info(String.format("Warn: Some Extension jar file has malformed path. Ignoring: %s", jarFile.toURI())); } catch (IOException e) { log.info(String.format("Warn: Some Extension jar file has malformed path. Ignoring: %s", jarFile.toURI())); } } } // ? File[] subDirs = extJarDir.toFile().listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.exists() && pathname.isDirectory() && pathname.canRead(); } }); if (null != subDirs) { for (File subDir : subDirs) { // jar? uriList.addAll(getJarPaths(subDir.toPath(), searchDescend)); } } return uriList; } catch (RuntimeException e) { e.printStackTrace(); log.info(String.format("Warn: Error occured while loading Extension: %s", e.getMessage())); throw new DcEngineException("Error occured while loading Extension.", DcEngineException.STATUSCODE_SERVER_ERROR, e); } catch (Exception e) { log.info(String.format("Warn: Error occured while loading Extension: %s", e.getMessage())); throw new DcEngineException("Error occured while loading Extension.", DcEngineException.STATUSCODE_SERVER_ERROR, e); } }