Example usage for java.io File toString

List of usage examples for java.io File toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns the pathname string of this abstract pathname.

Usage

From source file:io.apiman.gateway.engine.impl.DefaultPluginRegistry.java

private static File getConfiguredPluginsDir(Map<String, String> configMap) {
    String pluginsDirPath = configMap.get("pluginsDir"); //$NON-NLS-1$
    if (pluginsDirPath != null) {
        File file = new File(pluginsDirPath).getAbsoluteFile();
        if (!file.exists()) {
            file.mkdirs();/* w  w  w . j  a  v a 2s  .c  o  m*/
        } else if (file.isFile()) {
            throw new RuntimeException("Invalid plugins directory: " + file.toString()); //$NON-NLS-1$
        }
        return file;
    } else {
        return createTempPluginsDir();
    }
}

From source file:net.sf.jabref.logic.util.io.FileUtil.java

private static File shortenFileName(File fileName, String directory) {
    if ((fileName == null) || !fileName.isAbsolute() || (directory == null)) {
        return fileName;
    }/*from  w  w w .jav  a2 s.  c o  m*/

    String dir = directory;
    String longName;
    if (OS.WINDOWS) {
        // case-insensitive matching on Windows
        longName = fileName.toString().toLowerCase();
        dir = dir.toLowerCase();
    } else {
        longName = fileName.toString();
    }

    if (!dir.endsWith(FILE_SEPARATOR)) {
        dir = dir.concat(FILE_SEPARATOR);
    }

    if (longName.startsWith(dir)) {
        // result is based on original name, not on lower-cased name
        String newName = fileName.toString().substring(dir.length());
        return new File(newName);
    } else {
        return fileName;
    }
}

From source file:com.photon.phresco.service.docs.impl.DocumentUtil.java

private static void listFiles(File file, StringBuffer sb) {
    if (isDebugEnabled) {
        S_LOGGER.debug("Entering Method DocumentUtil.listFiles(File file,StringBuffer sb)");
    }/*from  w w w  .j  ava 2  s.  c om*/
    String[] list = file.list();
    sb.append("<ul>"); //$NON-NLS-1$
    for (String fileOrFolder : list) {
        File newFile = new File(file.toString() + File.separator + fileOrFolder);
        if (newFile.isHidden())
            continue;
        /*if(newFile.isDirectory()){
        sb.append("<li>"); //$NON-NLS-1$
        sb.append("<a href=./"); //$NON-NLS-1$
        sb.append(newFile.getName());
        sb.append("\">"); //$NON-NLS-1$
        sb.append(newFile.getPath());
        sb.append("</a>"); //$NON-NLS-1$
        sb.append("</li>"); //$NON-NLS-1$
        listFiles(newFile, sb);
        } else {*/
        sb.append("<li>"); //$NON-NLS-1$
        sb.append("<a href=" + "\"" + "./"); //$NON-NLS-1$
        sb.append(newFile.getName());
        sb.append("\">"); //$NON-NLS-1$
        sb.append(newFile.getName());
        sb.append("</a>"); //$NON-NLS-1$
        sb.append("</li>"); //$NON-NLS-1$
        //            }
    }
    sb.append("</ul>"); //$NON-NLS-1$
}

From source file:de.teamgrit.grit.report.TexGenerator.java

/**
 * Writes the source code into the .tex file.
 * //from  ww w .  j  a v  a 2s.  c  o m
 * @param file
 *            File the source code gets written into.
 * @param submission
 *            SubmissionObj the needed information gets taken from.
 * @throws IOException
 *             If something goes wrong when writing.
 */
private static void writeSourceCode(File file, Submission submission) throws IOException {
    FileWriterWithEncoding writer = new FileWriterWithEncoding(file, "UTF-8", true);

    writer.append("\\paragraph{Code}~\\\\\n");

    for (File f : FileUtils.listFiles(submission.getSourceCodeLocation().toFile(),
            FileFilterUtils.fileFileFilter(), TrueFileFilter.INSTANCE)) {

        // determines programming language of the file and adjusts the
        // lstlisting according to it
        String language = "no valid file";
        String fileExtension = FilenameUtils.getExtension(f.toString());

        if (fileExtension.matches("[Jj][Aa][Vv][Aa]")) {
            language = "Java";
        } else if (fileExtension.matches("([Ll])?[Hh][Ss]")) {
            language = "Haskell";
        } else if (fileExtension.matches("[Cc]|[Hh]")) {
            language = "C";
        } else if (fileExtension.matches("[Cc][Pp][Pp]")) {
            language = "C++";
        } else {
            // file is not a valid source file
            continue;
        }

        writer.append("\\lstinputlisting[language=" + language);

        writer.append(", breaklines=true]{" + FilenameUtils.separatorsToUnix((f.getAbsolutePath())) + "}\n");

    }
    writer.close();
}

From source file:com.piketec.jenkins.plugins.tpt.Utils.java

/**
 * Builds a absolute path from the workspace directory and the given path.
 * <ul>/*  w w w.  j av  a  2s  .  co m*/
 * <li>If both are <code>null</code>, the current working directory will returned - hopefully it
 * is inside the workspace.</li>
 * <li>If the workspace is <code>null</code>, the path will returned.</li>
 * <li>If the path is <code>null</code>, the workspace will returned.</li>
 * <li>If the path is absolute, the path will returned.</li>
 * <li>If the path is relative, the path will append to the workspace and returned.</li>
 * </ul>
 * 
 * @param workspaceDir
 *          Current workspace for the build.
 * @param path
 *          Relative or absolute path.
 * @return A absolute path, but it can be a nonexisting file system object or not a directory.
 */
