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.ir.web.action.repository.EditRepository.java

private void updateInstitutionalCollectionIndexFolder(Repository r, String folder) throws IOException {

    log.debug("update institutional collection index folder " + folder);
    String oldFolder = r.getInstitutionalCollectionIndexFolder();
    boolean change = true;
    if (folder != null) {
        // add the end seperator
        if (folder.charAt(folder.length() - 1) != IOUtils.DIR_SEPARATOR) {
            folder = folder + IOUtils.DIR_SEPARATOR;
        }//from   ww w .j a  v a  2  s .com
        File f = new File(folder);
        if (oldFolder != null) {
            File oldFolderFile = new File(oldFolder);

            if (f.getAbsolutePath().equals(oldFolderFile.getAbsolutePath())) {
                change = false;
            }
        }

        if (change) {
            FileUtils.forceMkdir(f);
            log.debug("setting institutional collection index folder to " + folder);
            r.setInstitutionalCollectionIndexFolder(folder);
            if (oldFolder != null) {
                FileUtils.deleteQuietly(new File(oldFolder));
            }
        }
    } else {
        if (oldFolder != null) {
            FileUtils.deleteQuietly(new File(oldFolder));
        }
    }
}

From source file:edu.ur.ir.web.action.repository.EditRepository.java

private void updateUserGroupIndexFolder(Repository r, String folder) throws IOException {

    log.debug("update user group index folder " + folder);
    String oldFolder = r.getUserGroupIndexFolder();
    boolean change = true;
    if (folder != null) {
        // add the end seperator
        if (folder.charAt(folder.length() - 1) != IOUtils.DIR_SEPARATOR) {
            folder = folder + IOUtils.DIR_SEPARATOR;
        }//  ww w. j  a va2s  .  co  m
        File f = new File(folder);
        if (oldFolder != null) {
            File oldFolderFile = new File(oldFolder);

            if (f.getAbsolutePath().equals(oldFolderFile.getAbsolutePath())) {
                change = false;
            }
        }

        if (change) {
            FileUtils.forceMkdir(f);
            log.debug("setting user group index folder to " + folder);
            r.setUserGroupIndexFolder(folder);
            if (oldFolder != null) {
                FileUtils.deleteQuietly(new File(oldFolder));
            }
        }
    } else {
        if (oldFolder != null) {
            FileUtils.deleteQuietly(new File(oldFolder));
        }
    }
}

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

/**
 * Set the path of the folder. This makes no changes to the children
 * folders. /*from   ww w . jav a2  s.  c  o  m*/
 * 
 * 
 * This converts the paths to the correct path immediately / for unix and \
 * for windows.
 * 
 * @param path
 * @throws IllegalState Exception if the file database is equal to null.
 */
void setPath(String inPath) {

    if (fileDatabase == null) {
        throw new IllegalStateException("File Database cannot be null");
    }
    if (isRoot()) {
        path = null;
    } else {
        inPath = FilenameUtils.separatorsToSystem(inPath.trim());

        // add the end seperator
        if (inPath.charAt(inPath.length() - 1) != IOUtils.DIR_SEPARATOR) {
            inPath = inPath + IOUtils.DIR_SEPARATOR;
        }

        // verify the path is valid if this has any parents.
        if (!verifyPath(inPath)) {
            throw new IllegalArgumentException("inPath is : " + inPath + " but should equal parent path "
                    + " plus parents name which = " + parent.getPath());
        }

        String basePath = fileDatabase.getFullPath();
        path = inPath.substring(basePath.length());
    }
}

From source file:edu.ur.hibernate.file.db.HbTreeFolderInfoDAOTest.java

/**
 * Test TreeFolderInfo persistance with children
 * @throws LocationAlreadyExistsException 
 * /*from   w  ww.ja  va  2  s  . co  m*/
 */
