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:edu.stanford.muse.webapp.GroupsConfig.java

/** writes out all serializable objects in the current session to a file */
public static boolean save(HttpSession session, String title) throws IOException {
    String cacheDir = (String) JSPHelper.getSessionAttribute(session, "cacheDir");
    if (cacheDir == null)
        return false;
    String dir = cacheDir;/*from  ww  w .  ja v a  2s  . co m*/
    String filename = dir + File.separatorChar + title + GROUPING_SUFFIX;
    Archive archive = JSPHelper.getArchive(session);
    GroupAssigner ga = archive.groupAssigner;
    JSPHelper.log.info("Saving grouping to " + filename);
    boolean success = true;
    try {
        Util.writeObjectToFile(filename, ga);
    } catch (Exception e) {
        JSPHelper.log.warn("Warning unable to save groups: " + Util.stackTrace(e));
        success = false;
    }
    return success;
}

From source file:net.lightbody.bmp.proxy.jetty.html.Include.java

/** Constructor. 
 * Include file.//from w  w w.  j a v a2 s  .co  m
 * @param fileName Filename
 * @exception IOException File not found
 */
public Include(String fileName) throws IOException {
    if (File.separatorChar != '/')
        fileName = fileName.replace('/', File.separatorChar);
    if (log.isDebugEnabled())
        log.debug("IncludeTag(" + fileName + ")");
    includeFile(new File(fileName));
}

From source file:com.microsoft.office.core.AbstractPropertyTest.java

private ODataProperty primitive() throws IOException {
    final InputStream input = getClass().getResourceAsStream(getVersion().name().toLowerCase()
            + File.separatorChar + "Customer_-10_CustomerId." + getSuffix(getFormat()));
    final ODataProperty property = getClient().getReader().readProperty(input, getFormat());
    assertNotNull(property);// ww  w  . ja  va2  s .  c o m
    assertTrue(property.hasPrimitiveValue());
    assertTrue(-10 == property.getPrimitiveValue().<Integer>toCastValue());

    ODataProperty comparable;
    final ODataProperty written = getClient().getReader()
            .readProperty(getClient().getWriter().writeProperty(property, getFormat()), getFormat());
    if (getFormat() == ODataFormat.XML) {
        comparable = written;
    } else {
        // This is needed because type information gets lost with JSON serialization
        final ODataPrimitiveValue typedValue = getClient().getPrimitiveValueBuilder()
                .setType(EdmSimpleType.fromValue(property.getPrimitiveValue().getTypeName()))
                .setText(written.getPrimitiveValue().toString()).build();
        comparable = ODataObjectFactory.newPrimitiveProperty(written.getName(), typedValue);
    }

    assertEquals(property, comparable);

    return property;
}

From source file:com.silverpeas.util.ZipManager.java

/**
 * Compress a file into a zip file.//www.j a  v  a 2s. c o  m
 *
 * @param filePath
 * @param zipFilePath
 * @return
 * @throws IOException
 */
public static long compressFile(String filePath, String zipFilePath) throws IOException {
    ZipArchiveOutputStream zos = new ZipArchiveOutputStream(new FileOutputStream(zipFilePath));
    InputStream in = new FileInputStream(filePath);
    try {
        // cration du flux zip
        zos = new ZipArchiveOutputStream(new FileOutputStream(zipFilePath));
        zos.setFallbackToUTF8(true);
        zos.setCreateUnicodeExtraFields(NOT_ENCODEABLE);
        zos.setEncoding(CharEncoding.UTF_8);
        String entryName = FilenameUtils.getName(filePath);
        entryName = entryName.replace(File.separatorChar, '/');
        zos.putArchiveEntry(new ZipArchiveEntry(entryName));
        IOUtils.copy(in, zos);
        zos.closeArchiveEntry();
        return new File(zipFilePath).length();
    } finally {
        IOUtils.closeQuietly(in);
        IOUtils.closeQuietly(zos);
    }
}

