List of usage examples for org.apache.commons.io IOUtils DIR_SEPARATOR
char DIR_SEPARATOR
To view the source code for org.apache.commons.io IOUtils DIR_SEPARATOR.
Click Source Link
From source file:es.urjc.mctwp.bbeans.research.SessionInvBean.java
public String getRelativeThumbDir() { return IOUtils.DIR_SEPARATOR + ctxThumbDir.getPath(); }
From source file:edu.ur.file.db.TreeFolderInfoTest.java
/** * Test adding children functionality//from w ww. j av a 2 s .com * @throws LocationAlreadyExistsException */ @Test public void testAddChildren() throws LocationAlreadyExistsException { // this will create folders so we need to place them in directories String childrenPath = properties.getProperty("FolderInfoTest.children.path"); DefaultFileServer server = new DefaultFileServer("fileServer"); DefaultFileDatabase fd = server.createFileDatabase("displayName_20", "fileDB_20", childrenPath, "description"); TreeFolderInfo folder1 = FileSystemManager.createFolder("TreeFolderInfo1", fd); folder1.setDisplayName("displayName1"); String folderPath = fd.getFullPath(); folderPath += "TreeFolderInfo1" + IOUtils.DIR_SEPARATOR; assert folder1.getFullPath().equals(folderPath) : " Folder path should = " + folderPath + " but is " + folder1.getFullPath(); TreeFolderInfo child1 = folder1.createChild("displayName2", "child1"); folderPath += "child1" + IOUtils.DIR_SEPARATOR; assert child1.getFullPath().equals(folderPath) : "path should equal " + folderPath + "but equals " + child1.getFullPath(); TreeFolderInfo child2 = folder1.createChild("displayName3", "child2"); TreeFolderInfo subChild1 = child1.createChild("displayName4", "subChild1"); assert subChild1.getParent() == child1 : "Child 1 should be sub child's parent"; assert child1.getChildren().contains(subChild1) : "Child1 should contain sub child1"; TreeFolderInfo subChild2 = child1.createChild("displayName5", "subChild2"); assert child1.getChildren().contains(subChild2) : "Child1 should contain child 2"; assert folder1.getExists() : "Folder in file system"; assert folder1.getChildren().size() == 2 : "The number of folders should be 2 but is " + folder1.getChildren().size(); assert child1.getChildren().size() == 2 : "The number of folders should be 2 but is " + child1.getChildren().size(); assert child2.getChildren().size() == 0 : "The number of children should be 0 but is " + child2.getChildren().size(); assert folder1.getChild("child1").equals(child1) : "Child one should be found"; assert folder1.getChild("child2").equals(child2) : "Child two should be found"; assert folder1.getChild("child1").getChild("subChild1").equals(subChild1) : "sub child one should be found"; assert folder1.getChild("child1").getChild("subChild2").equals(subChild2) : "sub child two should be found"; assert folder1.isRoot() : "folder 1 should be root"; assert child1.getParent().equals(folder1) : "Child one parent should be folder 1"; assert subChild1.getParent().equals(child1) : "Child one should be parent of sub child1"; assert child1.getPath().equals(folder1.getFullPath()) : "Paths should be the same child 1 = " + child1.getPath() + " folder 1 = " + folder1.getFullPath(); assert child1.getChildren().contains(subChild2) : "Child1 should contain child 2"; assert child1.removeChild(subChild2) : "Sub child 2 should be removed"; TreeFolderInfo other2 = child1.getChild("subChild2"); assert other2 == null : "Sub child information should not exist"; assert child1.removeChild(subChild1) : "SubChild one should be deleted"; assert child1.getChild(subChild1.getName()) == null : "Sub Child 1 should not be in object"; assert subChild1.getParent() == null : "The child 1 should no longer have a parent"; assert subChild1.getFullPath() == null : "Subchild no longer has a path but path is " + subChild1.getFullPath(); folder1.removeChild(child1); assert folder1.getChild("child1") == null : "Should not find child 1"; FileSystemManager.deleteDirectory(fd.getFullPath()); }
From source file:eu.mrbussy.pdfsplitter.Application.java
/** * Split the given PDF file into multiple files using pages. * /*from w w w. j a v a2s .co m*/ * @param filename * - Name of the PDF to split * @param useSubFolder * - Use a separate folder to place the files in. */ public static void SplitFile(File file, boolean useSubFolder) { PdfReader reader = null; String format = null; if (useSubFolder) format = "%1$s%2$s%4$s%2$s_%%03d.%3$s"; else format = "%1$s%2$s_%%03d.%3$s"; String splitFile = String.format(format, FilenameUtils.getFullPath(file.getAbsolutePath()), FilenameUtils.getBaseName(file.getAbsolutePath()), FilenameUtils.getExtension(file.getAbsolutePath()), IOUtils.DIR_SEPARATOR); try { reader = new PdfReader(new FileInputStream(file)); if (reader.getNumberOfPages() > 0) { for (int pageNum = 1; pageNum <= reader.getNumberOfPages(); pageNum++) { System.out.println(String.format(splitFile, pageNum)); String filename = String.format(splitFile, pageNum); Document document = new Document(reader.getPageSizeWithRotation(1)); PdfCopy writer = new PdfCopy(document, new FileOutputStream(filename)); document.open(); // Copy the page from the original PdfImportedPage page = writer.getImportedPage(reader, pageNum); writer.addPage(page); document.close(); writer.close(); } } } catch (Exception ex) { // TODO Implement exception handling ex.printStackTrace(System.err); } finally { if (reader != null) // Always close the stream reader.close(); } }
From source file:com.mirth.connect.util.ArchiveUtils.java
/** * Extracts an archive using generic stream factories provided by commons-compress. *//*from w w w.j a v a2 s . c o m*/ private static void extractGenericArchive(File archiveFile, File destinationFolder) throws CompressException { try { InputStream inputStream = new BufferedInputStream(FileUtils.openInputStream(archiveFile)); try { inputStream = new CompressorStreamFactory().createCompressorInputStream(inputStream); } catch (CompressorException e) { // a compressor was not recognized in the stream, in this case we leave the inputStream as-is } ArchiveInputStream archiveInputStream = new ArchiveStreamFactory() .createArchiveInputStream(inputStream); ArchiveEntry entry; int inputOffset = 0; byte[] buffer = new byte[BUFFER_SIZE]; try { while (null != (entry = archiveInputStream.getNextEntry())) { File outputFile = new File( destinationFolder.getAbsolutePath() + IOUtils.DIR_SEPARATOR + entry.getName()); if (entry.isDirectory()) { FileUtils.forceMkdir(outputFile); } else { FileOutputStream outputStream = null; try { outputStream = FileUtils.openOutputStream(outputFile); int bytesRead; int outputOffset = 0; while ((bytesRead = archiveInputStream.read(buffer, inputOffset, BUFFER_SIZE)) > 0) { outputStream.write(buffer, outputOffset, bytesRead); inputOffset += bytesRead; outputOffset += bytesRead; } } finally { IOUtils.closeQuietly(outputStream); } } } } finally { IOUtils.closeQuietly(archiveInputStream); } } catch (Exception e) { throw new CompressException(e); } }
From source file:edu.ur.file.db.DefaultFileDatabase.java
/** * Get the full path for this file database * This includes the file database name. * /*w ww . j av a 2 s .c o m*/ * @return */ public String getFullPath() { return getPath() + name + IOUtils.DIR_SEPARATOR; }
From source file:edu.ur.file.db.FileSystemManagerTest.java
/** * Test moving a folder. /*from w ww . ja va2 s . com*/ * @throws LocationAlreadyExistsException * @throws IllegalFileSystemNameException */ @Test public void moveFolderWithFilesTest() throws LocationAlreadyExistsException, IllegalFileSystemNameException { // create a file server with the specified path String serverPath = properties.getProperty("FileSystemManagerTest.move.initial"); DefaultFileServer server = new DefaultFileServer("fileServer"); DefaultFileDatabase fd = server.createFileDatabase("displayName11", "fileDB_11", serverPath, "description"); TreeFolderInfo infoCurrent = FileSystemManager.createFolder("start1", fd); File f = new File(infoCurrent.getFullPath()); assert f.exists() : "Folder should be created"; // create the first file to store in the temporary folder String tempDirectory = properties.getProperty("file_db_temp_directory"); File directory = new File(tempDirectory); // helper to create the file FileUtil testUtil = new FileUtil(); testUtil.createDirectory(directory); // temporary path that the file will start in and then move it into the folder File folderFile = testUtil.creatFile(directory, "inFolderFile", "Hello - This is text in a file that is going to be deleted"); DefaultFileInfo myFileInfo = infoCurrent.createFileInfo(folderFile, "myFile"); myFileInfo.setId(1l); String endPath = properties.getProperty("FileSystemManagerTest.move.final"); DefaultFileDatabase fd2 = server.createFileDatabase("displayName12", "fileDB_12", endPath, "description"); TreeFolderInfo infoDest = FileSystemManager.createFolder("end1", fd2); File oldLocation = new File(infoCurrent.getFullPath()); assert oldLocation.exists() : "Folder " + oldLocation.getAbsolutePath() + " should exist"; infoDest.addChild(infoCurrent); assert !oldLocation.exists() : " Folder " + oldLocation.getAbsolutePath() + " should no longer exist"; String correctFolderName = FilenameUtils .separatorsToSystem(infoDest.getFullPath() + "start1" + IOUtils.DIR_SEPARATOR); assert infoCurrent.getFullPath().equals(correctFolderName) : "New path should equal " + correctFolderName + " but " + "equals " + infoCurrent.getFullPath(); assert infoCurrent.getFiles().size() == 1 : "Info Dest should have one child but has " + infoDest.getFiles().size(); DefaultFileInfo childFile = infoCurrent.getFileInfo(1L); assert childFile != null : "Child should not be null"; String nameToEqual = FilenameUtils.separatorsToSystem(infoCurrent.getFullPath() + childFile.getName()); assert childFile.getFullPath().equals(nameToEqual) : "File name should equal " + nameToEqual + " but " + " = " + childFile.getFullPath(); assert FileSystemManager.deleteFolder(infoDest) : "Folder Path should be deleted"; assert FileSystemManager.deleteFolder(infoCurrent) : "Folder Path should be deleted"; assert FileSystemManager.deleteDirectory(fd.getFullPath()); assert FileSystemManager.deleteDirectory(fd2.getFullPath()); }
From source file:edu.ur.file.db.DefaultFileDatabase.java
/** * Set the path of the folder. This makes no changes to the children * folders. The path must be a full path and cannot be relative. The path * must also include the prefix i.e. C:/ (for windows) or / (for unix). * /* w w w . j a v a 2s . c om*/ * * This converts the paths to the correct path immediately / for *NIX and \ * for windows. * * @param path */ void setPath(String path) { path = FilenameUtils.separatorsToSystem(path.trim()); // add the end separator if (path.charAt(path.length() - 1) != IOUtils.DIR_SEPARATOR) { path = path + IOUtils.DIR_SEPARATOR; } // get the prefix prefix = FilenameUtils.getPrefix(path).trim(); // the prefix cannot be null. if (prefix == null || prefix.equals("")) { throw new IllegalArgumentException("Path must have a prefix"); } this.path = FilenameUtils.getPath(path); }
From source file:com.mirth.connect.util.ArchiveUtils.java
/** * Extracts folders/files from a zip archive using zip-optimized code from commons-compress. *//*ww w. j a va2 s . c o m*/ private static void extractZipArchive(File archiveFile, File destinationFolder) throws CompressException { ZipFile zipFile = null; try { zipFile = new ZipFile(archiveFile); Enumeration<ZipArchiveEntry> entries = zipFile.getEntries(); ZipArchiveEntry entry = null; byte[] buffer = new byte[BUFFER_SIZE]; for (; entries.hasMoreElements(); entry = entries.nextElement()) { File outputFile = new File( destinationFolder.getAbsolutePath() + IOUtils.DIR_SEPARATOR + entry.getName()); if (entry.isDirectory()) { FileUtils.forceMkdir(outputFile); } else { InputStream inputStream = zipFile.getInputStream(entry); OutputStream outputStream = FileUtils.openOutputStream(outputFile); try { IOUtils.copyLarge(inputStream, outputStream, buffer); } finally { IOUtils.closeQuietly(inputStream); IOUtils.closeQuietly(outputStream); } } } } catch (Exception e) { throw new CompressException(e); } finally { ZipFile.closeQuietly(zipFile); } }
From source file:com.mirth.connect.plugins.datapruner.DataPruner.java
@Override public void run() { try {//from w w w.ja v a 2 s . com logger.debug("Executing pruner, started at " + new SimpleDateFormat("MM/dd/yyyy hh:mm aa").format(Calendar.getInstance().getTime())); if (pruneEvents) { pruneEvents(); } String date = new SimpleDateFormat(MessageWriterFactory.ARCHIVE_DATE_PATTERN) .format(Calendar.getInstance().getTime()); String archiveFolder = (archiveEnabled) ? archiverOptions.getRootFolder() + IOUtils.DIR_SEPARATOR + date : null; Queue<PrunerTask> taskQueue; try { taskQueue = buildTaskQueue(); } catch (Exception e) { // the error should already be logged return; } logger.debug("Pruner task queue built, " + taskQueue.size() + " channels will be processed"); Map<String, String> attributes = new HashMap<String, String>(); if (taskQueue.isEmpty()) { attributes.put("No messages to prune.", ""); eventController.dispatchEvent(new ServerEvent(serverId, DataPrunerService.PLUGINPOINT, Level.INFORMATION, Outcome.SUCCESS, attributes)); } while (!taskQueue.isEmpty()) { ThreadUtils.checkInterruptedStatus(); PrunerTask task = taskQueue.poll(); try { status.setCurrentChannelId(task.getChannelId()); status.setCurrentChannelName(task.getChannelName()); status.setTaskStartTime(Calendar.getInstance()); PruneResult result = pruneChannel(task.getChannelId(), task.getChannelName(), task.getMessageDateThreshold(), task.getContentDateThreshold(), archiveFolder, task.isArchiveEnabled()); status.getProcessedChannelIds().add(task.getChannelId()); attributes.put("Channel ID", task.getChannelId()); attributes.put("Channel Name", task.getChannelName()); if (archiveEnabled && task.isArchiveEnabled()) { attributes.put("Messages Archived", Long.toString(result.numMessagesArchived)); } attributes.put("Messages Pruned", Long.toString(result.numMessagesPruned)); attributes.put("Content Rows Pruned", Long.toString(result.numContentPruned)); attributes.put("Time Elapsed", getTimeElapsed()); eventController.dispatchEvent(new ServerEvent(serverId, DataPrunerService.PLUGINPOINT, Level.INFORMATION, Outcome.SUCCESS, attributes)); } catch (InterruptedException e) { throw e; } catch (Exception e) { status.getFailedChannelIds().add(task.getChannelId()); attributes.put("channel", task.getChannelName()); attributes.put("error", e.getMessage()); attributes.put("trace", ExceptionUtils.getStackTrace(e)); eventController.dispatchEvent(new ServerEvent(serverId, DataPrunerService.PLUGINPOINT, Level.ERROR, Outcome.FAILURE, attributes)); Throwable t = e; if (e instanceof DataPrunerException) { t = e.getCause(); } logger.error("Failed to prune messages for channel " + task.getChannelName() + " (" + task.getChannelId() + ").", t); } finally { status.getPendingChannelIds().remove(task.getChannelId()); status.setCurrentChannelId(null); status.setCurrentChannelName(null); } } logger.debug("Pruner job finished executing"); } catch (InterruptedException e) { // We need to clear this thread's interrupted status, or else the EventController will fail to dispatch the event Thread.interrupted(); ServerEvent event = new ServerEvent(serverId, DataPrunerService.PLUGINPOINT + " Halted"); event.setLevel(Level.INFORMATION); event.setOutcome(Outcome.SUCCESS); eventController.dispatchEvent(event); logger.debug("Data Pruner halted"); } catch (Throwable t) { logger.error("An error occurred while executing the data pruner", t); } finally { status.setEndTime(Calendar.getInstance()); lastStatus = SerializationUtils.clone(status); running.set(false); } }
From source file:com.taobao.datax.plugins.writer.ftpwriter.FtpWriter.java
private static String buildFilePath(String path, String fileName, String suffix) { char lastChar = path.charAt(path.length() - 1); if (lastChar != '/' && lastChar != '\\') { path = path + IOUtils.DIR_SEPARATOR; }//from w ww. j a v a 2s .com if (null == suffix) { suffix = ""; } else { suffix = suffix.trim(); } return String.format("%s%s%s", path, fileName, suffix); }