Example usage for org.apache.commons.io IOUtils DIR_SEPARATOR

List of usage examples for org.apache.commons.io IOUtils DIR_SEPARATOR

Introduction

In this page you can find the example usage for org.apache.commons.io IOUtils DIR_SEPARATOR.

Prototype

char DIR_SEPARATOR

To view the source code for org.apache.commons.io IOUtils DIR_SEPARATOR.

Click Source Link

Document

The system directory separator character.

Usage

From source file:edu.ur.file.db.FileSystemManager.java

/**
 * Move a folder to the top level of a file database.
 * /*from  w  w  w. j a  va2  s .c  o  m*/
 * @param current
 * @param destination
 * @return true if the folder is moved.
 */
public static boolean moveFolder(TreeFolderInfo current, DefaultFileDatabase destination) {
    if (log.isDebugEnabled()) {
        log.debug("Moving folder " + current.toString());
        log.debug("To file database " + destination.toString());
    }
    boolean moved = false;
    String beforeMovePath = current.getFullPath();
    String newChildPath = destination.getFullPath() + current.getName() + IOUtils.DIR_SEPARATOR;

    if (renameFile(new File(beforeMovePath), new File(newChildPath))) {
        destination.addExistingFolder(current);
        moved = true;
    } else {
        throw new IllegalStateException("Could not move directory to " + newChildPath);
    }

    if (log.isDebugEnabled()) {
        log.debug("Move Complete");
    }
    return moved;
}

From source file:com.mirth.connect.server.migration.Migrate2_0_0.java

private void migrateServerProperties() throws MigrationException {
    /*//from   w ww . j  a  v  a 2s.c om
     * Since we moved the server properties from a file to the database, we need
     * to copy over the previous properties into the database if a file exists
     */
    File propertiesFile = new File(getBaseDir() + IOUtils.DIR_SEPARATOR + "server.properties");

    if (propertiesFile.exists()) {
        try {
            Properties serverProperties = new Properties();
            serverProperties.load(new FileInputStream(propertiesFile));

            for (Object name : serverProperties.keySet()) {
                updateServerProperty((String) name, serverProperties.getProperty((String) name));
            }

            if (!propertiesFile.delete()) {
                logger.error("Could not delete existing server.properties file. Please delete it manually.");
            }
        } catch (FileNotFoundException e) {
            logger.error("Error loading existing server.properties file.", e);
        } catch (IOException e) {
            logger.error("Error loading existing server.properties file.", e);
        }
    }
}

From source file:com.tc.utils.DxlUtils.java

private static void write(File dir, String fileName, byte[] byteMe) {
    OutputStream out = null;//from  w  w  w . j av  a  2 s.  c  om
    try {
        out = new FileOutputStream(dir.getPath() + IOUtils.DIR_SEPARATOR + fileName);
        IOUtils.write(byteMe, out);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(out);
    }

}

From source file:com.mirth.connect.util.messagewriter.MessageWriterVfs.java

@Override
public boolean write(Message message) throws MessageWriterException {
    try {/*from w w w .j av  a  2 s  .  c  o m*/
        String content = (contentType == null) ? toXml(message) : extractContent(message);

        if (StringUtils.isNotBlank(content)) {
            String file = uri + IOUtils.DIR_SEPARATOR + replacer.replaceValues(filePattern, message, false);

            if (!file.equals(currentFile)) {
                if (writer != null) {
                    writer.close();
                }

                if (currentFileObject != null) {
                    currentFileObject.close();
                }

                currentFile = file;
                currentFileObject = VFS.getManager().resolveFile(file);

                if (currentFileObject.getType() == FileType.FOLDER) {
                    throw new MessageWriterException(
                            "Cannot save message to file \"" + file + "\", it is a directory");
                }

                writer = new OutputStreamWriter(currentFileObject.getContent().getOutputStream(true));
            }

            writer.write(content);
            writer.append(IOUtils.LINE_SEPARATOR_WINDOWS); // the VFS output stream requires windows newlines
            writer.flush();
            return true;
        }

        return false;
    } catch (Exception e) {
        throw new MessageWriterException(e);
    }
}

From source file:com.mirth.connect.util.ArchiveUtils.java

/**
 * Create an archive file from files/sub-folders in a given source folder.
 * /*w  w w  .j a  va2  s  . c o  m*/
 * @param sourceFolder
 *            Sub-folders and files inside this folder will be copied into the archive
 * @param destinationFile
 *            The destination archive file
 * @param archiver
 *            The archiver format, see
 *            org.apache.commons.compress.archivers.ArchiveStreamFactory
 * @param compressor
 *            The compressor format, see
 *            org.apache.commons.compress.compressors.CompressorStreamFactory
 * @throws CompressException
 */