@Test
public void treeFolderChildrenPathDAOTest() throws LocationAlreadyExistsException {

    TransactionStatus ts = tm.getTransaction(td);

    DefaultFileServer fileServer = new DefaultFileServer("fileServer");

    String childrenPath = properties.getProperty("HbFolderDAOTest.children_path");

    DefaultFileDatabase fd = fileServer.createFileDatabase("display_file_db_1", "file_db_1", childrenPath,
            "Description");

    fileServerDAO.makePersistent(fileServer);

    TreeFolderInfo treeFolderInfo1 = fd.createRootFolder("rootFolder1", "root");

    assert treeFolderInfo1.getFullPath()
            .equals(fd.getFullPath() + "root" + IOUtils.DIR_SEPARATOR) : "Path should equal " + fd.getFullPath()
                    + "root" + IOUtils.DIR_SEPARATOR + " but equals " + treeFolderInfo1.getFullPath();

    TreeFolderInfo treeFolderInfo2 = fd.createRootFolder("rootFolder2", "root2");

    assert treeFolderInfo2.getFullPath().equals(
            fd.getFullPath() + "root2" + IOUtils.DIR_SEPARATOR) : "Path should equal " + fd.getFullPath()
                    + "root2" + IOUtils.DIR_SEPARATOR + " but equals " + treeFolderInfo2.getFullPath();

    // add a child
    TreeFolderInfo childTreeFolderInfo1 = treeFolderInfo1.createChild("display3", "childTreeFolderInfo1");

    assert childTreeFolderInfo1.getFullPath()
            .equals(treeFolderInfo1.getFullPath() + "childTreeFolderInfo1"
                    + IOUtils.DIR_SEPARATOR) : "Path should equal " + treeFolderInfo1.getFullPath()
                            + "childTreeFolderInfo1" + IOUtils.DIR_SEPARATOR + " but equals "
                            + childTreeFolderInfo1.getFullPath();

    // add another child
    TreeFolderInfo childTreeFolderInfo2 = treeFolderInfo1.createChild("display4", "childTreeFolderInfo2");

    assert childTreeFolderInfo2.getFullPath()
            .equals(treeFolderInfo1.getFullPath() + "childTreeFolderInfo2"
                    + IOUtils.DIR_SEPARATOR) : "Path should equal " + treeFolderInfo1.getFullPath()
                            + "childTreeFolderInfo2" + IOUtils.DIR_SEPARATOR + " but equals "
                            + childTreeFolderInfo2.getFullPath();

    // add another child
    TreeFolderInfo subTreeFolderInfo1 = childTreeFolderInfo1.createChild("display5", "subTreeFolderInfo1");

    assert subTreeFolderInfo1.getFullPath()
            .equals(childTreeFolderInfo1.getFullPath() + "subTreeFolderInfo1"
                    + IOUtils.DIR_SEPARATOR) : "Path should equal " + childTreeFolderInfo1.getFullPath()
                            + "subTreeFolderInfo1" + IOUtils.DIR_SEPARATOR + " but equals "
                            + subTreeFolderInfo1.getFullPath();

    // add another child
    TreeFolderInfo subTreeFolderInfo2 = childTreeFolderInfo1.createChild("display6", "subTreeFolderInfo2");

    assert subTreeFolderInfo2.getFullPath()
            .equals(childTreeFolderInfo1.getFullPath() + "subTreeFolderInfo2"
                    + IOUtils.DIR_SEPARATOR) : "Path should equal " + childTreeFolderInfo1.getFullPath()
                            + "subTreeFolderInfo2" + IOUtils.DIR_SEPARATOR + " but equals "
                            + subTreeFolderInfo1.getFullPath();

    treeFolderInfo1.setDisplayName("display1");
    treeFolderInfo2.setDisplayName("display2");

    // persist the tree
    treeFolderInfoDAO.makePersistent(treeFolderInfo1);
    treeFolderInfoDAO.makePersistent(treeFolderInfo2);

    tm.commit(ts);

    // start new transaction
    ts = tm.getTransaction(td);

    // reload the data from the database and re-check

    treeFolderInfo1 = treeFolderInfoDAO.getById(treeFolderInfo1.getId(), false);
    fd = treeFolderInfo1.getFileDatabase();

    assert treeFolderInfo1.getFullPath()
            .equals(fd.getFullPath() + "root" + IOUtils.DIR_SEPARATOR) : "Path should equal " + fd.getFullPath()
                    + "root" + IOUtils.DIR_SEPARATOR + " but equals " + treeFolderInfo1.getFullPath();

    // clean up the rest
    fileServerDAO.makeTransient(fileServerDAO.getById(fileServer.getId(), false));

    assert fileServer.deleteDatabase(fd.getName()) : "File Database should be deleted";

    tm.commit(ts);
}

