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:Main.java

/**
 * Add a zip entry into the provided <code>ZipOutputStream</code>. The zip
 * entry is the part of <code>filePathToZip</code> truncated with the
 * <code>baseFolderPath</code>.
 * <p>// w w  w.j  av a2s .co m
 * So a file or folder <code>c:\my\base\folder\my\file\to\zip.txt</code>
 * will be added in archive using <code>my/file/to/zip.txt</code> entry.
 */
public static void addZipEntry(ZipOutputStream zos, File fileToZip, File baseFolder) {
    if (!baseFolder.isDirectory()) {
        throw new IllegalArgumentException(baseFolder.getPath() + " is not a directory.");
    }

    if (fileToZip.isDirectory()) {
        final File[] files = fileToZip.listFiles();
        for (final File file : files) {
            addZipEntry(zos, file, baseFolder);
        }
    } else {
        final String filePathToZip;
        final int start;
        try {
            filePathToZip = fileToZip.getCanonicalPath();
            start = baseFolder.getCanonicalPath().length() + 1;
        } catch (final IOException e1) {
            throw new IllegalStateException(e1);
        }

        final int end = filePathToZip.length();
        String entryName = filePathToZip.substring(start, end);
        entryName = entryName.replace(File.separatorChar, '/');
        final FileInputStream inputStream;
        try {
            inputStream = new FileInputStream(filePathToZip);
        } catch (final FileNotFoundException e) {
            throw new IllegalStateException(e);
        }
        addEntryInputStream(zos, entryName, inputStream);
    }
}

From source file:com.linecorp.armeria.server.http.tomcat.UnmanagedTomcatServiceTest.java

@BeforeClass
public static void createTomcat() throws Exception {
    tomcatWithWebApp = new Tomcat();
    tomcatWithWebApp.setPort(0);/*from w w w  .  ja  v  a 2  s .  co m*/
    tomcatWithWebApp.setBaseDir(
            "build" + File.separatorChar + "tomcat-" + UnmanagedTomcatServiceTest.class.getSimpleName() + "-1");
    tomcatWithWebApp.addWebapp("", new File("build" + File.separatorChar + "classes" + File.separatorChar
            + "test" + File.separatorChar + "tomcat_service").getAbsolutePath());
    tomcatWithWebApp.getService().getContainer().setName("tomcatWithWebApp");

    tomcatWithoutWebApp = new Tomcat();
    tomcatWithoutWebApp.setPort(0);
    tomcatWithoutWebApp.setBaseDir(
            "build" + File.separatorChar + "tomcat-" + UnmanagedTomcatServiceTest.class.getSimpleName() + "-2");
}

From source file:ZipHelper.java

private static void fileToZip(File file, ZipOutputStream zout, File baseDir) throws Exception {
    String entryName = file.getPath().substring(baseDir.getPath().length() + 1);
    if (File.separatorChar != '/')
        entryName = entryName.replace(File.separator, "/");
    if (file.isDirectory()) {
        zout.putNextEntry(new ZipEntry(entryName + "/"));
        zout.closeEntry();/*  w ww . j  a v  a  2s .co m*/
        File[] files = file.listFiles();
        for (int i = 0; i < files.length; i++)
            fileToZip(files[i], zout, baseDir);
    } else {
        FileInputStream is = null;
        try {
            is = new FileInputStream(file);
            zout.putNextEntry(new ZipEntry(entryName));
            streamCopy(is, zout);
        } finally {
            zout.closeEntry();
            if (is != null)
                is.close();
        }
    }
}

From source file:edu.stanford.muse.util.Log4JUtils.java

