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:cascading.ComparePlatformsTest.java

private static void createComparisons(String comparison, File lhsRoot, File rhsRoot, TestSuite suite) {
    LOG.info("comparing directory: {}, with: {}", lhsRoot, rhsRoot);

    LinkedList<File> lhsFiles = new LinkedList<File>(
            FileUtils.listFiles(lhsRoot, new RegexFileFilter("^[\\w-]+"), TrueFileFilter.INSTANCE));
    LinkedList<File> rhsFiles = new LinkedList<File>();

    LOG.info("found lhs files: {}", lhsFiles.size());

    int rootLength = lhsRoot.toString().length() + 1;

    ListIterator<File> iterator = lhsFiles.listIterator();
    while (iterator.hasNext()) {
        File localFile = iterator.next();
        File file = new File(rhsRoot, localFile.toString().substring(rootLength));

        if (localFile.toString().endsWith(NONDETERMINISTIC))
            iterator.remove();/*from  w  ww.ja  v  a  2  s .c o  m*/
        else if (file.exists())
            rhsFiles.add(file);
        else
            iterator.remove();
    }

    LOG.info("running {} comparisons", lhsFiles.size());

    for (int i = 0; i < lhsFiles.size(); i++) {
        File localFile = lhsFiles.get(i);
        File hadoopFile = rhsFiles.get(i);

        suite.addTest(new CompareTestCase(comparison, localFile, hadoopFile));
    }
}

From source file:PathUtils.java

/**
 * Calculates the relative path between a specified root directory and a target path.
 *
 * @param root   The absolute path of the root directory.
 * @param target The path to the target file or directory.
 * @return The relative path between the specified root directory and the target path.
 * @throws IllegalArgumentException <ul><li>The root file cannot be null.</li><li>The target cannot be
 *                                  null.</li><li>The root file must be a directory.</li><li>The root file must be
 *                                  absolute.</li></ul>
 *//*  w w  w .j  av  a 2s  .  co m*/
public static String relativize(final File root, final File target) throws IllegalArgumentException {
    if (root == null)
        throw new IllegalArgumentException("The root file cannot be null.");
    if (target == null)
        throw new IllegalArgumentException("The target cannot be null.");
    if (!root.isDirectory())
        throw new IllegalArgumentException("The root file must be a directory.");
    if (!root.isAbsolute())
        throw new IllegalArgumentException("The root file must be absolute.");
    if (!target.isAbsolute())
        return target.toString();

    if (root.equals(target))
        return ".";

    // Deconstruct hierarchies
    final Deque<File> rootHierarchy = new ArrayDeque<File>();
    for (File f = root; f != null; f = f.getParentFile())
        rootHierarchy.push(f);
    final Deque<File> targetHierarchy = new ArrayDeque<File>();
    for (File f = target; f != null; f = f.getParentFile())
        targetHierarchy.push(f);

    // Trace common root
    while (rootHierarchy.size() > 0 && targetHierarchy.size() > 0
            && rootHierarchy.peek().equals(targetHierarchy.peek())) {
        rootHierarchy.pop();
        targetHierarchy.pop();
    }
    // Create relative path
    final StringBuilder sb = new StringBuilder(rootHierarchy.size() * 3 + targetHierarchy.size() * 32);
    while (rootHierarchy.size() > 0) {
        sb.append("..");
        rootHierarchy.pop();
        if (rootHierarchy.size() > 0 || targetHierarchy.size() > 0)
            sb.append(File.separator);
    }
    while (targetHierarchy.size() > 0) {
        sb.append(targetHierarchy.pop().getName());
        if (targetHierarchy.size() > 0)
            sb.append(File.separator);
    }
    return sb.toString();
}

From source file:msearch.tool.MSLog.java

public static synchronized void setLogfile(String logFileString) {
    logFile = new File(logFileString);
    File dir = new File(logFile.getParent());
    if (!dir.exists()) {
        if (!dir.mkdirs()) {
            logFile = null;/*from w  w w.j av  a  2  s.c  o  m*/
            MSLog.fehlerMeldung(632012165, MSLog.FEHLER_ART_PROG, "Search.logSchreiben",
                    "Kann den Pfad nicht anlegen: " + dir.toString());
        }
    }

}

