List of usage examples for org.apache.commons.io FilenameUtils separatorsToSystem
public static String separatorsToSystem(String path)
From source file:org.apereo.portal.utils.AntPatternFileFilter.java
private String fixAntPattern(String pattern) { pattern = FilenameUtils.separatorsToSystem(pattern); if (!SelectorUtils.hasWildcards(pattern)) { pattern = "**" + File.separatorChar + pattern; }//from w w w . java2 s. c o m return pattern; }
From source file:org.broadleafcommerce.cms.file.service.StaticAssetStorageServiceImpl.java
@Transactional("blTransactionManagerAssetStorageInfo") @Override// ww w . j ava2s. c om public void createStaticAssetStorage(InputStream fileInputStream, StaticAsset staticAsset) throws IOException { if (StorageType.DATABASE.equals(staticAsset.getStorageType())) { StaticAssetStorage storage = staticAssetStorageDao.create(); storage.setStaticAssetId(staticAsset.getId()); Blob uploadBlob = staticAssetStorageDao.createBlob(fileInputStream, staticAsset.getFileSize()); storage.setFileData(uploadBlob); staticAssetStorageDao.save(storage); } else if (StorageType.FILESYSTEM.equals(staticAsset.getStorageType())) { FileWorkArea tempWorkArea = broadleafFileService.initializeWorkArea(); // Convert the given URL from the asset to a system-specific suitable file path String destFileName = FilenameUtils.normalize(tempWorkArea.getFilePathLocation() + File.separator + FilenameUtils.separatorsToSystem(staticAsset.getFullUrl())); InputStream input = fileInputStream; byte[] buffer = new byte[fileBufferSize]; File destFile = new File(destFileName); if (!destFile.getParentFile().exists()) { if (!destFile.getParentFile().mkdirs()) { if (!destFile.getParentFile().exists()) { throw new RuntimeException("Unable to create parent directories for file: " + destFileName); } } } OutputStream output = new FileOutputStream(destFile); boolean deleteFile = false; try { int bytesRead; int totalBytesRead = 0; while ((bytesRead = input.read(buffer)) != -1) { totalBytesRead += bytesRead; if (totalBytesRead > maxUploadableFileSize) { deleteFile = true; throw new IOException("Maximum Upload File Size Exceeded"); } output.write(buffer, 0, bytesRead); } // close the output file stream prior to moving files around output.close(); broadleafFileService.addOrUpdateResource(tempWorkArea, destFile, deleteFile); } finally { IOUtils.closeQuietly(output); broadleafFileService.closeWorkArea(tempWorkArea); } } }
From source file:org.broadleafcommerce.common.file.service.BroadleafFileServiceImpl.java
protected File getLocalResource(String resourceName, boolean skipSite) { if (skipSite) { String baseDirectory = getBaseDirectory(skipSite); // convert the separators to the system this is currently run on String systemResourcePath = FilenameUtils.separatorsToSystem(resourceName); String filePath = FilenameUtils.normalize(baseDirectory + File.separator + systemResourcePath); return new File(filePath); } else {/*ww w .j a v a2 s .c om*/ String baseDirectory = getBaseDirectory(true); ExtensionResultHolder<String> holder = new ExtensionResultHolder<String>(); if (extensionManager != null) { ExtensionResultStatusType result = extensionManager.getProxy().processPathForSite(baseDirectory, resourceName, holder); if (!ExtensionResultStatusType.NOT_HANDLED.equals(result)) { return new File(holder.getResult()); } } return getLocalResource(resourceName, true); } }
From source file:org.broadleafcommerce.common.resource.service.ResourceBundlingServiceImpl.java
protected void saveBundle(Resource resource) { FileWorkArea tempWorkArea = fileService.initializeWorkArea(); String fileToSave = FilenameUtils.separatorsToSystem(getResourcePath(resource.getDescription())); String tempFilename = FilenameUtils.concat(tempWorkArea.getFilePathLocation(), fileToSave); File tempFile = new File(tempFilename); if (!tempFile.getParentFile().exists()) { if (!tempFile.getParentFile().mkdirs()) { if (!tempFile.getParentFile().exists()) { throw new RuntimeException("Unable to create parent directories for file: " + tempFilename); }// w w w .ja va2s.c om } } BufferedOutputStream out = null; InputStream ris = null; try { ris = resource.getInputStream(); out = new BufferedOutputStream(new FileOutputStream(tempFile)); StreamUtils.copy(ris, out); ris.close(); out.close(); fileService.addOrUpdateResourceForPath(tempWorkArea, tempFile, true); } catch (IOException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(ris); IOUtils.closeQuietly(out); fileService.closeWorkArea(tempWorkArea); } }
From source file:org.codehaus.mojo.gwt.shell.CSSMojo.java
public void doExecute() throws MojoExecutionException, MojoFailureException { setup();/*w w w.ja v a 2 s . c o m*/ boolean generated = false; // java -cp gwt-dev.jar:gwt-user.jar // com.google.gwt.resources.css.InterfaceGenerator -standalone -typeName some.package.MyCssResource -css // input.css if (cssFiles != null) { for (String file : cssFiles) { final String typeName = FilenameUtils.separatorsToSystem(file).substring(0, file.lastIndexOf('.')) .replace(File.separatorChar, '.'); final File javaOutput = new File(getGenerateDirectory(), typeName.replace('.', File.separatorChar) + ".java"); final StringBuilder content = new StringBuilder(); out = new StreamConsumer() { public void consumeLine(String line) { content.append(line).append(SystemUtils.LINE_SEPARATOR); } }; for (Resource resource : (List<Resource>) getProject().getResources()) { final File candidate = new File(resource.getDirectory(), file); if (candidate.exists()) { getLog().info("Generating " + javaOutput + " with typeName " + typeName); ensureTargetPackageExists(getGenerateDirectory(), typeName); try { new JavaCommand("com.google.gwt.resources.css.InterfaceGenerator") .withinScope(Artifact.SCOPE_COMPILE).arg("-standalone").arg("-typeName") .arg(typeName).arg("-css").arg(candidate.getAbsolutePath()) .withinClasspath(getGwtDevJar()).withinClasspath(getGwtUserJar()).execute(); final FileWriter outputWriter = new FileWriter(javaOutput); outputWriter.write(content.toString()); outputWriter.close(); } catch (IOException e) { throw new MojoExecutionException("Failed to write to file: " + javaOutput); } generated = true; break; } } if (content.length() == 0) { throw new MojoExecutionException("cannot generate java source from file " + file + "."); } } } if (generated) { getLog().debug("add compile source root " + getGenerateDirectory()); addCompileSourceRoot(getGenerateDirectory()); } }
From source file:org.codice.ddf.configuration.migration.ImportMigrationEntryImpl.java
/** * Instantiates a new migration entry by parsing the provided zip entry's name for a migratable * identifier and an entry relative name. * * @param contextProvider a provider for migration contexts given a migratable id * @param ze the zip entry for which we are creating an entry *///from w w w . ja va 2s. c o m ImportMigrationEntryImpl(Function<String, ImportMigrationContextImpl> contextProvider, ZipEntry ze) { // we still must sanitize because there could be a mix of / and \ and Paths.get() doesn't // support that final Path fqn = Paths.get(FilenameUtils.separatorsToSystem(ze.getName())); final int count = fqn.getNameCount(); if (count > 1) { this.context = contextProvider.apply(fqn.getName(0).toString()); this.path = fqn.subpath(1, count); } else { // system entry this.context = contextProvider.apply(null); this.path = fqn; } this.absolutePath = context.getPathUtils().resolveAgainstDDFHome(path); this.file = absolutePath.toFile(); this.name = FilenameUtils.separatorsToUnix(path.toString()); this.entry = ze; this.isFile = true; }
From source file:org.codice.ddf.configuration.migration.ImportMigrationJavaPropertyReferencedEntryImpl.java
ImportMigrationJavaPropertyReferencedEntryImpl(ImportMigrationContextImpl context, Map<String, Object> metadata) { super(context, metadata); this.propertiesPath = Paths.get(FilenameUtils .separatorsToSystem(JsonUtils.getStringFrom(metadata, MigrationEntryImpl.METADATA_NAME, true))); }
From source file:org.codice.ddf.configuration.migration.ImportMigrationPropertyReferencedEntryImplTest.java
@Test public void testCompareToWhenNameDifferent() throws Exception { final String migratableName2 = "where/some/dir/test2.txt"; final Path migratablePath2 = Paths.get(FilenameUtils.separatorsToSystem(migratableName2)); final Map<String, Object> metadata2 = ImmutableMap.of(MigrationEntryImpl.METADATA_REFERENCE, migratableName2, MigrationEntryImpl.METADATA_PROPERTY, MIGRATABLE_PROPERTY); Mockito.when(context.getOptionalEntry(migratablePath2)).thenReturn(Optional.of(referencedEntry)); final ImportMigrationPropertyReferencedEntryImpl entry2 = Mockito .mock(ImportMigrationPropertyReferencedEntryImpl.class, Mockito.withSettings() .useConstructor(context, metadata2).defaultAnswer(Answers.CALLS_REAL_METHODS)); Assert.assertThat(entry.compareTo(entry2), Matchers.not(Matchers.equalTo(0))); }
From source file:org.dataconservancy.dcs.util.FilePathUtil.java
/** * This method has been deprecated use Apache FileNameUtils instead. * Takes the provided file path and converts all slashes to the platform specific slash. * @param filePath The file path to convert the slashes on. * @return The file path with slash converted to the platform specific slashes, or the original filepath string if * slashes aren't used as the file separator character. Returns null if the file path object is null. *//*from w ww . j a va2s .c o m*/ @Deprecated public static String convertToPlatformSpecificSlash(String filePath) { return FilenameUtils.separatorsToSystem(filePath); }
From source file:org.dataconservancy.packaging.impl.OpenPackageService.java
private File extract(final File dest_dir, final ArchiveEntry entry, final ArchiveInputStream ais) throws IOException { final String path = FilenameUtils.separatorsToSystem(entry.getName()); final File file = new File(dest_dir, path); if (entry.isDirectory()) { file.mkdirs();//www . ja v a 2 s .co m } else { if (file.getParentFile() != null) { file.getParentFile().mkdirs(); } try (OutputStream os = new FileOutputStream(file)) { IOUtils.copyLarge(ais, os, 0, entry.getSize()); } catch (final IOException e) { throw new IOException("Couldn't create " + file.toString() + ". Please make sure you have write access for the extract directory.", e); } } return new File(path); }