Example usage for java.io File separatorChar

List of usage examples for java.io File separatorChar

Introduction

In this page you can find the example usage for java.io File separatorChar.

Prototype

char separatorChar

To view the source code for java.io File separatorChar.

Click Source Link

Document

The system-dependent default name-separator character.

Usage

From source file:com.linwoodhomes.internal.DefaultTempFile.java

/**
 * Create a new file factory so that the previous instance will be garbage
 * collected and it's temporary files deleted.
 * /*w w w .  j  a v a  2  s  .co m*/
 * Lets try to use the temp cleaning tracker ourselves.
 * @throws InitializationException if the file factory could not init.
 */
private void resetFileFactory() throws InitializationException {
    File xwikiTmpDir = new File(System.getProperty("java.io.tmpdir") + File.separatorChar + "xwiki-tmp");

    log.info("DefaultTempFile: Setting temp file location to: " + xwikiTmpDir);

    try {
        if (xwikiTmpDir.exists() && xwikiTmpDir.isDirectory()) {
            // clean out any existing temporary files.
            FileUtils.cleanDirectory(xwikiTmpDir);
            log.debug("DefaultTempFile: cleaned up temporary directory");
        } else {
            // create the directory
            xwikiTmpDir.mkdir();
        }

        log.info("DefaultTempFile: Files will be created in memory with" + " fileSize LESS than: "
                + DEFAULT_SIZE_THRESHOLD + " bytes. Files >= will be saved to disk.");
        fileFactory = new DiskFileItemFactory(DEFAULT_SIZE_THRESHOLD, xwikiTmpDir);
        fileFactory.setFileCleaningTracker(null); // let us handle the
                                                  // tracking.

    } catch (IOException ioe) {
        log.error("Failed to initialize the temp file factory in directory: " + xwikiTmpDir, ioe);
        throw new InitializationException("Could not initialize temporary File Factory", ioe);
    }
}

From source file:com.opera.core.systems.OperaPaths.java

/**
 * Tries to load the launcher executable from the jar file A copy of the
 * launcher is put into user directory and on each call is compared to the
 * content in jar file//ww w. j av a  2  s . c om
 *
 * @return path to launcher executable
 */
public String getOperaLauncherPath() {
    String launcherName = getLauncherNameForOS();

    String executablePath = null;

    // Get the launcher path
    URL res = OperaDriver.class.getClassLoader().getResource("launcher/" + launcherName);
    if (res != null) {
        String url = res.toExternalForm();
        // If the launcher is inside the jar we will need to copy it out
        if ((url.startsWith("jar:")) || (url.startsWith("wsjar:"))) {
            executablePath = FileUtils.getUserDirectoryPath() + File.separatorChar + ".launcher"
                    + File.separatorChar + launcherName;
            File cur_launcher = new File(executablePath);

            // Whether we need to copy a new launcher across, either because
            // it doesn't currently exist, or because its hash differs from
            // our launcher
            boolean copy = false;
            if (!cur_launcher.exists()) {
                copy = true;
            } else {
                try {
                    // Copy if launchers don't match
                    copy = !Arrays.equals(md5(executablePath), md5(res.openStream()));
                } catch (Exception e) {
                    copy = true;
                }
            }

            if (copy == true) {
                try {
                    if (!cur_launcher.exists())
                        FileUtils.touch(cur_launcher);

                    InputStream is = res.openStream();
                    OutputStream os = new FileOutputStream(cur_launcher);

                    IOUtils.copy(is, os);

                    is.close();
                    os.close();

                    cur_launcher.setLastModified(cur_launcher.lastModified());
                } catch (IOException e) {
                    throw new WebDriverException("Cant write file to disk : " + e.getMessage());
                }
                logger.fine("New launcher copied");
            }
            // If launcher is not inside jar we can run it from it's current
            // location
        } else if (url.startsWith("file:")) {
            File f;
            try {
                f = new File(res.toURI());
            } catch (URISyntaxException e) {
                f = new File(res.getPath());
            }
            executablePath = f.getAbsolutePath();
        }
    }

    if (executablePath != null)
        makeLauncherExecutable(executablePath);

    return executablePath;
}

From source file:net.sourceforge.jencrypt.lib.FolderList.java

/**
 * This method returns the path of a file to encrypt relative to the given
 * folder on the commandline./*from   w  w w .j a v  a2  s .c o m*/
 * 
 * E.g. Folder to encrypt: \tmp\test. File in folder to encrypt:
 * \tmp\test\readme.txt. Relative path: test\readme.txt.
 * 
 * @param fileToEncrypt
 * @return path of fileToEncrypt relative to the commandline argument of the
 *         folder to encrypt.
 */
private String getRelativePathString(File fileToEncrypt) {

    // Remove the parent of top folder from the full path of the current
    // file.
    String relativePath = fileToEncrypt.getAbsolutePath().substring(getArchiveTopFolder().length());

    // If the top folder was e.g. 'C:' then the first separator wasn't
    // removed
    if (relativePath.charAt(0) == File.separatorChar)
        relativePath = relativePath.substring(1);

    return relativePath;
}

