List of usage examples for org.apache.commons.io FilenameUtils removeExtension
public static String removeExtension(String filename)
From source file:MSUmpire.SpectrumParser.mzXMLParser.java
private boolean FSScanPosRead() { if (!new File(FilenameUtils.removeExtension(filename) + ".ScanPosFS").exists()) { return false; }// w ww. j a v a 2 s . com try { Logger.getRootLogger() .debug("Reading ScanPos:" + FilenameUtils.removeExtension(filename) + ".ScanPosFS..."); FileInputStream fileIn = new FileInputStream(FilenameUtils.removeExtension(filename) + ".ScanPosFS"); FSTObjectInput in = new FSTObjectInput(fileIn); ScanIndex = (TreeMap<Integer, Long>) in.readObject(); TotalScan = ScanIndex.size(); in.close(); fileIn.close(); } catch (Exception ex) { Logger.getRootLogger().debug("ScanIndex serialization file failed"); //Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex)); return false; } return true; }
From source file:com.github.ithildir.liferay.mobile.go.GoSDKBuilder.java
protected void copyResource(String name, String destination) throws IOException { File destinationDir = new File(destination); destinationDir = new File(destinationDir.getAbsoluteFile(), CharPool.SLASH + name); URL sourceURL = getClass().getResource(CharPool.SLASH + name); URLConnection sourceConnection = sourceURL.openConnection(); if (sourceConnection instanceof JarURLConnection) { copyJarResource((JarURLConnection) sourceConnection, destinationDir); } else {/*from ww w.java 2 s.c om*/ File sourceDir = new File(sourceURL.getPath()); FileUtils.copyDirectory(sourceDir, destinationDir); } Iterator<File> itr = FileUtils.iterateFiles(destinationDir, new String[] { "copy" }, true); while (itr.hasNext()) { File file = itr.next(); String cleanPath = FilenameUtils.removeExtension(file.getAbsolutePath()); File cleanFile = new File(cleanPath); if (!cleanFile.exists()) { FileUtils.moveFile(file, new File(cleanPath)); } else { file.delete(); } } }
From source file:com.rubinefocus.admin.servlet.UploadServlet.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//from ww w . jav a 2s. c om * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //processRequest(request, response); try { PrintWriter out = response.getWriter(); File f = new File(this.getServletContext().getRealPath("/admin/assets/images/adminPic")); String savePath = f.getPath(); savePath = savePath.replace("%20", " "); savePath = savePath.replace("build", ""); String fileName = ""; for (Part part : request.getParts()) { fileName = extractFileName(part); fileName = fileName.replace(" ", ""); fileName = fileName.replace("-", ""); fileName = fileName.replace(":", ""); File file = new File(savePath + "/" + fileName); if (file.exists()) { String fileNameWithOutExt = FilenameUtils.removeExtension(fileName); String ext = FilenameUtils.getExtension(fileName); fileName = fileNameWithOutExt + new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date()) + "." + ext; fileName = fileName.replace(" ", ""); fileName = fileName.replace("-", ""); fileName = fileName.replace(":", ""); part.write(savePath + File.separator + fileName); } else { part.write(savePath + File.separator + fileName); } } } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.freedomotic.plugins.devices.simulation.TrackingReadFile.java
/** * Reads coordinates from file./*from w w w . j a va 2s.c o m*/ * * @param f file of coordinates */ private void readMoteFileCoordinates(File f) { ArrayList<Coordinate> coord = new ArrayList<>(); String userId = FilenameUtils.removeExtension(f.getName()); try (FileReader fr = new FileReader(f); BufferedReader br = new BufferedReader(fr);) { LOG.info("Reading coordinates from file \"{}\"", f.getAbsolutePath()); String line; while ((line = br.readLine()) != null) { //tokenize string StringTokenizer st = new StringTokenizer(line, ","); LOG.info("Mote \"{}\" coordinate added \"{}\"", userId, line); Coordinate c = new Coordinate(); c.setUserId(userId); c.setX(new Integer(st.nextToken())); c.setY(new Integer(st.nextToken())); c.setTime(new Integer(st.nextToken())); coord.add(c); } WorkerThread wt = new WorkerThread(this, coord, ITERATIONS); workers.add(wt); } catch (FileNotFoundException ex) { LOG.error("Coordinates file not found for mote \"{}\"", userId); } catch (IOException ex) { LOG.error("IOException: ", ex); } }
From source file:com.doculibre.constellio.utils.persistence.ConstellioPersistenceContext.java
private static void generatePersistenceFile() { //Usefull for unit testing String basePersistenceFileName = System.getProperty("base-persistence-file"); if (basePersistenceFileName == null) { basePersistenceFileName = "persistence_derby.xml"; }//from w w w.ja v a 2 s . c o m File classesDir = ClasspathUtils.getClassesDir(); File metaInfDir = new File(classesDir, "META-INF"); File persistenceFile = new File(metaInfDir, "persistence.xml"); File persistenceBaseFile = new File(metaInfDir, basePersistenceFileName); if (persistenceFile.exists()) { persistenceFile.delete(); } // FIXME Using text files rather than Dom4J because of empty xmlns attribute generated... try { String persistenceBaseText = FileUtils.readFileToString(persistenceBaseFile); StringBuffer sbJarFile = new StringBuffer("\n"); File pluginsDir = PluginFactory.getPluginsDir(); for (String availablePluginName : ConstellioSpringUtils.getAvailablePluginNames()) { if (PluginFactory.isValidPlugin(availablePluginName)) { File pluginDir = new File(pluginsDir, availablePluginName); File pluginJarFile = new File(pluginDir, availablePluginName + ".jar"); String pluginJarURI = pluginJarFile.toURI().toString(); sbJarFile.append("\n"); sbJarFile.append("<jar-file>" + pluginJarURI + "</jar-file>"); } } File webInfDir = ClasspathUtils.getWebinfDir(); File libDir = new File(webInfDir, "lib"); File[] contellioJarFiles = libDir.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { boolean accept; if (pathname.isDirectory()) { accept = false; } else { List<String> availablePluginNames = ConstellioSpringUtils.getAvailablePluginNames(); String jarNameWoutExtension = FilenameUtils.removeExtension(pathname.getName()); accept = availablePluginNames.contains(jarNameWoutExtension); } return accept; } }); for (File constellioJarFile : contellioJarFiles) { URI constellioJarFileURI = constellioJarFile.toURI(); sbJarFile.append("\n"); sbJarFile.append("<jar-file>" + constellioJarFileURI + "</jar-file>"); } String persistenceText = persistenceBaseText.replaceAll("</provider>", "</provider>" + sbJarFile); FileUtils.writeStringToFile(persistenceFile, persistenceText); // persistenceFile.deleteOnExit(); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.sleepcamel.ifdtoutils.MvnPluginMojo.java
private String fileToClass(File baseDirectory, File file) { String classFilePath = FilenameUtils.removeExtension(file.getPath()).replace(baseDirectory.getPath(), "") .substring(1);/* ww w . j a va 2 s . c o m*/ String className = classFilePath.replace(File.separatorChar, '.'); while (classFilePath.length() != className.length()) { classFilePath = className; className = classFilePath.replace(File.pathSeparatorChar, '.'); } return className; }
From source file:com.liferay.mobile.sdk.windows.WindowsSDKBuilder.java
protected void copyResource(String name, String destination) throws IOException { File destinationDir = new File(destination); destinationDir = destinationDir.getAbsoluteFile(); URL sourceURL = getClass().getResource(CharPool.SLASH + name); URLConnection sourceConnection = sourceURL.openConnection(); if (sourceConnection instanceof JarURLConnection) { copyJarResource((JarURLConnection) sourceConnection, destinationDir); } else {//from w w w . j a v a 2s.c o m File sourceDir = new File(sourceURL.getPath()); FileUtils.copyDirectory(sourceDir, destinationDir); } Iterator<File> itr = FileUtils.iterateFiles(destinationDir, new String[] { "copy" }, true); while (itr.hasNext()) { File file = itr.next(); String cleanPath = FilenameUtils.removeExtension(file.getAbsolutePath()); File cleanFile = new File(cleanPath); if (!cleanFile.exists()) { FileUtils.moveFile(file, new File(cleanPath)); } else { file.delete(); } } }
From source file:de.nbi.ontology.test.OntologyMatchTest.java
/** * Test, if terms are properly match to concept labels. The a list of terms * contains a term in each line.//from ww w.jav a 2 s . c o m * * @param inFile * a list of terms * @throws IOException */ @SuppressWarnings("unchecked") @Test(dataProviderClass = TestFileProvider.class, dataProvider = "synonymTestFiles", groups = { "functest" }) public void synonyms(File inFile) throws IOException { log.info("Processing " + inFile.getName()); String basename = FilenameUtils.removeExtension(inFile.getAbsolutePath()); File outFile = new File(basename + ".out"); File resFile = new File(basename + ".res"); List<String> terms = FileUtils.readLines(inFile); PrintWriter w = new PrintWriter(new FileWriter(outFile)); for (String term : terms) { OntClass clazz = index.getModel().getOntClass(term); log.trace("** matching " + term); w.println(index.getSynonyms(clazz)); } w.flush(); w.close(); Assert.assertTrue(FileUtils.contentEquals(outFile, resFile)); }
From source file:de.flapdoodle.embed.process.store.ExtractedArtifactStore.java
private File getTargetDirectoryForExtractedFiles(File artifact) throws IOException { if (_directory != null) { return _directory.asFile(); }//from w w w . j a v a 2 s.c o m File directory = new File(FilenameUtils.removeExtension(artifact.getAbsolutePath())); FileUtils.forceMkdir(directory); return directory; }
From source file:com.doculibre.constellio.plugins.PluginFactory.java
private static void initPluginManager() { if (pm == null) { pm = PluginManagerFactory.createPluginManager(); File classesDir = ClasspathUtils.getClassesDir(); pm.addPluginsFrom(classesDir.toURI()); File pluginsDir = getPluginsDir(); File[] pluginDirs = pluginsDir.listFiles(new FileFilter() { @Override/*from w w w. j a va 2 s.co m*/ public boolean accept(File pathname) { boolean accept; if (pathname.isFile()) { accept = false; } else if (DefaultConstellioPlugin.NAME.equals(pathname)) { accept = true; } else { List<String> availablePluginNames = ConstellioSpringUtils.getAvailablePluginNames(); accept = availablePluginNames.contains(pathname.getName()); } return accept; } }); if (pluginDirs == null) { return; } for (File pluginDir : pluginDirs) { // Plugin root dir jars Collection<File> pluginJarFiles = FileUtils.listFiles(pluginDir, new String[] { "jar" }, false); // Accept only one root dir jar File pluginJarFile = pluginJarFiles.isEmpty() ? null : pluginJarFiles.iterator().next(); if (pluginJarFile != null) { URI pluginJarFileURI = pluginJarFile.toURI(); pm.addPluginsFrom(pluginJarFileURI); PluginManagerImpl pmImpl = (PluginManagerImpl) pm; ClassPathManager classPathManager = pmImpl.getClassPathManager(); ClassLoader classLoader = ClassPathManagerUtils.getClassLoader(classPathManager, pluginJarFile); classLoaders.add(classLoader); File pluginLibDir = new File(pluginDir, "lib"); if (pluginLibDir.exists() && pluginLibDir.isDirectory()) { Collection<File> pluginDependencies = FileUtils.listFiles(pluginLibDir, new String[] { "jar" }, false); ClassPathManagerUtils.addJarDependencies(classPathManager, pluginJarFile, pluginDependencies); } } } File webInfDir = ClasspathUtils.getWebinfDir(); File libDir = new File(webInfDir, "lib"); File[] contellioJarFiles = libDir.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { boolean accept; if (pathname.isDirectory()) { accept = false; } else { List<String> availablePluginNames = ConstellioSpringUtils.getAvailablePluginNames(); String jarNameWoutExtension = FilenameUtils.removeExtension(pathname.getName()); accept = availablePluginNames.contains(jarNameWoutExtension); } return accept; } }); for (File constellioJarFile : contellioJarFiles) { URI constellioJarFileURI = constellioJarFile.toURI(); pm.addPluginsFrom(constellioJarFileURI); } } }