List of usage examples for org.apache.commons.io FilenameUtils separatorsToUnix
public static String separatorsToUnix(String path)
From source file:org.silverpeas.core.util.FileUtilTest.java
@BeforeEach public void setUp() throws IOException { rootFolder = File.createTempFile("root", "Folder"); if (rootFolder.exists()) { FileUtils.deleteQuietly(rootFolder); rootFolder = new File(FileUtils.getTempDirectory(), "rootFolder_" + UUID.randomUUID().toString()); }//from w w w .jav a2 s . com rootFolder.mkdirs(); FileUtils.touch(new File(rootFolder, "atRoot.txt")); File subFolderA = new File(rootFolder, "SubFolderA"); subFolderA.mkdir(); FileUtils.touch(new File(subFolderA, "atSubFolderA_1.txt")); FileUtils.touch(new File(subFolderA, "atSubFolderA_2.txt")); File subFolderB = new File(rootFolder, "SubFolderB"); subFolderB.mkdir(); FileUtils.touch(new File(subFolderB, "atSubFolderB_1.txt")); FileUtils.touch(new File(subFolderB, "sameName.txt")); File subFolderBSubFolderA = new File(subFolderB, "SubFolderBSubFolderA"); subFolderBSubFolderA.mkdir(); FileUtils.touch(new File(subFolderBSubFolderA, "atSubFolderBSubFolderA_1.txt")); FileUtils.touch(new File(subFolderBSubFolderA, "atSubFolderBSubFolderA_2.txt")); FileUtils.touch(new File(subFolderBSubFolderA, "sameName.txt")); String[] expectedFiles = new String[] { "/atRoot.txt", "/SubFolderA/atSubFolderA_1.txt", "/SubFolderA/atSubFolderA_2.txt", "/SubFolderB/atSubFolderB_1.txt", "/SubFolderB/sameName.txt", "/SubFolderB/SubFolderBSubFolderA/atSubFolderBSubFolderA_1.txt", "/SubFolderB/SubFolderBSubFolderA/atSubFolderBSubFolderA_2.txt", "/SubFolderB/SubFolderBSubFolderA/sameName.txt" }; List<String> actualFiles = new ArrayList<String>(); int substringIndex = rootFolder.getPath().length(); for (File file : FileUtils.listFiles(rootFolder, FileFilterUtils.trueFileFilter(), FileFilterUtils.trueFileFilter())) { actualFiles.add(FilenameUtils.separatorsToUnix(file.getPath().substring(substringIndex))); } assertThat(actualFiles, containsInAnyOrder(expectedFiles)); }
From source file:org.silverpeas.core.util.FileUtilTest.java
@Test public void testMoveAllFilesAtRootFolder() throws IOException { File[] foldersAtRoot = FileUtil.moveAllFilesAtRootFolder(rootFolder); assertThat(foldersAtRoot, arrayWithSize(2)); for (File folder : foldersAtRoot) { assertThat(folder.exists(), is(false)); }//from w ww . j a v a 2 s . c om String[] expectedFiles = new String[] { "/atRoot.txt", "/atSubFolderA_1.txt", "/atSubFolderA_2.txt", "/atSubFolderB_1.txt", "/atSubFolderBSubFolderA_1.txt", "/atSubFolderBSubFolderA_2.txt", "/sameName.txt" }; List<String> actualFiles = new ArrayList<String>(); int substringIndex = rootFolder.getPath().length(); for (File file : FileUtils.listFiles(rootFolder, FileFilterUtils.trueFileFilter(), FileFilterUtils.trueFileFilter())) { actualFiles.add(FilenameUtils.separatorsToUnix(file.getPath().substring(substringIndex))); } assertThat(actualFiles, containsInAnyOrder(expectedFiles)); }
From source file:org.silverpeas.core.util.ZipUtil.java
/** * Mthode compressant un dossier de faon rcursive au format zip. * * @param folderToZip - dossier compresser * @param zipFile - fichier zip creer/*from www . j a v a 2 s. c o m*/ * @return la taille du fichier zip gnr en octets * @throws FileNotFoundException * @throws IOException */ public static long compressPathToZip(File folderToZip, File zipFile) throws IOException { try (ZipArchiveOutputStream zos = new ZipArchiveOutputStream(new FileOutputStream(zipFile))) { zos.setFallbackToUTF8(true); zos.setCreateUnicodeExtraFields(NOT_ENCODEABLE); zos.setEncoding(Charsets.UTF_8.name()); Collection<File> folderContent = FileUtils.listFiles(folderToZip, null, true); for (File file : folderContent) { String entryName = file.getPath().substring(folderToZip.getParent().length() + 1); entryName = FilenameUtils.separatorsToUnix(entryName); zos.putArchiveEntry(new ZipArchiveEntry(entryName)); try (InputStream in = new FileInputStream(file)) { IOUtils.copy(in, zos); zos.closeArchiveEntry(); } } } return zipFile.length(); }
From source file:org.silverpeas.core.viewer.util.SwfUtilTest.java
private static String separatorsToUnix(String filePath) { return FilenameUtils.separatorsToUnix(filePath).replaceAll("[a-zA-Z]:", ""); }
From source file:org.silverpeas.process.io.file.AbstractFileHandler.java
/** * Gets handled root directories of a base path from the session. (reads, writes, deletes) * @param basePath//ww w.ja v a 2 s .c o m * @param skipDeleted * @return */ protected Collection<String> getSessionHandledRootPathNames(final FileBasePath basePath, final boolean skipDeleted) { final Set<String> rootPathNames = new HashSet<String>(); if (isHandledPath(basePath)) { // reads and writes final String[] directories = getSessionPath(basePath).list(DirectoryFileFilter.DIRECTORY); if (directories != null) { rootPathNames.addAll(Arrays.asList(directories)); } // deletes if (!skipDeleted) { String[] deletedFileNameParts; for (final File deleted : getMarkedToDelete(basePath)) { if (deleted.getPath().startsWith(basePath.getPath())) { deletedFileNameParts = FilenameUtils .separatorsToUnix(deleted.getPath().substring(basePath.getPath().length())) .replaceAll("^/", "").split("/"); if (deletedFileNameParts != null && deletedFileNameParts.length > 0) { rootPathNames.add(deletedFileNameParts[0]); } } } } // Potential items to remove rootPathNames.remove(SESSION_TEMP_NODE); rootPathNames.remove(null); rootPathNames.remove(""); } return rootPathNames; }
From source file:org.silverpeas.search.indexEngine.model.RepositoryIndexer.java
private void indexDirectory(String action, String creationDate, String creatorId, File directory) { String unixDirectoty = FilenameUtils.separatorsToUnix(directory.getPath()); if (ADD_ACTION.equals(action)) { // indexer le rpertoire FullIndexEntry fullIndexEntry = new FullIndexEntry(getComponentId(), "LinkedDir", unixDirectoty); fullIndexEntry.setTitle(directory.getName()); fullIndexEntry.setCreationDate(creationDate); fullIndexEntry.setCreationUser(creatorId); IndexEngineProxy.addIndexEntry(fullIndexEntry); count++;/*from w w w . j a va2 s . co m*/ } else if (REMOVE_ACTION.equals(action)) { IndexEntryPK indexEntry = new IndexEntryPK(getComponentId(), "LinkedDir", unixDirectoty); IndexEngineProxy.removeIndexEntry(indexEntry); } }
From source file:org.silverpeas.search.indexEngine.model.RepositoryIndexer.java
public void indexFile(String action, String creationDate, String creatorId, File file) { // String path = currentPath + separator + fileName; String unixFilePath = FilenameUtils.separatorsToUnix(file.getPath()); if (ADD_ACTION.equals(action)) { String fileName = file.getName(); // Add file in index FullIndexEntry fullIndexEntry = new FullIndexEntry(getComponentId(), "LinkedFile", unixFilePath); fullIndexEntry.setTitle(fileName); boolean haveGotExtension = (fileName.lastIndexOf('.') != -1); if (haveGotExtension) { fullIndexEntry.setPreView(fileName.substring(0, fileName.lastIndexOf('.'))); } else {// www .j av a2s . co m fullIndexEntry.setPreView(fileName); } fullIndexEntry.setCreationDate(creationDate); fullIndexEntry.setCreationUser(creatorId); if (haveGotExtension && !fileName.startsWith("~")) { String format = FileUtil.getMimeType(fileName); String lang = "fr"; fullIndexEntry.addFileContent(unixFilePath, null, format, lang); } IndexEngineProxy.addIndexEntry(fullIndexEntry); count++; } else if (REMOVE_ACTION.equals(action)) { // Remove file from index IndexEntryPK indexEntry = new IndexEntryPK(getComponentId(), "LinkedFile", unixFilePath); IndexEngineProxy.removeIndexEntry(indexEntry); } }
From source file:org.silverpeas.util.ConfigurationHolder.java
/** * Gets the home directory of the JCR repository in Silverpeas. * * @return the absolute path of the JCR repository home directory. * @throws IOException if an errors occurs while getting the parameter. *///from w ww.j ava 2s . c om public static String getJCRRepositoryHome() throws IOException { String repositoryHome = ConfigurationHolder.getDataHome() + File.separatorChar + "jackrabbit"; Properties props = FileUtil.loadResource(JCR_PROPERTIES); repositoryHome = props.getProperty(JCR_HOME_KEY, repositoryHome); File repositoryHomeDir; if (repositoryHome.toLowerCase().startsWith("file:")) { repositoryHomeDir = new File(URI.create(FilenameUtils.separatorsToUnix(repositoryHome))); } else { repositoryHomeDir = new File(repositoryHome); } if (!repositoryHomeDir.isDirectory()) { throw new FileNotFoundException("The JCR home directory '" + repositoryHome + "' isn't found"); } return repositoryHomeDir.getAbsolutePath(); }
From source file:org.siphon.d2js.jshttp.ServerUnitManager.java
public String localFilePathToRequestPath(String srcFile) { String delta = FilenameUtils.separatorsToUnix(srcFile.substring(srcFolder.length())); return (delta.charAt(0) != '/') ? "/" + delta : delta; }
From source file:org.skb.kb.SKB.java
/** * Loads all available packages for the current site. * //w w w .j a va 2s. co m * This function loads all available (installed) packages for the current site ($site_id). * This can be practical when loading individual packages is inconvenient. It is used for * viewing configuration by the Core.SkbConfig package. * @param additional */ public void loadAllSitePackages(ArrayList<String> additional) { String pkg_dir = this.configuration.get("path/repository").toString(); String site_id = this.configuration.get("skb/site-id").toString(); FindPackageDirectories fpd = new FindPackageDirectories(); fpd.siteID(site_id); List<String> files = fpd.getTxtFiles(pkg_dir); pkg_dir = pkg_dir.replace(FilenameUtils.getPrefix(pkg_dir), ""); for (int i = 0; i < files.size(); i++) { String fn = files.get(i); fn = fn.replace(FilenameUtils.getPrefix(fn), ""); fn = fn.replace(FilenameUtils.separatorsToUnix(pkg_dir), ""); fn = fn.replace("/", "."); this.requirePackage(fn); } // in_array(str_replace($pkg_dir,"",$pkg),$additional) }