From source file:it.biblio.servlets.Inserimento_Ristampa.java

/**
 * metodo per gestire l'upload di file// w  ww.j a v a2  s . co  m
 *
 * @param request
 * @param response
 * @param k
 * @return
 * @throws IOException
 */
private boolean upload(HttpServletRequest request) throws IOException, Exception {

    Map<String, Object> ristampe = new HashMap<String, Object>();
    int idopera = Integer.parseInt(request.getParameter("id"));

    if (ServletFileUpload.isMultipartContent(request)) {

        FileItemFactory fif = new DiskFileItemFactory();
        ServletFileUpload sfo = new ServletFileUpload(fif);
        List<FileItem> items = sfo.parseRequest(request);
        for (FileItem item : items) {
            String fname = item.getFieldName();
            if (item.isFormField() && fname.equals("ISBN") && !item.getString().isEmpty()) {
                ristampe.put("isbn", item.getString());
            } else if (item.isFormField() && fname.equals("numero_pagine") && !item.getString().isEmpty()) {
                ristampe.put("numpagine", Integer.parseInt(item.getString()));
            } else if (item.isFormField() && fname.equals("anno_pub") && !item.getString().isEmpty()) {
                ristampe.put("datapub", item.getString());
            } else if (item.isFormField() && fname.equals("editore") && !item.getString().isEmpty()) {
                ristampe.put("editore", item.getString());
            } else if (item.isFormField() && fname.equals("lingua") && !item.getString().isEmpty()) {
                ristampe.put("lingua", item.getString());
            } else if (item.isFormField() && fname.equals("indice") && !item.getString().isEmpty()) {
                ristampe.put("indice", item.getString());
                //se  stato inserito un pdf salvo il file e inserisco nella mappa i dati
            } else if (!item.isFormField() && fname.equals("PDF")) {
                String name = item.getName();
                long size = item.getSize();
                if (size > 0 && !name.isEmpty()) {
                    File target = new File(getServletContext().getRealPath("") + File.separatorChar + "PDF"
                            + File.separatorChar + name);
                    item.write(target);
                    ristampe.put("download", "PDF" + File.separatorChar + name);
                }
                //salvo l'immagine e inserisco i dati nella mappa
            } else if (!item.isFormField() && fname.equals("copertina")) {
                String name = item.getName();
                long size = item.getSize();
                if (size > 0 && !name.isEmpty()) {
                    File target = new File(getServletContext().getRealPath("") + File.separatorChar
                            + "Copertine" + File.separatorChar + name);
                    item.write(target);
                    ristampe.put("copertina", "Copertine" + File.separatorChar + name);
                }
            }
        }
        ristampe.put("pubblicazioni", idopera);
        return Database.insertRecord("ristampe", ristampe);

    }
    return false;
}

From source file:gda.jython.logger.RedirectableFileLoggerTest.java

@Test
public void testPathChangedUpdate() throws Exception {
    String scratch = TestHelpers.setUpTest(RedirectableFileLoggerTest.class, "testPathChanged", true);
    String logfile1 = concat(scratch, concat("visit1", FILENAME));
    String logfile2 = concat(scratch, concat("visit2", FILENAME));

    // visit 1/*from  w  ww .  j av a 2 s  .co  m*/
    createLogger(logfile1);
    assertEquals("NOSUCHLINE", readLogLine(logfile1, 0));
    logger.log("visit1-abcd1234");
    assertEquals("visit1-abcd1234", readLogLine(logfile1, 0));

    // visit 2
    logger.update(null, new PathChanged(logfile2));
    assertEquals(
            "<<<log moved to: test-scratch/gda/jython/logger/RedirectableFileLoggerTest/testPathChanged/visit2/gdaterminal.log>>>"
                    .replace('/', File.separatorChar),
            readLogLine(logfile1, 1));
    assertEquals(
            "<<<log moved from: test-scratch/gda/jython/logger/RedirectableFileLoggerTest/testPathChanged/visit1/gdaterminal.log>>>"
                    .replace('/', File.separatorChar),
            readLogLine(logfile2, 0));
    logger.log("visit2-abcd1234");
    assertEquals("visit2-abcd1234", readLogLine(logfile2, 1));

    // back to visit 1
    logger.update(null, new PathChanged(logfile1));
    assertEquals(
            "<<<log moved from: test-scratch/gda/jython/logger/RedirectableFileLoggerTest/testPathChanged/visit2/gdaterminal.log>>>"
                    .replace('/', File.separatorChar),
            readLogLine(logfile1, 2));
    assertEquals(
            "<<<log moved to: test-scratch/gda/jython/logger/RedirectableFileLoggerTest/testPathChanged/visit1/gdaterminal.log>>>"
                    .replace('/', File.separatorChar),
            readLogLine(logfile2, 2));
    logger.log("visit1again-abcd1234");
    assertEquals("visit1again-abcd1234", readLogLine(logfile1, 3));
}