From source file:com.stratio.crossdata.connector.plugin.installer.InstallerGoalLauncher.java

public static void launchInstallerGoal(InstallerGoalConfig config, Log log) throws IOException {

    log.info("Create TARGET directory.");
    File targetDirectory = new File(
            FilenameUtils.concat(config.getOutputDirectory(), config.getConnectorName()));
    if (targetDirectory.exists()) {
        log.info("Remove previous TARGET directory");
        FileUtils.forceDelete(targetDirectory);
    }/*from  w w w  . j  a  va  2  s  .  c om*/
    File includeConfigDirectory = new File(config.getIncludeDirectory());
    FileUtils.copyDirectory(includeConfigDirectory, targetDirectory);

    log.info("Create LIB directory.");
    File libDirectory = new File(FilenameUtils.concat(targetDirectory.toString(), "lib"));
    FileUtils.copyFileToDirectory(config.getMainJarRepo(), libDirectory);
    for (File jarFile : config.getDependenciesJarRepo()) {
        FileUtils.copyFileToDirectory(jarFile, libDirectory);
    }

    log.info("Create CONF directory.");
    File confDirectory = new File(FilenameUtils.concat(targetDirectory.toString(), "conf"));
    File confConfigDirectory = new File(config.getConfigDirectory());
    FileUtils.copyDirectory(confConfigDirectory, confDirectory);

    log.info("Create BIN Directory");
    File binDirectory = new File(FilenameUtils.concat(targetDirectory.toString(), "bin"));
    FileUtils.forceMkdir(binDirectory);

    log.info("Launch template");
    String outputString = (config.getUnixScriptTemplate());
    outputString = outputString.replaceAll("<name>", config.getConnectorName());
    outputString = outputString.replaceAll("<desc>", config.getDescription());
    String user = config.getUserService();
    if (config.isUseCallingUserAsService()) {
        user = System.getProperty("user.name");
    }
    outputString = outputString.replaceAll("<user>", user);
    outputString = outputString.replaceAll("<mainClass>", config.getMainClass());
    int index = config.getMainClass().lastIndexOf('.');
    String className = config.getMainClass();
    if (index != -1) {
        className = config.getMainClass().substring(index + 1);
    }
    outputString = outputString.replaceAll("<mainClassName>", className);

    outputString = outputString.replaceAll("<jmxPort>", config.getJmxPort());
    String pidFileName = "";
    if (config.getPidFileName() != null) {
        pidFileName = config.getPidFileName();
    }
    outputString = outputString.replaceAll("<pidFileName>", pidFileName);

    File binFile = new File(FilenameUtils.concat(binDirectory.toString(), config.getConnectorName()));
    FileUtils.writeStringToFile(binFile, outputString);
    if (!binFile.setExecutable(true)) {
        throw new IOException("Can't change executable option.");
    }

    log.info("Process complete: " + targetDirectory);
}

From source file:ml.hsv.java

