List of usage examples for org.apache.commons.io FilenameUtils separatorsToSystem
public static String separatorsToSystem(String path)
From source file:org.eclipse.jdt.ls.core.internal.managers.BasicFileDetectorTest.java
@Test public void testScanBuildFileAtRootExcludingNestedDirs() throws Exception { BasicFileDetector detector = new BasicFileDetector(Paths.get("projects/buildfiles"), "buildfile") .includeNested(false);/*from w w w . j a va2 s. c o m*/ Collection<Path> dirs = detector.scan(null); assertEquals("Found " + dirs, 1, dirs.size());// .metadata is ignored assertEquals(FilenameUtils.separatorsToSystem("projects/buildfiles"), dirs.iterator().next().toString()); }
From source file:org.eclipse.jdt.ls.core.internal.managers.BasicFileDetectorTest.java
private List<String> separatorsToSystem(List<String> paths) { return paths.stream().map(p -> FilenameUtils.separatorsToSystem(p)).collect(Collectors.toList()); }
From source file:org.eclipse.jdt.ls.core.internal.managers.BasicFileDetectorTest.java
@Test public void testScanNestedBuildFilesDepth2() throws Exception { BasicFileDetector detector = new BasicFileDetector(Paths.get("projects/buildfiles/parent"), "buildfile") .includeNested(false).maxDepth(2); Collection<Path> dirs = detector.scan(null); assertEquals("Found " + dirs, 1, dirs.size()); assertEquals(FilenameUtils.separatorsToSystem("projects/buildfiles/parent/1_1"), dirs.iterator().next().toString()); }
From source file:org.hoteia.qalingo.core.service.impl.RetailerServiceImpl.java
public String buildRetailerLogoFilePath(final Retailer retailer, final String logo) { String assetfileRootPath = engineSettingService.getAssetFileRootPath().getDefaultValue(); if (assetfileRootPath.endsWith("/")) { assetfileRootPath = assetfileRootPath.substring(0, assetfileRootPath.length() - 1); }//from ww w. j a va 2s . com String retailerLogoFilePath = engineSettingService.getAssetRetailerAndStoreFilePath().getDefaultValue(); if (retailerLogoFilePath.endsWith("/")) { retailerLogoFilePath = retailerLogoFilePath.substring(0, retailerLogoFilePath.length() - 1); } if (!retailerLogoFilePath.startsWith("/")) { retailerLogoFilePath = "/" + retailerLogoFilePath; } String absoluteFolderPath = new StringBuilder(assetfileRootPath).append(retailerLogoFilePath) .append("/retailer-logo/").append(retailer.getCode()).append("/").toString(); String absoluteFilePath = new StringBuilder(absoluteFolderPath).append(logo).toString(); return FilenameUtils.separatorsToSystem(absoluteFilePath); }
From source file:org.hoteia.qalingo.core.service.RetailerService.java
public String buildRetailerLogoFilePath(final Retailer retailer, final String logo) { String assetfileRootPath = engineSettingService.getSettingAssetFileRootPath().getDefaultValue(); if (assetfileRootPath.endsWith("/")) { assetfileRootPath = assetfileRootPath.substring(0, assetfileRootPath.length() - 1); }// ww w .ja va 2 s . co m String retailerLogoFilePath = engineSettingService.getSettingAssetRetailerAndStoreFilePath() .getDefaultValue(); if (retailerLogoFilePath.endsWith("/")) { retailerLogoFilePath = retailerLogoFilePath.substring(0, retailerLogoFilePath.length() - 1); } if (!retailerLogoFilePath.startsWith("/")) { retailerLogoFilePath = "/" + retailerLogoFilePath; } String absoluteFolderPath = new StringBuilder(assetfileRootPath).append(retailerLogoFilePath) .append("/retailer-logo/").append(retailer.getCode()).append("/").toString(); String absoluteFilePath = new StringBuilder(absoluteFolderPath).append(logo).toString(); return FilenameUtils.separatorsToSystem(absoluteFilePath); }
From source file:org.jasig.ssp.service.impl.StudentDocumentServiceImpl.java
private synchronized String calculateNewRelativeFileLocation(String originalFileName) { if (volumes.isEmpty()) { initVolumes();/*www .j a v a 2 s . c o m*/ } //base + next volume String volume = volumes.get(lastVolumeIndex++); volume = "".equals(volume) ? volume : "/" + volume; String location = volume; //+ year + month + originalFileName location = location + "/" + Calendar.getInstance().get(Calendar.YEAR) + "/" + Calendar.getInstance().get(Calendar.MONTH) + "/" + Calendar.getInstance().getTimeInMillis(); //mod the index so the index is never > volumes.size() lastVolumeIndex = lastVolumeIndex % volumes.size(); return FilenameUtils.separatorsToSystem(location); }
From source file:org.jboss.windup.interrogator.DirectoryInterrogationEngine.java
public DirectoryMetadata process(File outputDirectory, File targetDirectory) { //this will recurse all files from this directory; all but hidden directories. RecursiveDirectoryMetaFactory rdmf = new RecursiveDirectoryMetaFactory(targetDirectory); List<DirectoryMetadata> directories = new LinkedList<DirectoryMetadata>(); DirectoryMetadata root = rdmf.recursivelyExtract(); unfoldRecursion(root, directories);/*from www .j a v a2 s . c om*/ int i = 1; int j = directories.size(); for (DirectoryMetadata directoryMeta : directories) { LOG.info("Interrogating (" + i + " of " + j + "): " + directoryMeta.getRelativePath()); Collection<File> files = FileUtils.listFiles(directoryMeta.getFilePointer(), TrueFileFilter.INSTANCE, null); if (LOG.isDebugEnabled()) { LOG.debug(" Processing " + files.size() + " files within directory."); } if (outputDirectory != null) { String dirOutput = FilenameUtils.normalize(FilenameUtils.separatorsToSystem( outputDirectory.getAbsolutePath() + File.separatorChar + directoryMeta.getRelativePath())); directoryMeta.setArchiveOutputDirectory(new File(dirOutput)); } for (Interrogator<?> interrogator : interrogators) { for (File file : files) { if (file.isFile()) { LOG.debug("Processing file: " + file.getAbsolutePath()); TempSourceMetadata fileMeta = new TempSourceMetadata(file); fileMeta.setArchiveMeta(directoryMeta); LOG.debug("Set archive as: " + directoryMeta); interrogator.processFile(fileMeta); } } } i++; } return root; }
From source file:org.jboss.windup.util.RPMToZipTransformer.java
public static File convertRpmToZip(File file) throws Exception { LOG.info("File: " + file.getAbsolutePath()); FileInputStream fis = new FileInputStream(file); ReadableChannelWrapper in = new ReadableChannelWrapper(Channels.newChannel(fis)); InputStream uncompressed = new GZIPInputStream(fis); in = new ReadableChannelWrapper(Channels.newChannel(uncompressed)); String rpmZipName = file.getName(); rpmZipName = StringUtils.replace(rpmZipName, ".", "-"); rpmZipName = rpmZipName + ".zip"; String rpmZipPath = FilenameUtils.getFullPath(file.getAbsolutePath()); File rpmZipOutput = new File(rpmZipPath + File.separator + rpmZipName); LOG.info("Converting RPM: " + file.getName() + " to ZIP: " + rpmZipOutput.getName()); ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(rpmZipOutput)); String rpmName = file.getName(); rpmName = StringUtils.replace(rpmName, ".", "-"); CpioHeader header;//from w w w .j a v a 2 s .com int total = 0; do { header = new CpioHeader(); total = header.read(in, total); if (header.getFileSize() > 0) { BoundedInputStream bis = new BoundedInputStream(uncompressed, header.getFileSize()); String relPath = FilenameUtils.separatorsToSystem(header.getName()); relPath = StringUtils.removeStart(relPath, "."); relPath = StringUtils.removeStart(relPath, "/"); relPath = rpmName + File.separator + relPath; relPath = StringUtils.replace(relPath, "\\", "/"); ZipEntry zipEntry = new ZipEntry(relPath); zos.putNextEntry(zipEntry); IOUtils.copy(bis, zos); } else { final int skip = header.getFileSize(); if (uncompressed.skip(skip) != skip) throw new RuntimeException("Skip failed."); } total += header.getFileSize(); } while (!header.isLast()); zos.flush(); zos.close(); return rpmZipOutput; }
From source file:org.jenkinsci.plugins.skytap.SkytapUtils.java
/** * Prepends the workspace path to a save file name as a default if user has * not provided a full path./*from w w w. java2 s .co m*/ * * @param build * @param savefile * * @return fullpath * */ public static String convertFileNameToFullPath(AbstractBuild build, String savefile) { FilenameUtils fu = new FilenameUtils(); // if its just a filename with no path, prepend workspace dir if (fu.getPath(savefile).equals("")) { JenkinsLogger.log( "File: " + savefile + " was specified without a path. Defaulting path to Jenkins workspace."); String workspacePath = SkytapUtils.expandEnvVars(build, "${WORKSPACE}"); savefile = workspacePath + "/" + savefile; savefile = fu.separatorsToSystem(savefile); return savefile; } else { return fu.separatorsToSystem(savefile); } }
From source file:org.jwebsocket.util.Tools.java
/** * Return TRUE if the file is located inside of the given base path, FALSE otherwise * * @param aFile/* w ww.j av a 2 s.co m*/ * @param aBasePath * @return */ public static boolean isParentPath(File aFile, String aBasePath) { try { String lCanonicalPath = FilenameUtils.separatorsToSystem(aFile.getCanonicalPath()) + File.separator; String lBasePath = FilenameUtils.separatorsToSystem(aBasePath); if (SystemUtils.IS_OS_WINDOWS) { if (lCanonicalPath.toLowerCase().startsWith(lBasePath.toLowerCase())) { return true; } } else { if (!lCanonicalPath.startsWith(lBasePath)) { return false; } } } catch (IOException lEx) { return false; } return true; }