List of usage examples for org.apache.commons.io FilenameUtils normalize
public static String normalize(String filename)
From source file:com.orange.ocara.model.export.docx.DocxWriter.java
/** * Transforms the unzipped directory (templateDirectory) to exportFile docx file (exportFile) using exporter. * * @throws DocxWriterException If failed exportFile export *///from w w w .j av a2 s .com public void export() throws DocxWriterException { if (!checkDirectory(workingDirectory)) { throw new DocxWriterException("Working directory could not be checked"); } if (!checkFile(exportFile)) { throw new DocxWriterException("Export File could not be checked"); } if (exporter == null) { throw new DocxWriterException("Exporter could not be null"); } // compile try { exporter.compile(workingDirectory); } catch (DocxExporterException e) { throw new DocxWriterException("Failed to compile exporter", e); } // zip templateDirectory to exportFile final String rootPath = FilenameUtils.normalize(workingDirectory.getPath() + "/"); ZipOutputStream zos = null; try { zos = new ZipOutputStream(new FileOutputStream(exportFile)); zipDirectory(rootPath, workingDirectory, zos); } catch (IOException e) { throw new DocxWriterException("Failed to zip template directory", e); } finally { IOUtils.closeQuietly(zos); } }
From source file:com.moviejukebox.tools.PropertiesUtil.java
/** * Set the properties filename with a warning if the file is not found * * @param streamName//from w w w.ja v a 2s. com * @param warnFatal * @return */ public static boolean setPropertiesStreamName(final String streamName, boolean warnFatal) { LOG.info("Using properties file '{}'", FilenameUtils.normalize(streamName)); InputStream propertiesStream = ClassLoader.getSystemResourceAsStream(streamName); try { if (propertiesStream == null) { propertiesStream = new FileInputStream(streamName); } try (Reader reader = new InputStreamReader(propertiesStream, PROPERTIES_CHARSET)) { PROPS.load(reader); } } catch (IOException error) { // Output a warning if required. if (warnFatal) { LOG.error( "Failed loading file {}: Please check your configuration. The properties file should be in the classpath.", streamName, error); } else { LOG.debug("Warning (non-fatal): User properties file '{}', not found.", streamName); } return Boolean.FALSE; } finally { try { if (propertiesStream != null) { propertiesStream.close(); } } catch (IOException e) { // Ignore } } return Boolean.TRUE; }
From source file:net.sf.zekr.engine.server.DefaultHttpServerTest.java
public void testToUrl() throws Exception { String path = (String) server.pathLookup.get(HttpServer.BASE_RESOURCE); path = FilenameUtils.normalize(path + "/path/to/somewhere"); assertEquals(server.getUrl() + HttpServer.BASE_RESOURCE + "/path/to/somewhere", server.toUrl(path)); path = (String) server.pathLookup.get(HttpServer.WORKSPACE_RESOURCE); path = FilenameUtils.normalize(path + "/path/to/somewhere"); assertEquals(server.getUrl() + HttpServer.WORKSPACE_RESOURCE + "/path/to/somewhere", server.toUrl(path)); path = (String) server.pathLookup.get(HttpServer.CACHED_RESOURCE); path = FilenameUtils.normalize(path + "/path/to/somewhere"); assertEquals(server.getUrl() + HttpServer.CACHED_RESOURCE + "/path/to/somewhere", server.toUrl(path)); }
From source file:ch.unibas.fittingwizard.mocks.MockFitMtpScript.java
@Override public FitMtpOutput execute(FitMtpInput input) { File outputDir = new File(sessionDir, RealFitScript.OutputDirName); outputDir.mkdir();/*from w ww .ja va 2s . c o m*/ File testdataOutput = new File(testdataDir, RealFitScript.OutputDirName); File outputMockData = new File(testdataOutput, RealFitScript.ConsoleOutputFileName); File resultMockData = new File(testdataOutput, RealFitScript.FitResultFileName); File outputFile = new File(outputDir, RealFitScript.getOutputFileNameForFit(input.getFitId())); File resultsFile = new File(outputDir, RealFitScript.getResultFileNameForFit(input.getFitId())); try { logger.info(String.format("Copying mock data from %s to %s.", FilenameUtils.normalize(testdataOutput.getAbsolutePath()), FilenameUtils.normalize(outputDir.getAbsolutePath()))); FileUtils.copyFile(resultMockData, resultsFile); FileUtils.copyFile(outputMockData, outputFile); } catch (IOException e) { throw new RuntimeException("Could not copy mock data to output directory."); } FitMtpOutput output = new FitMtpOutput(outputFile, resultsFile); return output; }
From source file:com.abiquo.testng.TestServerAndAMListener.java
private static String getRelativeContextPath(String relpath) { return FilenameUtils.normalize(relpath); }
From source file:cop.maven.plugins.RamlMojoTest.java
@Test(groups = "getSourceDirectories") public void shouldReturnProjectBuildSourcePathWhenSourceDirectoryEmpty() throws Exception { mojo.project.getBuild().setSourceDirectory("aaa/bbb"); Set<File> files = mojo.getSourceDirectories(); assertThat(files).hasSize(1);/*from www.ja va 2 s .c o m*/ assertThat(files.iterator().next().getPath()).isEqualTo(FilenameUtils.normalize("aaa/bbb")); }
From source file:ch.unibas.fittingwizard.application.workflows.ExportFitWorkflow.java
/** * * @param input/*from ww w. j av a 2 s.c o m*/ * @return */ @Override public Void execute(WorkflowContext<ExportFitInput> input) { logger.info("Executing export workflow."); Fit fit = input.getParameter().getFit(); File destination = input.getParameter().getDestination(); if (destination == null) { destination = getDefaultExportDir(); logger.info("No destination passed. Using default destination: " + FilenameUtils.normalize(destination.getAbsolutePath())); } List<File> exportedFiles = new ArrayList<>(); for (MoleculeId moleculeId : fit.getAllMoleculeIds()) { ExportScriptOutput output = exportScript.execute(new ExportScriptInput(fit.getId(), moleculeId)); exportedFiles.add(output.getExportFile()); } copyToDestinationIfNecessary(exportedFiles, destination); return null; }
From source file:com.clank.launcher.builder.ClientFileCollector.java
@Override protected void onFile(File file, String relPath) throws IOException { if (file.getName().endsWith(FileInfoScanner.FILE_SUFFIX)) { return;/* w w w . java 2 s . com*/ } FileInstall entry = new FileInstall(); String hash = Files.hash(file, hf).toString(); String hashedPath = hash.substring(0, 2) + "/" + hash.substring(2, 4) + "/" + hash; File destPath = new File(destDir, hashedPath); entry.setHash(hash); entry.setLocation(hashedPath); entry.setTo(FilenameUtils.separatorsToUnix(FilenameUtils.normalize(relPath))); entry.setSize(file.length()); applicator.apply(entry); destPath.getParentFile().mkdirs(); ClientFileCollector.log.info(String.format("Adding %s from %s...", relPath, file.getAbsolutePath())); Files.copy(file, destPath); manifest.getTasks().add(entry); }
From source file:com.izforge.izpack.installer.bootstrap.Installer.java
private static void initializeLogging(String logFileName) throws IOException { if (logFileName != null) { final Properties props = new Properties(); final String cname = FileHandler.class.getName(); props.setProperty("handlers", cname); props.setProperty(cname + ".pattern", FilenameUtils.normalize(logFileName)); props.setProperty(cname + ".formatter", FileFormatter.class.getName()); props.setProperty(ConsoleHandler.class.getName() + ".level", "OFF"); props.setProperty(".level", "OFF"); LogUtils.loadConfiguration(props); } else {//from ww w .j a v a2s. com LogUtils.loadConfiguration(); } logger = Logger.getLogger(Installer.class.getName()); }
From source file:com.igormaznitsa.jcp.AbstractSpyPreprocessorContextTest.java
protected String getCurrentTestFolder() { final String testFolder = FilenameUtils.normalizeNoEndSeparator(System.getProperty("test.folder")); final String fullClassPath = this.getClass().getName().replace('.', File.separatorChar); return FilenameUtils.normalize(testFolder + File.separator + fullClassPath.substring(0, fullClassPath.lastIndexOf(File.separatorChar))); }