From source file:org.messic.server.api.APITagWizard.java

/**
 * Obtain all available tagwizard plugins, only the names without results. Also return the basic wizard info
 * obtained from the uploaded files, at position 0.
 * // w w w.  j  a  v a 2  s  . co m
 * @param mdouser {@link MDOUser} scope
 * @return List<TAGWizardPlugin/> plugins available
 * @throws IOException
 */
public List<org.messic.server.api.datamodel.TAGWizardPlugin> getWizards(User user, String albumCode)
        throws IOException {
    MDOUser mdouser = daoUser.getUserByLogin(user.getLogin());
    List<TAGWizardPlugin> twp = getTAGWizardPlugins();
    ArrayList<org.messic.server.api.datamodel.TAGWizardPlugin> result = new ArrayList<org.messic.server.api.datamodel.TAGWizardPlugin>();
    if (twp != null) {
        for (int i = 0; i < twp.size(); i++) {
            org.messic.server.api.datamodel.TAGWizardPlugin dmtwp = new org.messic.server.api.datamodel.TAGWizardPlugin(
                    twp.get(i).getName(), (Album) null);
            result.add(dmtwp);
        }
    }

    String basePath = mdouser.calculateTmpPath(daoSettings.getSettings(), albumCode);
    File tmpPath = new File(basePath);
    File[] files = tmpPath.listFiles();

    Properties indexProps = new Properties();
    File findex = new File(basePath + File.separatorChar + APIAlbum.INDEX_TMP_PROPERTIES_FILENAME);
    if (findex.exists()) {
        FileInputStream fisIndex = new FileInputStream(findex);
        indexProps.load(fisIndex);
        fisIndex.close();
    }

    org.messic.server.api.datamodel.TAGWizardPlugin basicPlugin = this.tagWizard.getAlbumWizard(user, null,
            files, indexProps);
    result.add(0, basicPlugin);

    return result;
}

From source file:com.silverpeas.mailinglist.service.job.TestMessageChecker.java

@After
public void tearDownTest() {
    Mailbox.clearAll();
    FileFolderManager.deleteFolder(BUILD_PATH + File.separatorChar + "uploads", false);
}

From source file:com.qcadoo.model.internal.file.FileServiceImpl.java

@Override
public String getPathFromUrl(final String url) {
    String denormalizedUrl = denormalizeSeparators(url);
    return uploadDirectory.getAbsolutePath() + File.separator + denormalizedUrl
            .substring(denormalizedUrl.indexOf(File.separatorChar) + L_FILE_URL_PREFIX.length() - 1);
}

From source file:com.photon.phresco.util.ProjectUtils.java

public static ProjectInfo getProjectInfoFile(File directory) throws PhrescoException {
    StringBuilder builder = new StringBuilder();
    builder.append(directory.getPath()).append(File.separatorChar).append(DOT_PHRESCO_FOLDER)
            .append(File.separatorChar).append(PROJECT_INFO_FILE);
    BufferedReader bufferedReader = null;
    try {//from  w w w  .  jav a2s.  c o  m
        File projectInfoFile = new File(builder.toString());
        if (!projectInfoFile.exists()) {
            return null;
        }
        bufferedReader = new BufferedReader(new FileReader(builder.toString()));
        Gson gson = new Gson();
        ProjectInfo projectInfo = gson.fromJson(bufferedReader, ProjectInfo.class);
        //         ApplicationInfo applicationInfo = null;
        //         if (projectInfo != null) {
        //            applicationInfo = projectInfo.getAppInfos().get(0);
        //         }
        return projectInfo;
    } catch (JsonSyntaxException e) {
        throw new PhrescoException(e);
    } catch (JsonIOException e) {
        throw new PhrescoException(e);
    } catch (FileNotFoundException e) {
        throw new PhrescoException(e);
    } finally {
        Utility.closeReader(bufferedReader);
    }
}

From source file:org.rivetlogic.utils.IntegrationUtils.java

public static String encodePath(String alfPath) {

    StringBuilder pathBuilder = new StringBuilder(100);
    StringTokenizer tokenizer = new StringTokenizer(alfPath, Character.toString(File.separatorChar));

    while (tokenizer.hasMoreElements()) {
        String pStr = tokenizer.nextElement().toString();
        if (!pStr.startsWith("/")) {
            for (String prefix : IntegrationConstants.NAMESPACE_PREFIX_RESOLVER.getPrefixes()) {
                if (pStr.startsWith(prefix)) {
                    pStr = pStr.substring(0, prefix.length() + 1)
                            + ISO9075.encode(pStr.substring(prefix.length() + 1));
                }/*w  w w . j  a  v  a2 s .com*/
            }
            pathBuilder.append(File.separatorChar);
            pathBuilder.append(pStr);
        }
    }

    return pathBuilder.toString();
}