From source file:com.microfocus.application.automation.tools.pc.PcClient.java

public boolean downloadTrendReportAsPdf(String trendReportId, String directory) throws PcException {

    try {//from w  ww.  j  a v  a  2s  .  c  o  m
        logger.println(String.format("%s - %s: %s %s", dateFormatter.getDate(),
                Messages.DownloadingTrendReport(), trendReportId, Messages.InPDFFormat()));
        InputStream in = restProxy.getTrendingPDF(trendReportId);
        File dir = new File(directory);
        if (!dir.exists()) {
            dir.mkdirs();
        }
        String filePath = directory + IOUtils.DIR_SEPARATOR + "trendReport" + trendReportId + ".pdf";
        Path destination = Paths.get(filePath);
        Files.copy(in, destination, StandardCopyOption.REPLACE_EXISTING);
        logger.println(String.format("%s - %s: %s %s", dateFormatter.getDate(), Messages.TrendReport(),
                trendReportId, Messages.SuccessfullyDownloaded()));
    } catch (Exception e) {

        logger.println(String.format("%s - %s: %s", dateFormatter.getDate(),
                Messages.FailedToDownloadTrendReport(), e.getMessage()));
        throw new PcException(e.getMessage());
    }

    return true;

}

From source file:edu.ur.ir.user.service.DefaultUserFileSystemService.java

/**
 * Creates an index folder for a user if one does not exist.  The creates a folder
 * with the given name in the top level repository user index location.
 * //w  ww.ja  v  a2 s .  c  o  m
 * @param user - user 
 * @param repository 
 * @param folderName
 * @throws LocationAlreadyExistsException - if the folder location already exists
 * @throws IOException 
 */
public void createIndexFolder(IrUser user, Repository repository, String folderName)
        throws LocationAlreadyExistsException, IOException {
    if (user.getPersonalIndexFolder() == null || user.getPersonalIndexFolder().equals("")) {
        // get the top level folder structure for user index folders
        String userTopLevelIndexFolder = repository.getUserWorkspaceIndexFolder();
        // make sure end separator exists
        if (userTopLevelIndexFolder.charAt(userTopLevelIndexFolder.length() - 1) != IOUtils.DIR_SEPARATOR) {
            userTopLevelIndexFolder = userTopLevelIndexFolder + IOUtils.DIR_SEPARATOR;
        }

        String userFolder = userTopLevelIndexFolder + folderName + IOUtils.DIR_SEPARATOR;

        File f = new File(userFolder);

        if (f.exists()) {
            throw new LocationAlreadyExistsException("location already exists", userFolder);
        }

        FileUtils.forceMkdir(f);

        user.setPersonalIndexFolder(userFolder);
        irUserDAO.makePersistent(user);
    }
}

From source file:org.jenkinsci.plugins.pipeline.modeldefinition.agent.impl.DockerPipelineFromDockerfile.java

@Nonnull
public String getDockerfilePath() {
    StringBuilder fullPath = new StringBuilder();
    if (!StringUtils.isEmpty(dir)) {
        fullPath.append(dir);//from  www .j  a  v  a  2 s . co  m
        fullPath.append(IOUtils.DIR_SEPARATOR);
    }
    fullPath.append(getDockerfileAsString());
    return fullPath.toString();
}

From source file:org.opencastproject.loadtest.impl.IngestJob.java

