Example usage for java.io File getCanonicalPath

List of usage examples for java.io File getCanonicalPath

Introduction

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

Prototype

public String getCanonicalPath() throws IOException 

Source Link

Document

Returns the canonical pathname string of this abstract pathname.

Usage

From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.util.FileListReader.java

public List<String> readManifest(final File theFile) throws IOException {
    final String theCanPath = theFile.getCanonicalPath();
    final String fullPath = theCanPath.substring(0, theCanPath.lastIndexOf(SEPARATOR));
    final String name = theCanPath.substring(theCanPath.lastIndexOf(SEPARATOR) + 1, theCanPath.length());
    return readFileWithList(fullPath, name);
}

From source file:javafx1.Testpics.java

private void bildSchleife() {
    File f = new File("F:/NetBeansProjekte/pictures");
    File[] fileArray = f.listFiles();
    java.util.Arrays.sort(fileArray);
    for (File file : fileArray) {
        try {/*from   ww w.ja v  a2s .c o m*/
            System.out.println("file: " + file.getCanonicalPath());
            File outputfile = new File(file.getCanonicalPath() + ".jpg");
            BufferedImage bi = ImageIO.read(file);
            System.out.println(" enc" + encodeToString(bi, "jpg"));
            ImageIO.write(bi, "jpg", outputfile);
            bi = ImageIO.read(outputfile);
            System.out.println(" w" + bi.getWidth() + " h" + bi.getHeight());
            byte[] data = ((DataBufferByte) bi.getRaster().getDataBuffer()).getData();
            // System.out.println(new String(data));
            byte[] x = Base64.encodeBase64URLSafe(data);
            System.out.println("x" + new String(x));
            String b64 = Base64.encodeBase64String(data);
            System.out.println("64" + b64);

            //                byte[] backToBytes = Base64.decodeBase64(base64String);
            //                InputStream in = new ByteArrayInputStream(backToBytes);
            //                BufferedImage bi;
            //                bi = ImageIO.read(in);
            //byte[] xx = base64String.getBytes(StandardCharsets.UTF_8);
            // bild, wie es von http kommt
            //                RunPic rp = new RunPic(this, data);
            //                Platform.runLater(rp);
            try {
                Thread.sleep(50);
                break;
            } catch (InterruptedException ex) {
                Logger.getLogger(JavaFX1.class.getName()).log(Level.SEVERE, null, ex);
            }

        } catch (IOException ex) {
            Logger.getLogger(JavaFX1.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:net.rim.ejde.internal.util.VMUtils.java

/**
 * Creates a new VM based on the attributes specified in the given execution environment description file. The format of the
 * file is defined by <code>http://wiki.eclipse.org/Execution_Environment_Descriptions</code>.
 *
 * @param eeFile//ww w.ja v  a2  s. com
 *            VM definition file
 * @param name
 *            name for the VM, or <code>null</code> if a default name should be assigned
 * @param id
 *            id to assign to the new VM
 *
 * @return VM standin
 *
 * @throws CoreException
 *             the core exception
 *
 * @exception CoreException
 *                if unable to create a VM from the given definition file
 */
public static VMStandin createVMFromDefinitionFile(final File eeFile, String name, final String id)
        throws CoreException {
    if ((null == eeFile) || !eeFile.exists() || !eeFile.isFile()) {
        return null;
    }

    synchronized (eeFile) {
        final ExecutionEnvironmentDescription description = new ExecutionEnvironmentDescription(eeFile);
        final BlackBerryVMInstallType bbType = (BlackBerryVMInstallType) JavaRuntime
                .getVMInstallType(BlackBerryVMInstallType.VM_ID);

        final IStatus defFileValidityStatus = BlackBerryVMInstallType.validateDefinitionFile(description);

        if (defFileValidityStatus.isOK()) {
            final VMStandin standin = new VMStandin(bbType, id);
            String vmName = name;
            if ((name == null) || (name.length() <= 0)) {
                vmName = description.getProperty(ExecutionEnvironmentDescription.EE_NAME);
                if (vmName == null) {
                    vmName = eeFile.getName();
                }
            }
            standin.setName(vmName);

            final String home = description.getProperty(ExecutionEnvironmentDescription.JAVA_HOME);

            final File homeFile = new File(home);
            final IStatus installLocValidityStatus = bbType.validateInstallLocation(homeFile);
            if (!installLocValidityStatus.isOK()) {
                throw new CoreException(installLocValidityStatus);
            }

            standin.setInstallLocation(new File(home));
            standin.setLibraryLocations(description.getLibraryLocations());
            standin.setVMArgs(description.getVMArguments());
            standin.setJavadocLocation(BlackBerryVMInstallType.getJavadocLocation(description.getProperties()));

            standin.setAttribute(BlackBerryVMInstallType.ATTR_EXECUTION_ENVIRONMENT_ID,
                    description.getProperty(ExecutionEnvironmentDescription.CLASS_LIB_LEVEL));

            File exe = description.getExecutable();

            if (exe == null) {
                exe = description.getConsoleExecutable();
            }
            if (exe != null) {
                try {
                    standin.setAttribute(BlackBerryVMInstallType.ATTR_JAVA_EXE, exe.getCanonicalPath());
                } catch (final IOException e) {
                    throw new CoreException(new Status(IStatus.ERROR, ContextManager.PLUGIN_ID,
                            LaunchingMessages.JavaRuntime_24, e));
                }
            }
            standin.setAttribute(BlackBerryVMInstallType.ATTR_JAVA_VERSION,
                    description.getProperty(ExecutionEnvironmentDescription.LANGUAGE_LEVEL));
            standin.setAttribute(BlackBerryVMInstallType.ATTR_DEFINITION_FILE, eeFile.getPath());
            standin.setAttribute(BlackBerryVMInstallType.ATTR_DEBUG_ARGS,
                    description.getProperty(ExecutionEnvironmentDescription.DEBUG_ARGS));
            standin.setAttribute(BlackBerryVMInstallType.ATTR_RAPC_OUTPUT_FOLDER,
                    description.getProperty(BlackBerryVMInstallType.EE_RAPC_OUTPUT_FOLDER));
            standin.setAttribute(BlackBerryVMInstallType.ATTR_CLASSPATH_PROVIDER,
                    RIMClasspathProvider.RIM_CLASSPATH_PROVIDER_ID);
            standin.setAttribute(BlackBerryVMInstallType.ATTR_DESCRIPTION,
                    description.getProperty(BlackBerryVMInstallType.EE_DESCRIPTION));
            standin.setAttribute(BlackBerryVMInstallType.ATTR_INTERNAL,
                    description.getProperty(BlackBerryVMInstallType.EE_INTERNAL));
            standin.setAttribute(BlackBerryVMInstallType.ATTR_DIRECTIVE,
                    description.getProperty(BlackBerryVMInstallType.EE_DIRECTIVE));
            standin.setAttribute(BlackBerryVMInstallType.ATTR_VERSION,
                    description.getProperty(BlackBerryVMInstallType.EE_VERSION));
            return standin;
        }
        _log.error("Failed createVMFromDefinitionFile: " + eeFile.getPath() + "| " + defFileValidityStatus);
        throw new CoreException(defFileValidityStatus);
    }
}

From source file:hudson.Util.java

/**
 * Checks if the given file represents a symlink.
 *///w ww  .j a v a  2s  .  c  o m
//Taken from http://svn.apache.org/viewvc/maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/util/FileSetManager.java?view=markup
public static boolean isSymlink(File file) throws IOException {
    String name = file.getName();
    if (name.equals(".") || name.equals(".."))
        return false;

    File fileInCanonicalParent = null;
    File parentDir = file.getParentFile();
    if (parentDir == null) {
        fileInCanonicalParent = file;
    } else {
        fileInCanonicalParent = new File(parentDir.getCanonicalPath(), name);
    }
    return !fileInCanonicalParent.getCanonicalFile().equals(fileInCanonicalParent.getAbsoluteFile());
}

From source file:com.buaa.cfs.utils.Shell.java

/** Centralized logic to discover and validate the sanity of the Hadoop 
 *  home directory. Returns either NULL or a directory that exists and 
 *  was specified via either -Dhadoop.home.dir or the HADOOP_HOME ENV 
 *  variable.  This does a lot of work so it should only be called 
 *  privately for initialization once per process.
 **///from  w w w . j ava 2 s  .co m
private static String checkHadoopHome() {

    // first check the Dflag hadoop.home.dir with JVM scope
    String home = System.getProperty("hadoop.home.dir");

    // fall back to the system/user-global env variable
    if (home == null) {
        home = System.getenv("HADOOP_HOME");
    }

    try {
        // couldn't find either setting for hadoop's home directory
        if (home == null) {
            throw new IOException("HADOOP_HOME or hadoop.home.dir are not set.");
        }

        if (home.startsWith("\"") && home.endsWith("\"")) {
            home = home.substring(1, home.length() - 1);
        }

        // check that the home setting is actually a directory that exists
        File homedir = new File(home);
        if (!homedir.isAbsolute() || !homedir.exists() || !homedir.isDirectory()) {
            throw new IOException("Hadoop home directory " + homedir
                    + " does not exist, is not a directory, or is not an absolute path.");
        }

        home = homedir.getCanonicalPath();

    } catch (IOException ioe) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Failed to detect a valid hadoop home directory", ioe);
        }
        home = null;
    }

    return home;
}

From source file:com.magnet.tools.tests.MagnetToolStepDefs.java

public static void installMagnetZip(String filePath, String directory, boolean cleanFirst) throws Throwable {
    String file = expandVariables(filePath).trim();
    Assert.assertTrue("installer zip should exist:" + file, new File(file).exists());
    Assert.assertTrue("installer zip should be a file:" + file, new File(file).isFile());
    Assert.assertTrue("installer zip path must be absolute:" + file, new File(file).isAbsolute());
    File dir = new File(expandVariables(directory).trim());
    if (cleanFirst) {
        if (dir.exists()) {
            FileUtils.deleteDirectory(dir);
        }//from w w  w . j a v  a2  s  .  c  om
        if (!dir.mkdirs()) {
            ScenarioUtils.log("Directory already exists: " + dir);
        }
    } else {
        // delete only the installation dir, not the parent
        String[] dirs = { "lib", "bin", "config" };
        for (String d : dirs) {
            File dirFile = new File(dir, d);
            if (dirFile.exists()) {
                FileUtils.deleteDirectory(dirFile);
            }
        }
    }
    ScenarioUtils.unzip(new File(file), dir);
    ScenarioUtils.setEnvironmentVariable(MAGNET_TOOL_HOME, dir.getCanonicalPath());

}

From source file:it.drwolf.ridire.utility.RIDIREPlainTextCleaner.java

public void cleanTextFile(File f) throws IOException {
    File tmpFile = new File(f.getCanonicalPath() + ".tmp");
    FileUtils.writeStringToFile(tmpFile, this.getCleanText(f));
    FileUtils.deleteQuietly(f);/*from w  w w .j a  va 2  s  . c o  m*/
    FileUtils.moveFile(tmpFile, f);
}

From source file:ch.puzzle.modjprof.instrumentation.InstrumentationIT.java

@Test
public void testExecute() throws IOException, InterruptedException {
    File configFile = new File("target/modjprof.properties");
    String agentArguments = "config=" + configFile.getCanonicalPath();
    assertThat(execute(new String[] {}, agentArguments), is(equalTo(0)));

    long threadId = Thread.currentThread().getId();
    File file = new File(getClass().getClassLoader().getResource(EXPECTED_TRC_FILE).getFile());
    List<String> expectedLines = FileUtils.readLines(file);
    List<String> resultLines = FileUtils.readLines(new File(String.format(TRC_FILE, threadId)), UTF_8);

    assertThat(expectedLines.size(), is(equalTo(resultLines.size())));
    for (int i = 0; i < expectedLines.size(); i++) {
        assertThat(removeTimestamp(resultLines.get(i)), is(removeTimestamp(expectedLines.get(i))));
    }/*from   w w w. ja  v  a 2  s  .  c  o  m*/
}

From source file:net.orpiske.ssps.common.groovy.GroovyClasspathWalker.java

@Override
protected void handleDirectoryStart(File directory, int depth, Collection results) throws IOException {
    loader.addClasspath(directory.getCanonicalPath());
}

From source file:info.fetter.logstashforwarder.RegistrarTest.java

@Test
public void testWriteState2() throws JsonGenerationException, JsonMappingException, IOException {
    FileState state1 = new FileState();
    state1.setDirectory("/directory1");
    state1.setFileName("file1");
    state1.setPointer(1234);/*  ww w . ja  v  a 2s .com*/
    state1.setSignature(123456);
    state1.setSignatureLength(135);
    FileState state2 = new FileState();
    state2.setDirectory("/directory2");
    state2.setFileName("file2");
    state2.setPointer(4321);
    state2.setSignature(654321);
    state2.setSignatureLength(531);
    List<FileState> stateList = new ArrayList<FileState>(2);
    stateList.add(state1);
    stateList.add(state2);
    File file = new File("state2.json");
    logger.debug("Writing to file : " + file.getCanonicalPath());
    Registrar.writeStateToJson(file, stateList);
}