public static fileData[] batchColorFeatureBuilder(String ip, int N, int C_h, int C_s, int C_v, File trainFile,
        File fileInputList, int cellDimension) throws IOException {
    //get array of all files 

    File ipFiles = new File(ip);

    File allImages[] = ipFiles.listFiles();
    int nImages = allImages.length;
    fileData allImageData[] = new fileData[nImages];

    FileWriter op = new FileWriter(trainFile.toString());
    FileWriter op2 = new FileWriter(fileInputList.toString());

    for (int i = 0; i < nImages; i++) {
        //System.out.print("On file number :"+(i+1)+", "+allImages[i].getName() + "\n");

        String fileNameWithOutExt = FilenameUtils.removeExtension(allImages[i].getName());

        op2.write(fileNameWithOutExt + "\n");
        op2.flush();/*from  w w w  .j ava  2 s  .c  o m*/

        //System.out.println(allImages[i].getName());
        if (allImages[i].getName().contains("cat")) //1=dog, 0=cat, -1=unknown
        {
            allImageData[i] = new fileData(0, colorFeatureBuilder(img2RGB2HSV(new File(allImages[i].toURI())),
                    N, C_h, C_s, C_v, cellDimension));
        } else if (allImages[i].getName().contains("dog")) {
            allImageData[i] = new fileData(1, colorFeatureBuilder(img2RGB2HSV(new File(allImages[i].toURI())),
                    N, C_h, C_s, C_v, cellDimension));
        } else if (allImages[i].getName().contains("airplane")) {
            allImageData[i] = new fileData(2, colorFeatureBuilder(img2RGB2HSV(new File(allImages[i].toURI())),
                    N, C_h, C_s, C_v, cellDimension));
        } else if (allImages[i].getName().contains("automobile")) {
            allImageData[i] = new fileData(3, colorFeatureBuilder(img2RGB2HSV(new File(allImages[i].toURI())),
                    N, C_h, C_s, C_v, cellDimension));
        } else if (allImages[i].getName().contains("bird")) {
            allImageData[i] = new fileData(4, colorFeatureBuilder(img2RGB2HSV(new File(allImages[i].toURI())),
                    N, C_h, C_s, C_v, cellDimension));
        } else if (allImages[i].getName().contains("deer")) {
            allImageData[i] = new fileData(5, colorFeatureBuilder(img2RGB2HSV(new File(allImages[i].toURI())),
                    N, C_h, C_s, C_v, cellDimension));
        } else if (allImages[i].getName().contains("frog")) {
            allImageData[i] = new fileData(6, colorFeatureBuilder(img2RGB2HSV(new File(allImages[i].toURI())),
                    N, C_h, C_s, C_v, cellDimension));
        } else if (allImages[i].getName().contains("horse")) {
            allImageData[i] = new fileData(7, colorFeatureBuilder(img2RGB2HSV(new File(allImages[i].toURI())),
                    N, C_h, C_s, C_v, cellDimension));
        } else if (allImages[i].getName().contains("ship")) {
            allImageData[i] = new fileData(8, colorFeatureBuilder(img2RGB2HSV(new File(allImages[i].toURI())),
                    N, C_h, C_s, C_v, cellDimension));
        } else if (allImages[i].getName().contains("truck")) {
            allImageData[i] = new fileData(9, colorFeatureBuilder(img2RGB2HSV(new File(allImages[i].toURI())),
                    N, C_h, C_s, C_v, cellDimension));
        }

        //store intermed. results start here
        StringBuffer ip2 = new StringBuffer();
        ip2.append(allImageData[i].type);
        for (int j = 0; j < allImageData[i].colorFeatureVector.size(); j++) {
            if (allImageData[i].colorFeatureVector.get(j)) {
                ip2.append(" " + (j + 1) + ":1");
            }
        }
        ip2.append("\n");
        op.write(ip2.toString());
        op.flush();
        //end intermed. results
    }

    op.close();
    op2.close();
    return allImageData;
}

From source file:edu.uci.ics.asterix.test.aql.TestsUtils.java