/** Waits for the start delay, changes the correct metadata for the mediapackage and ingests it. **/
@Override//w w  w.jav  a 2  s .co  m
public void run() {
    ThreadCounter.add();
    try {
        Thread.sleep(startDelay * LoadTest.MILLISECONDS_IN_SECONDS * LoadTest.SECONDS_IN_MINUTES);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    logger.info("Starting to run " + id);
    String workingDirectory = loadTest.getWorkspaceLocation() + IOUtils.DIR_SEPARATOR + id + "/";
    // Create working directory
    try {
        FileUtils.forceMkdir(new File(workingDirectory));
    } catch (IOException e) {
        logger.error(
                "Had trouble creating working directory at " + workingDirectory + " because " + e.getMessage());
    }
    // Copy source media package
    logger.info("Beginning Copy of " + id);
    String copyCommand = "cp " + loadTest.getSourceMediaPackageLocation() + " " + workingDirectory + id
            + ".zip";
    Execute.launch(copyCommand);
    // Change id in manifest.xml
    updateManifestID(workingDirectory);
    // Change id in episode.xml
    updateEpisodeID(workingDirectory);
    // Update the new manifest.xml and episode.xml to the zip file.
    logger.info("Beginning update of zipfile " + id);
    updateZip(workingDirectory);
    ingestMediaPackageWithJava(workingDirectory, workingDirectory + id + ".zip", loadTest.getWorkflowID());
    logger.info("Finished ingesting " + id);
    ThreadCounter.subtract();
}

From source file:se.trixon.solos.core.panel.NavigatorPanel.java

/**
 * This method is called from within the constructor to initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is always
 * regenerated by the Form Editor./*  www.j a  va 2s  .  com*/
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
    java.awt.GridBagConstraints gridBagConstraints;

    textField = new javax.swing.JTextField();
    toolBar = new javax.swing.JToolBar();
    rootButton = new javax.swing.JButton();
    parentButton = new javax.swing.JButton();
    historyButton = new javax.swing.JButton();
    bookmarksButton = new javax.swing.JButton();
    buttonPanel = new javax.swing.JPanel();

    setLayout(new java.awt.GridBagLayout());

    textField.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            textFieldActionPerformed(evt);
        }
    });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gridBagConstraints.weightx = 1.0;
    add(textField, gridBagConstraints);

    toolBar.setBorder(null);
    toolBar.setFloatable(false);
    toolBar.setBorderPainted(false);

    org.openide.awt.Mnemonics.setLocalizedText(rootButton, String.valueOf(IOUtils.DIR_SEPARATOR));
    rootButton.setToolTipText(Dict.ROOT.getString());
    rootButton.setFocusable(false);
    rootButton.setPreferredSize(new java.awt.Dimension(30, 30));
    rootButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            rootButtonActionPerformed(evt);
        }
    });
    toolBar.add(rootButton);

    org.openide.awt.Mnemonics.setLocalizedText(parentButton, ".."); // NOI18N
    parentButton.setToolTipText(Dict.UP.getString());
    parentButton.setFocusable(false);
    parentButton.setPreferredSize(new java.awt.Dimension(30, 30));
    parentButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            parentButtonActionPerformed(evt);
        }
    });
    toolBar.add(parentButton);

    historyButton.setIcon(Pict.Actions.CHRONOMETER.get(16));
    historyButton.setToolTipText(Dict.HISTORY.getString());
    historyButton.setEnabled(false);
    historyButton.setFocusable(false);
    historyButton.setMaximumSize(new java.awt.Dimension(20, 30));
    historyButton.setMinimumSize(new java.awt.Dimension(20, 30));
    historyButton.setPreferredSize(new java.awt.Dimension(30, 30));
    toolBar.add(historyButton);

    bookmarksButton.setIcon(Pict.Places.BOOKMARKS.get(16));
    bookmarksButton.setToolTipText(Dict.BOOKMARKS.getString());
    bookmarksButton.setEnabled(false);
    bookmarksButton.setFocusable(false);
    bookmarksButton.setMaximumSize(new java.awt.Dimension(20, 30));
    bookmarksButton.setMinimumSize(new java.awt.Dimension(20, 30));
    bookmarksButton.setPreferredSize(new java.awt.Dimension(30, 30));
    toolBar.add(bookmarksButton);

    add(toolBar, new java.awt.GridBagConstraints());

    buttonPanel.setLayout(new java.awt.GridLayout(1, 0));
    add(buttonPanel, new java.awt.GridBagConstraints());
}