public static synchronized void initialize() {
    // NOTE: do not use logger calls inside this method, as logging is still being set up
    if (initialized)
        return;/*  w w w  .  j  av  a  2 s.c  o m*/

    // LOG FILE will be set only once, either to <home>/.muse/muse.log (default) or overwritten with the help of muse.dirname and muse.log system props, typically to <home>/ePADD/epadd.log
    LOG_FILE = System.getProperty("user.home") + File.separatorChar + ".muse" + File.separatorChar + "muse.log";
    String newLogFile = System.getProperty("muse.log"); // for epadd this will be epadd.log, set in EpaddInitializer
    if (!Util.nullOrEmpty(newLogFile))
        LOG_FILE = newLogFile;

    File parent = new File(LOG_FILE).getParentFile();

    // check the parent directory of the log file first...
    // if the directory does not exist, create it
    if (!parent.exists()) {
        System.out.println("Creating " + parent);
        boolean result = parent.mkdirs();
        if (!result) {
            System.out.println("Sorry, unable to create: " + parent.getAbsolutePath());
            return;
        }
    } else if (!parent.isDirectory()) {
        System.out.println("Sorry, this needs to be a folder, not a file: " + parent.getAbsolutePath());
        return;
    } else if (!parent.canWrite()) {
        System.out.println("Sorry, this folder is not writable: " + parent.getAbsolutePath());
        return;
    }

    // now rename, truncate or create the actual log file
    try {
        /*
        try {
           File f = new File(LOG_FILE);
           if (f.exists())
           {
              // save the previous log file if it exists (shouldn't the rolling file appender take care of this??)
              RandomAccessFile raf = new RandomAccessFile(f, "rwd");
              raf.setLength(0);
              raf.close();
           }
        } catch (Exception e) { Util.print_exception(e);}
        */
        addLogFileAppender(LOG_FILE);

        // write a line so we can distinguish a new run in the log file
        String message = "________________________________________________________________________________________________ ";
        System.out.println(message);
        log.info(message);

        message = "Log messages will be recorded in " + LOG_FILE;
        System.out.println(message);
        log.info(message);
    } catch (Exception e) {
        Util.print_exception(e);
    }
    initialized = true;
}

From source file:com.thoughtworks.go.util.TestUtils.java

public static Matcher<? super String> isSameAsPath(final String expected) {
    final String expectedPath = expected.replace('/', File.separatorChar);

    return new TypeSafeMatcher<String>() {
        @Override//w  ww  .  j a va  2s  .  com
        protected boolean matchesSafely(String actual) {
            return expectedPath.equals(actual);
        }

        @Override
        public void describeTo(Description description) {
            description.appendText(expectedPath);
        }
    };
}

From source file:gov.nih.nci.cagrid.introduce.servicetools.FilePersistenceHelper.java

public static File getDefaultStorageDirectory(File baseDir, Class beanClass) throws IOException {
    if (beanClass == null) {
        return null;
    }//  w  w  w. ja  v  a2s . co  m
    String fullClassName = beanClass.getName();
    String className = fullClassName;
    int pos = className.lastIndexOf('.');
    if (pos != -1) {
        className = className.substring(pos + 1);
    }

    String dir = baseDir.getAbsolutePath() + File.separatorChar + className;

    File storageDir = new File(dir);
    if (!storageDir.getCanonicalPath().startsWith(baseDir.getCanonicalPath())) {
        throw new IOException("invalidStorageDir: " + dir);
    }

    return storageDir;
}

From source file:brut.util.OS.java

public static void cpdir(File src, File dest) throws BrutException {
    dest.mkdirs();/* w  ww .  jav  a2s.c om*/
    File[] files = src.listFiles();
    for (int i = 0; i < files.length; i++) {
        File file = files[i];
        File destFile = new File(dest.getPath() + File.separatorChar + file.getName());
        if (file.isDirectory()) {
            cpdir(file, destFile);
            continue;
        }
        try {
            InputStream in = new FileInputStream(file);
            OutputStream out = new FileOutputStream(destFile);
            IOUtils.copy(in, out);
            in.close();
            out.close();
        } catch (IOException ex) {
            throw new BrutException("Could not copy file: " + file, ex);
        }
    }
}

From source file:Main.java

public static File getSignatureDirectoryForFile(File originalFile) {
    return new File(originalFile.getParent() + File.separatorChar + MARTUS_SIGNATURE_FILE_DIRECTORY_NAME);
}

From source file:com.springsource.hq.plugin.tcserver.plugin.Utils.java

/**
 * Returns <code>true</code> when running on Windows, otherwise <code>false</code>.
 * /*w w  w.  j  a va 2  s .  co  m*/
 * @return <code>true</code> if running on Windows, otherwise <code>false</code>.
 */
public static boolean isWindows() {
    return File.separatorChar == '\\';
}

From source file:JarMaker.java

public static boolean pack(String jarPath, String jarFileName) {

    try {//from w  ww  . j a  va2s  .com
        String t_jarPathName = jarPath.replace('\\', File.separatorChar);
        String t_jarFileName = jarFileName.replace('\\', File.separatorChar);
        RealPackUtilityJar(t_jarPathName, t_jarFileName);
        return true;
    } catch (Exception ex) {
        return false;
    }
}