public static void createArchive(File sourceFolder, File destinationFile, String archiver, String compressor)
        throws CompressException {
    if (!sourceFolder.isDirectory() || !sourceFolder.exists()) {
        throw new CompressException("Invalid source folder: " + sourceFolder.getAbsolutePath());
    }

    logger.debug("Creating archive \"" + destinationFile.getAbsolutePath() + "\" from folder \""
            + sourceFolder.getAbsolutePath() + "\"");
    OutputStream outputStream = null;
    ArchiveOutputStream archiveOutputStream = null;

    try {
        /*
         * The commons-compress documentation recommends constructing a ZipArchiveOutputStream
         * with the archive file when using the ZIP archive format. See
         * http://commons.apache.org/proper/commons-compress/zip.html
         */
        if (archiver.equals(ArchiveStreamFactory.ZIP) && compressor == null) {
            archiveOutputStream = new ZipArchiveOutputStream(destinationFile);
        } else {
            // if not using ZIP format, use the archiver/compressor stream factories to initialize the archive output stream
            outputStream = new BufferedOutputStream(new FileOutputStream(destinationFile));

            if (compressor != null) {
                outputStream = new CompressorStreamFactory().createCompressorOutputStream(compressor,
                        outputStream);
            }

            archiveOutputStream = new ArchiveStreamFactory().createArchiveOutputStream(archiver, outputStream);
        }

        createFolderArchive(sourceFolder, archiveOutputStream,
                sourceFolder.getAbsolutePath() + IOUtils.DIR_SEPARATOR);
    } catch (Exception e) {
        throw new CompressException(e);
    } finally {
        IOUtils.closeQuietly(archiveOutputStream);
        IOUtils.closeQuietly(outputStream);
        logger.debug("Finished creating archive \"" + destinationFile.getAbsolutePath() + "\"");
    }
}

From source file:com.wenzani.maven.mongodb.InitMongoDb.java

private String getTarGzFileName() {
    return new StringBuilder(mongoDbDir).append(IOUtils.DIR_SEPARATOR).append("mongo.tar.gz").toString();
}

From source file:com.wenzani.maven.mongodb.InitMongoDb.java

private String getTarFileName() {
    return new StringBuilder(mongoDbDir).append(IOUtils.DIR_SEPARATOR).append("mongo.tar").toString();
}

From source file:edu.ur.file.db.FileSystemManager.java

/**
 * Move a file from one folder to another.  Once the move is
 * complete the old files are deleted./*w  w w.ja v  a2s. c  o  m*/
 * 
 * @param current directory the file is in
 * @param destination directory to move the file to.
 * 
 * @param fileInfo the file information.
 */
public static void moveFile(TreeFolderInfo destination, DefaultFileInfo fileInfo) {
    File fileToMove = new File(fileInfo.getFullPath());
    File destDirectory = new File(destination.getFullPath());
    File newFileDestName = new File(destination.getFullPath() + IOUtils.DIR_SEPARATOR + fileInfo.getName());

    if (!fileToMove.exists()) {
        throw new IllegalStateException("The file " + fileToMove.getAbsolutePath() + " does not exist ");
    }

    if (!destDirectory.exists()) {
        throw new IllegalStateException(
                "The directory " + destDirectory.getAbsolutePath() + " does not exist ");
    }

    //copy the file.
    if (renameFile(fileToMove, newFileDestName)) {
        destination.addFileInfo(fileInfo);
    } else {
        throw new IllegalStateException(
                "Could not move " + fileToMove.getAbsolutePath() + " to " + newFileDestName.getAbsolutePath());
    }
}

From source file:edu.ur.file.db.TreeFolderInfo.java

/**
 * Add an existing folder to this tree. Removes the child from any existing parent.
 * This is compareble to a move.//  w w  w.  ja  v a 2s. com
 * 
 * @param child
 *            to add
 * @return true if the child is added
 */
public boolean addChild(TreeFolderInfo child) {
    boolean added = false;
    if (log.isDebugEnabled()) {
        log.debug("Adding child " + child.toString());
        if ((child.getParent() != null) && child.getParent().equals(this)) {
            log.debug("child already child of this folder");
        }
    }

    if ((child.getParent() != null) && child.getParent().equals(this)) {
        added = true;
    } else {
        // copy the directory to the new location.
        String beforeMovePath = child.getFullPath();
        String newChildPath = this.getFullPath() + child.getName() + IOUtils.DIR_SEPARATOR;

        FileSystemManager.renameFile(new File(beforeMovePath), new File(newChildPath));

        // remove the child from the old parent node.
        if (!child.isRoot()) {
            TreeFolderInfo childParent = child.getParent();
            childParent.removeChild(child);
            childParent.cleanUpTree(child.getTreeSize(), child.getRightValue());
        } else if ((child.getName() != null) && (child.getFullPath() != null)) {
            FileSystemManager.deleteDirectory(child.getFullPath());
        }

        makeRoomInTree(child);

        if (!fileDatabase.equals(child.getFileDatabase())) {
            child.updateFileDatabase(fileDatabase);
        }

        child.setExists(true);
        child.setParent(this);

        children.add(child);
        added = true;
    }
    return added;
}

From source file:edu.cornell.med.icb.io.ResourceFinder.java

private URL findResourceInLocal(final String resource) {
    // Try to find the resource in the searchPaths
    for (final String searchPath : searchPaths) {
        final URL url = fileToURL(searchPath + IOUtils.DIR_SEPARATOR + resource);
        if (url != null) {
            return url;
        }//ww  w.j  a  va2s  . c  om
    }
    return null;
}