From source file:com.dragome.web.helpers.serverside.DragomeCompilerLauncher.java

private static Classpath process(Classpath classPath, DragomeConfigurator configurator) {
    try {// w w w .j  a v a 2  s  . c o m
        String path = null;

        String tempDir = System.getProperty("java.io.tmpdir");
        File tmpDir = new File(tempDir + File.separatorChar + "dragomeTemp");
        Path tmpPath = tmpDir.toPath();
        FileUtils.deleteDirectory(tmpDir);
        Files.createDirectories(tmpPath);
        File file = Files.createTempFile(tmpPath, "dragome-merged-", ".jar").toFile();
        file.deleteOnExit();
        path = file.getAbsolutePath();

        try (JarOutputStream jos = new JarOutputStream(new FileOutputStream(file))) {
            List<ClasspathEntry> entries = classPath.getEntries();
            for (ClasspathEntry classpathEntry : entries)
                classpathEntry.copyFilesToJar(jos, new DefaultClasspathFileFilter() {
                    private ArrayList<String> keepClass = new ArrayList<>();

                    public boolean accept(ClasspathFile classpathFile) {
                        boolean result = super.accept(classpathFile);

                        String entryName = classpathFile.getPath();
                        if (!keepClass.contains(entryName)) {
                            keepClass.add(entryName);

                            if (entryName.endsWith(".js") || entryName.endsWith(".class")
                                    || entryName.contains("MANIFEST") || entryName.contains(".html")
                                    || entryName.contains(".css"))
                                result &= true;
                        }
                        return result;
                    }
                });
        }

        if (configurator.isRemoveUnusedCode()) {
            return runProguard(file, configurator);
        } else
            return new Classpath(JarClasspathEntry.createFromPath(path));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:de.ailis.wlandsuite.PackPic.java

/**
 * @see de.ailis.wlandsuite.cli.PackProg#pack(java.io.File,
 *      java.io.OutputStream)//  w  w  w . j a  va2 s  . co m
 */

@Override
public void pack(File directory, OutputStream output) throws IOException {
    List<PicsAnimationFrameSet> frameSet;
    List<PicsAnimationInstruction> instructions;
    List<Pic> frames;
    Pic baseFrame, frame;
    String line;
    String[] parts;
    int delay;
    int frameSetNo, frameNo;
    BufferedReader reader;
    File file;
    File setDirectory;
    int lineNo;

    // Read the base frame
    baseFrame = new Pic(ImageIO.read(new File(directory.getPath() + File.separatorChar + "000.png")));

    // Read the frame sets
    frameSetNo = 0;
    frameSet = new ArrayList<PicsAnimationFrameSet>();
    while (true) {
        setDirectory = new File(String.format("%s%c%03d",
                new Object[] { directory.getPath(), File.separatorChar, frameSetNo }));
        if (!setDirectory.exists()) {
            break;
        }

        // Read the instructions
        instructions = new ArrayList<PicsAnimationInstruction>();
        file = new File(setDirectory.getPath() + File.separatorChar + "animation.txt");
        if (!file.exists()) {
            log.error("Animation file '" + file.getPath() + "' not found");
        }
        reader = new BufferedReader(new FileReader(file));
        lineNo = 0;
        while ((line = reader.readLine()) != null) {
            lineNo++;
            line = line.split("#")[0].trim();
            if (line.length() == 0)
                continue;
            parts = line.split("[ \\t]+");
            try {
                delay = Integer.parseInt(parts[0]);
                frameNo = Integer.parseInt(parts[1]);
                instructions.add(new PicsAnimationInstruction(delay, frameNo));
            } catch (Exception e) {
                log.error("Syntax error in animation file '" + file.getPath() + "' line " + lineNo);
            }
        }

        // Read the frames
        frameNo = 0;
        frames = new ArrayList<Pic>();
        while (true) {
            file = new File(String.format("%s%c%03d.png",
                    new Object[] { setDirectory.getPath(), File.separatorChar, frameNo + 1 }));
            if (!file.exists()) {
                break;
            }
            frame = new Pic(ImageIO.read(file));
            frames.add(frame);

            frameNo++;
        }
        frameSet.add(new PicsAnimationFrameSet(frames, instructions));
        frameSetNo++;
    }

    new PicsAnimation(baseFrame, frameSet).writeHacked(output);
}

From source file:eu.optimis_project.monitoring.config.ConfigurationManager.java

/**
 * Load configuration file as specified in the system property, and fall
 * back on the default file if required.
 *//* ww w .  ja v a  2  s. c o  m*/
private void loadConfigurationFile(String defaultConfigFilePath, String defaultConfigFileName)
        throws ConfigurationException {
    String configFilePath = System.getProperty("configuration.file.path");
    String configFileName = System.getProperty("configuration.file.name");
    String filePath = configFilePath == null ? defaultConfigFilePath : configFilePath;
    String fileName = configFileName == null ? defaultConfigFileName : configFileName;

    URL configURL;

    if (!filePath.endsWith(File.separator)) {
        filePath += File.separatorChar;
    }

    // Check if the file exists on the system, else try reading it from the
    // classpath
    File configFile = new File(filePath + fileName);
    if (configFile.exists()) {
        try {
            configURL = new URL(filePath + fileName);
        } catch (MalformedURLException e) {
            throw new ConfigurationException(e);
        }
    } else {
        configURL = this.getClass().getClassLoader().getResource(fileName);
    }

    PropertiesConfiguration config = null;
    try {
        config = new PropertiesConfiguration(configURL);
    } catch (ConfigurationException e) {
        if (defaultConfigFileName.equals(configFileName) && configFilePath.equals(defaultConfigFilePath)) {
            log.fatal("Could not find default configuration file: '" + configURL + "'", e);
            throw e;
        } else {
            // Try default file too
            try {
                config = new PropertiesConfiguration(defaultConfigFilePath);
            } catch (ConfigurationException e2) {
                log.warn("Could not find default file, trying same dir");
            }

            // Try file in same dir
            if (config == null) {
                String sameDirPath = System.getProperty("user.dir") + File.separatorChar
                        + defaultConfigFileName;
                try {
                    config = new PropertiesConfiguration(sameDirPath);
                    log.info("Using file in same directory:" + sameDirPath);
                } catch (ConfigurationException e2) {
                    log.fatal("Could not find specified " + "configuration file: '" + configFilePath
                            + File.separatorChar + configFileName + "', could not find default "
                            + "configuration file: '" + defaultConfigFilePath + File.separatorChar
                            + defaultConfigFileName + "', and could not find file in same dir: " + sameDirPath
                            + "'", e2);
                    throw e2;
                }
            }

            log.warn("Could not find specified " + "configuration file: '" + configFilePath + File.separatorChar
                    + configFileName + "', using default configuration at : '" + defaultConfigFilePath
                    + File.separatorChar + defaultConfigFileName + "'");
        }
    }
    config.setThrowExceptionOnMissing(true);
    this.configuration = config;
}

From source file:io.takari.maven.plugins.compile.javac.CompilerJavacLauncher.java

private void compile(File options, File output, final Map<File, Resource<File>> sources) throws IOException {
    new CompilerConfiguration(getSourceEncoding(), getCompilerOptions(), sources.keySet()).write(options);

    // use the same JVM as the one used to run Maven (the "java.home" one)
    String executable = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java";
    if (File.separatorChar == '\\') {
        executable = executable + ".exe";
    }/*from w  ww . java 2 s  . c  o m*/

    CommandLine cli = new CommandLine(executable);

    // jvm options
    cli.addArguments(new String[] { "-cp", jar.getAbsolutePath() });
    if (meminitial != null) {
        cli.addArgument("-Xms" + meminitial);
    }
    if (maxmem != null) {
        cli.addArgument("-Xmx" + maxmem);
    }

    // main class and program arguments
    cli.addArgument(CompilerJavacForked.class.getName());
    cli.addArgument(options.getAbsolutePath(), false);
    cli.addArgument(output.getAbsolutePath(), false);

    DefaultExecutor executor = new DefaultExecutor();
    // ExecuteWatchdog watchdog = null;
    // if (forkedProcessTimeoutInSeconds > 0) {
    // watchdog = new ExecuteWatchdog(forkedProcessTimeoutInSeconds * 1000L);
    // executor.setWatchdog(watchdog);
    // }
    // best effort to avoid orphaned child process
    executor.setProcessDestroyer(new ShutdownHookProcessDestroyer());
    executor.setWorkingDirectory(basedir);

    log.debug("External java process command line:\n   {}", cli);
    try {
        executor.execute(cli); // this throws ExecuteException if process return code != 0
    } catch (ExecuteException e) {
        if (!log.isDebugEnabled()) {
            log.info("External java process command line:\n   {}", cli);
        }
        throw e;
    }

    final Map<File, Output<File>> outputs = new HashMap<File, Output<File>>();

    CompilerOutput.process(output, new CompilerOutputProcessor() {
        @Override
        public void processOutput(File inputFile, File outputFile) {
            outputs.put(outputFile, context.processOutput(outputFile));
        }

        @Override
        public void addMessage(String path, int line, int column, String message, MessageSeverity kind) {
            if (".".equals(path)) {
                context.addPomMessage(message, kind, null);
            } else {
                File file = new File(path);
                Resource<File> resource = sources.get(file);
                if (resource == null) {
                    resource = outputs.get(file);
                }
                if (resource != null) {
                    if (isShowWarnings() || kind != MessageSeverity.WARNING) {
                        resource.addMessage(line, column, message, kind, null);
                    }
                } else {
                    log.warn("Unexpected java resource {}", file);
                }
            }
        }

        @Override
        public void addLogMessage(String message) {
            log.warn(message);
        }
    });
}

From source file:com.dragome.compiler.utils.FileManager.java

private static List<String> findClassesInJar(JarFile jarFile) {
    ArrayList<String> result = new ArrayList<String>();

    final Enumeration<JarEntry> entries = jarFile.entries();
    while (entries.hasMoreElements()) {
        final JarEntry entry = entries.nextElement();
        final String entryName = entry.getName();
        if (entryName.endsWith(".class"))
            result.add(entryName.replace('/', File.separatorChar).replace(".class", ""));
    }//from   ww  w  .  j  a v a 2 s.c  o  m

    return result;
}

From source file:net.sf.wickedshell.ui.shell.viewer.proposal.CompletionController.java

/**
 * Creates the path as <code>File</code> considering the custom root of
 * the given <code>IShellDescriptor</code>, if exists.
 *//* w ww  . j  av a2  s. c  om*/
private static final File getPath(IShellDescriptor descriptor, String pathString) {
    StringBuffer fullPathStringBuffer = new StringBuffer();
    if (descriptor.hasCustomRoot()) {
        fullPathStringBuffer.append(
                DomainPlugin.getDefault().getShellDescriptorProperties(descriptor.getId()).getRootDirectory());
    }
    fullPathStringBuffer.append(pathString.replace(descriptor.getPathSeparator(), File.separatorChar));
    String fullPathString = fullPathStringBuffer.toString();
    // if(fullPathString.startsWith("D:\\Programme\\cygwin\\cygdrive\\d")){
    // int realPathOffset = "D:\\Programme\\cygwin\\cygdrive\\d".length();
    // fullPathString = "D:\\" + fullPathString.substring(realPathOffset);
    // }
    return new File(fullPathString);
}