public static File getAbsolutePath(File workspaceDir, File path) {
    File absPath = workspaceDir;
    if (path == null) {
        absPath = (workspaceDir == null) ? new File("") : workspaceDir;
    } else {
        if (path.isAbsolute()) {
            absPath = path;
        } else {
            absPath = (workspaceDir == null) ? path : new File(workspaceDir, path.toString());
        }
    }
    return absPath.isAbsolute() ? absPath : absPath.getAbsoluteFile();
}

From source file:com.photon.phresco.framework.docs.impl.DocumentUtil.java

private static void listFiles(File file, StringBuffer sb) {
    if (isDebugEnabled) {
        S_LOGGER.debug("Entering Method DocumentUtil.listFiles(File file,StringBuffer sb)");
    }//from ww w. ja v  a2 s.c o m
    String[] list = file.list();
    sb.append("<ul>"); //$NON-NLS-1$
    for (String fileOrFolder : list) {
        File newFile = new File(file.toString() + File.separator + fileOrFolder);
        if (newFile.isHidden()) {
            continue;
        }
        /*if(newFile.isDirectory()){
        sb.append("<li>"); //$NON-NLS-1$
        sb.append("<a href=./"); //$NON-NLS-1$
        sb.append(newFile.getName());
        sb.append("\">"); //$NON-NLS-1$
        sb.append(newFile.getPath());
        sb.append("</a>"); //$NON-NLS-1$
        sb.append("</li>"); //$NON-NLS-1$
        listFiles(newFile, sb);
        } else {*/
        sb.append("<li>"); //$NON-NLS-1$
        sb.append("<a href=" + "\"" + "./"); //$NON-NLS-1$
        sb.append(newFile.getName());
        sb.append("\">"); //$NON-NLS-1$
        sb.append(newFile.getName());
        sb.append("</a>"); //$NON-NLS-1$
        sb.append("</li>"); //$NON-NLS-1$
        //            }
    }
    sb.append("</ul>"); //$NON-NLS-1$
}

From source file:fr.ens.biologie.genomique.eoulsan.actions.UploadS3Action.java

/**
 * Run Eoulsan in hadoop mode./*from www .  ja v a  2 s  .  c  om*/
 * @param workflowFile workflow file
 * @param designFile design file
 * @param s3Path path of data on S3 file system
 * @param jobDescription job description
 */
private static void run(final File workflowFile, final File designFile, final DataFile s3Path,
        final String jobDescription) {

    checkNotNull(workflowFile, "paramFile is null");
    checkNotNull(designFile, "designFile is null");
    checkNotNull(s3Path, "s3Path is null");

    getLogger().info("Parameter file: " + workflowFile);
    getLogger().info("Design file: " + designFile);

    try {

        // Test if worklflow file exists
        if (!workflowFile.exists()) {
            throw new FileNotFoundException(workflowFile.toString());
        }

        // Test if design file exists
        if (!designFile.exists()) {
            throw new FileNotFoundException(designFile.toString());
        }

        // Create ExecutionArgument object
        final ExecutorArguments arguments = new ExecutorArguments(workflowFile, designFile);
        arguments.setJobDescription(jobDescription);

        // Create the log Files
        Main.getInstance().createLogFiles(arguments.logPath(Globals.LOG_FILENAME),
                arguments.logPath(Globals.OTHER_LOG_FILENAME));

        // Create the executor
        final Executor e = new Executor(arguments);

        // Launch executor
        e.execute(Lists.newArrayList((Module) new LocalUploadModule(s3Path), new TerminalModule()), null);

    } catch (FileNotFoundException e) {
        Common.errorExit(e, "File not found: " + e.getMessage());
    } catch (Throwable e) {
        Common.errorExit(e, "Error while executing " + Globals.APP_NAME_LOWER_CASE + ": " + e.getMessage());
    }

}

From source file:boa.compiler.BoaCompiler.java

private static void generateJar(final String jarName, final File dir, final List<File> libJars)
        throws IOException, FileNotFoundException {
    final JarOutputStream jar = new JarOutputStream(
            new BufferedOutputStream(new FileOutputStream(new File(jarName))));

    try {// w  w  w.  j  a  v  a  2  s. c o  m
        final int offset = dir.toString().length() + 1;

        for (final File f : findFiles(dir, new ArrayList<File>()))
            putJarEntry(jar, f, f.getPath().substring(offset));

        for (final File f : libJars)
            putJarEntry(jar, f, "lib" + File.separatorChar + f.getName());
    } finally {
        jar.close();
    }
}

From source file:net.metanotion.sqlc.SQLC.java

private static String mkPath(final String outPath, final String[] packageName, final String name) {
    final File f = getFilePath(outPath, packageName);
    f.mkdirs();/*from  w  ww. j  a va2 s.c om*/
    return (f.toString() + File.separator + name + ".java");
}

From source file:com.all4tec.sa.maven.proguard.ProGuardMojo.java

private static String fileToString(File file) {
    return fileNameToString(file.toString());
}