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:be.redlab.maven.yamlprops.create.YamlConvertCli.java
public static void main(String... args) throws IOException { CommandLineParser parser = new DefaultParser(); Options options = new Options(); HelpFormatter formatter = new HelpFormatter(); options.addOption(Option.builder("s").argName("source").desc("the source folder or file to convert") .longOpt("source").hasArg(true).build()); options.addOption(Option.builder("t").argName("target").desc("the target file to store in") .longOpt("target").hasArg(true).build()); options.addOption(Option.builder("h").desc("print help").build()); try {//from w ww . j ava2s . c o m CommandLine cmd = parser.parse(options, args); if (cmd.hasOption('h')) { formatter.printHelp("converter", options); } File source = new File(cmd.getOptionValue("s", System.getProperty("user.dir"))); String name = source.getName(); if (source.isDirectory()) { PropertiesToYamlConverter yamlConverter = new PropertiesToYamlConverter(); String[] ext = { "properties" }; Iterator<File> fileIterator = FileUtils.iterateFiles(source, ext, true); while (fileIterator.hasNext()) { File next = fileIterator.next(); System.out.println(next); String s = StringUtils.removeStart(next.getParentFile().getPath(), source.getPath()); System.out.println(s); String f = StringUtils.split(s, IOUtils.DIR_SEPARATOR)[0]; System.out.println("key = " + f); Properties p = new Properties(); try { p.load(new FileReader(next)); yamlConverter.addProperties(f, p); } catch (IOException e) { e.printStackTrace(); } } FileWriter fileWriter = new FileWriter( new File(source.getParentFile(), StringUtils.substringBeforeLast(name, ".") + ".yaml")); yamlConverter.writeYaml(fileWriter); fileWriter.close(); } else { Properties p = new Properties(); p.load(new FileReader(source)); FileWriter fileWriter = new FileWriter( new File(source.getParentFile(), StringUtils.substringBeforeLast(name, ".") + ".yaml")); new PropertiesToYamlConverter().addProperties(name, p).writeYaml(fileWriter); fileWriter.close(); } } catch (ParseException e) { e.printStackTrace(); formatter.printHelp("converter", options); } }
From source file:eu.mrbussy.pdfsplitter.Application.java
/** * Start the main program.//from w w w. ja v a 2 s .c om * * @param args * - Arguments passed on to the program */ public static void main(String[] args) { // Read configurations try { String configDirname = FilenameUtils.concat(System.getProperty("user.home"), String.format(".%1$s%2$s", NAME, IOUtils.DIR_SEPARATOR)); String filename = FilenameUtils.concat(configDirname, CONFIGURATION_FILE); // Check to see if the directory exists and the file can be created/opened File configDir = new File(configDirname); if (!configDir.exists()) configDir.mkdir(); // Check to see if the file exists. If not create it File file = new File(filename); if (!file.exists()) { file.createNewFile(); } Configuration = new PropertiesConfiguration(file); // Automatically store the settings that change Configuration.setAutoSave(true); } catch (ConfigurationException | IOException ex) { // Unable to read the file. Probably because it does not exist --> create it. ex.printStackTrace(); } // Set locale to a configured language Locale.setDefault( new Locale(Configuration.getString("language", "nl"), Configuration.getString("country", "NL"))); // Start by parsing the command line ParseCommandline(args); // Display the help if required and leave the app if (arguments.hasOption("h")) { showHelp(); } // Display the app version and leave the app. if (arguments.hasOption("v")) { showVersion(); } // Not command line so start the app GUI if (!arguments.hasOption("c")) { try { // Change the look and feel UIManager.setLookAndFeel( Configuration.getString("LookAndFeel", "com.sun.java.swing.plaf.gtk.GTKLookAndFeel")); javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { (new MainWindow()).setVisible(true); } }); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) { // Something terrible happened so show the help showHelp(); } } }
From source file:eu.mrbussy.pdfsplitter.Splitter.java
/** * Split the given PDF file into multiple files using pages. * /* w w w .j a v a 2 s . c o m*/ * @param filename * - Name of the PDF to split * @param useSubFolder * - Use a separate folder to place the files in. */ public static void Run(File file, boolean useSubFolder) { PdfReader reader = null; String format = null; if (useSubFolder) { format = "%1$s%2$s%4$s"; // Directory format try { FileUtils.forceMkdir( new File(String.format(format, FilenameUtils.getFullPath(file.getAbsolutePath()), FilenameUtils.getBaseName(file.getAbsolutePath()), FilenameUtils.getExtension(file.getAbsolutePath()), IOUtils.DIR_SEPARATOR))); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } format = "%1$s%2$s%4$s%2$s_%%03d.%3$s"; // Directory format + filename } 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.hangum.tadpole.commons.util.ApplicationArgumentUtils.java
/** * .// ww w. jav a 2s.co m * @return */ public static String getResourcesDir() { String strResourceDir = ""; try { strResourceDir = getValue("-resourcesDir"); } catch (Exception e) { strResourceDir = FileUtils.getUserDirectoryPath() + IOUtils.DIR_SEPARATOR + "tadpole"; } return strResourceDir + IOUtils.DIR_SEPARATOR; }
From source file:com.mirth.connect.util.messagewriter.MessageWriterFactory.java
public MessageWriter getMessageWriter(MessageWriterOptions options, Encryptor encryptor) throws MessageWriterException { String baseFolder = StringUtils.defaultString(options.getBaseFolder(), System.getProperty("user.dir")); String rootFolder = FilenameUtils.getAbsolutePath(new File(baseFolder), options.getRootFolder()); String filePattern = options.getFilePattern(); if (filePattern.substring(0, 1).equals(IOUtils.DIR_SEPARATOR)) { filePattern = filePattern.substring(1); }//from w ww.j av a 2 s . co m MessageWriterFile fileWriter = new MessageWriterFile(rootFolder, filePattern, options.getContentType(), options.isDestinationContent(), options.isEncrypt(), encryptor); if (options.getArchiveFormat() == null) { return fileWriter; } if (options.getArchiveFileName() == null) { options.setArchiveFileName( new SimpleDateFormat(ARCHIVE_DATE_PATTERN).format(Calendar.getInstance().getTime())); } /* * If we are writing to an archive, make the vfsWriter write to a temporary folder that will * be removed once the archive file has been created */ String tempFolder = rootFolder + IOUtils.DIR_SEPARATOR + "." + options.getArchiveFileName(); FileUtils.deleteQuietly(new File(tempFolder)); fileWriter.setPath(tempFolder); File archiveFile = new File(rootFolder + IOUtils.DIR_SEPARATOR + options.getArchiveFileName() + "." + getArchiveExtension(options.getArchiveFormat(), options.getCompressFormat())); return new MessageWriterArchive(fileWriter, new File(tempFolder), archiveFile, options.getArchiveFormat(), options.getCompressFormat()); }
From source file:edu.ur.util.FileUtil.java
/** * Create a file in the specified directory with the * specified name and place in it the specified contents. * * @param directory - directory in which to create the file * @param fileName - name of the file to create * @param contents - Simple string to create the file *///from w w w . j av a 2s . c om public File creatFile(File directory, String fileName, String contents) { File f = new File(directory.getAbsolutePath() + IOUtils.DIR_SEPARATOR + fileName); // create the file BufferedOutputStream bos = null; FileOutputStream fos = null; try { f.createNewFile(); fos = new FileOutputStream(f); bos = new BufferedOutputStream(fos); bos.write(contents.getBytes()); bos.flush(); bos.close(); fos.close(); } catch (Exception e) { if (bos != null) { try { bos.close(); } catch (Exception ec) { } } if (fos != null) { try { fos.close(); } catch (Exception ec) { } } throw new RuntimeException(e); } return f; }
From source file:com.mirth.connect.util.messagewriter.MessageWriterArchive.java
/** * Ends message writing and moves the written folders/files into the archive file. */// www . j av a 2 s . com @Override public void finishWrite() throws MessageWriterException { fileWriter.close(); if (messagesWritten) { try { File tempFile = new File( archiveFile.getParent() + IOUtils.DIR_SEPARATOR + "." + archiveFile.getName()); try { FileUtils.forceDelete(tempFile); } catch (FileNotFoundException e) { } ArchiveUtils.createArchive(rootFolder, tempFile, archiver, compressor); try { FileUtils.forceDelete(archiveFile); } catch (FileNotFoundException e) { } FileUtils.moveFile(tempFile, archiveFile); } catch (Exception e) { throw new MessageWriterException(e); } finally { FileUtils.deleteQuietly(rootFolder); } } }
From source file:com.mirth.connect.util.messagewriter.MessageWriterFile.java
@Override public boolean write(Message message) throws MessageWriterException { try {// w w w .j a v a 2 s. c o m String file = path + IOUtils.DIR_SEPARATOR; String content = null; boolean replaced = false; if (contentType == null) { // If we're serializing and encrypting the message, we have to do replacement first if (encrypted) { file += replacer.replaceValues(filePattern, message); replaced = true; } content = toXml(message); } else { content = extractContent(message); } if (StringUtils.isNotBlank(content)) { // Do the replacement here if we haven't already if (!replaced) { file += replacer.replaceValues(filePattern, message); } if (!file.equals(currentFile)) { if (writer != null) { writer.close(); } currentFile = file; File fileObject = new File(file); if (fileObject.isDirectory()) { throw new MessageWriterException( "Cannot save message to file \"" + file + "\", it is a directory"); } writer = new OutputStreamWriter(FileUtils.openOutputStream(fileObject, true)); } writer.write(content); writer.append(IOUtils.LINE_SEPARATOR_WINDOWS); // windows newlines were required previously when commons-vfs was used writer.flush(); return true; } return false; } catch (Exception e) { throw new MessageWriterException(e); } }
From source file:com.wenzani.maven.mongodb.InitMongoDb.java
private void extractTarGz() { try {/*from ww w .java 2s .c om*/ getLog().info("Removing extracted mongodb dir..."); String extractedDir = new StringBuilder(mongoDbDir).append(IOUtils.DIR_SEPARATOR).append(mongoDbVersion) .toString(); File extractedDirFile = new File(extractedDir); if (extractedDirFile.exists()) { FileUtils.deleteDirectory(extractedDirFile); } getLog().info("Extracting fresh instance of mongodb..."); extract(); } catch (IOException e) { getLog().error(ExceptionUtils.getFullStackTrace(e)); } }
From source file:com.wenzani.maven.mongodb.StartMongoDb.java
private String getMongoD() { return new StringBuilder(mongoDbDir).append(IOUtils.DIR_SEPARATOR).append(mongoDbVersion) .append(IOUtils.DIR_SEPARATOR).append("bin").append(IOUtils.DIR_SEPARATOR).append("mongod") .toString();/* w w w . j a v a2s .c o m*/ }