private static void runScriptAndCompareWithResult(File scriptFile, PrintWriter print, File expectedFile,
        File actualFile) throws Exception {
    System.err.println("Expected results file: " + expectedFile.toString());
    BufferedReader readerExpected = new BufferedReader(
            new InputStreamReader(new FileInputStream(expectedFile), "UTF-8"));
    BufferedReader readerActual = new BufferedReader(
            new InputStreamReader(new FileInputStream(actualFile), "UTF-8"));
    String lineExpected, lineActual;
    int num = 1;// w ww  . java  2  s . c  o  m
    try {
        while ((lineExpected = readerExpected.readLine()) != null) {
            lineActual = readerActual.readLine();
            // Assert.assertEquals(lineExpected, lineActual);
            if (lineActual == null) {
                if (lineExpected.isEmpty()) {
                    continue;
                }
                throw new Exception("Result for " + scriptFile + " changed at line " + num + ":\n< "
                        + lineExpected + "\n> ");
            }

            if (!equalStrings(lineExpected.split("Time")[0], lineActual.split("Time")[0])) {
                throw new Exception("Result for " + scriptFile + " changed at line " + num + ":\n< "
                        + lineExpected + "\n> " + lineActual);
            }

            ++num;
        }
        lineActual = readerActual.readLine();
        // Assert.assertEquals(null, lineActual);
        if (lineActual != null) {
            throw new Exception(
                    "Result for " + scriptFile + " changed at line " + num + ":\n< \n> " + lineActual);
        }
        // actualFile.delete();
    } finally {
        readerExpected.close();
        readerActual.close();
    }

}

From source file:com.bedatadriven.renjin.appengine.AppEngineContextFactory.java

@VisibleForTesting
static String findHomeDirectory(File servletContextRoot, String sexpClassPath) throws IOException {

    LOG.fine("Found SEXP in '" + sexpClassPath);

    File jarFile = jarFileFromResource(sexpClassPath);
    StringBuilder homePath = new StringBuilder();
    homePath.append('/').append(jarFile.getName()).append("!/r");

    File parent = jarFile.getParentFile();
    while (!servletContextRoot.equals(parent)) {
        if (parent == null) {
            throw new IllegalStateException(
                    "Expected the renjin-core jar to be in the WEB-INF, bound found it in:\n"
                            + jarFile.toString() + "\nAre you sure you are running in a servlet environment?");
        }//from   ww  w. j  av a  2  s .  c  o m
        homePath.insert(0, parent.getName());
        homePath.insert(0, '/');
        parent = parent.getParentFile();
    }
    homePath.insert(0, "jar:file://");

    return homePath.toString();
}

From source file:jo.alexa.sim.ui.logic.RuntimeLogic.java

public static void saveHistory(RuntimeBean runtime, File source) throws IOException {
    JSONArray transs = ToJSONLogic.toJSONTransactions(runtime.getHistory());
    OutputStream os = new FileOutputStream(source);
    Writer wtr = new OutputStreamWriter(os, "utf-8");
    wtr.write(transs.toJSONString());/*from ww w.j a v  a  2 s. c o  m*/
    wtr.close();
    setProp("app.history", source.toString());
}

From source file:com.symbian.driver.core.processors.EmulatorPreProcessor.java

/**
 * @param lEmulatorHashBackup/*from   w w w .j a  v  a 2s  .co m*/
 * 
 * @deprecated This needs to use the emulator ROM tool
 */
public static void restoreEmulator(HashMap<File, File> lEmulatorHashBackup) {
    if (lEmulatorHashBackup != null) {
        for (File lEmulatorOrginal : lEmulatorHashBackup.keySet()) {
            File lEmulatorBackup = lEmulatorHashBackup.get(lEmulatorOrginal);

            if (lEmulatorBackup != null && !lEmulatorBackup.renameTo(lEmulatorOrginal)) {
                LOGGER.fine("Could not restore Emulator backup of: " + lEmulatorBackup.toString() + " to "
                        + lEmulatorOrginal.toString());
            }
        }
    }
}

From source file:jeplus.RadianceWinTools.java

/**
 * Create working directory and prepare input files for simulation
 * @param workdir The directory to be created
 * @return Preparation successful or not
 *//*from  w  w  w .j  a  v  a  2  s .  c  o  m*/
public static boolean prepareWorkDir(String workdir) {
    boolean success = true;
    // Create the directory
    File dir = new File(workdir);
    if (!dir.exists()) {
        success = dir.mkdirs();
    } else if (!dir.isDirectory()) {
        logger.error(dir.toString() + " is present but not a directory.");
        success = false;
    }
    if (success) {
        File[] files = dir.listFiles();
        for (File file : files) {
            file.delete();
        }
    }
    return success;
}