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:com.adaptris.core.common.FileDataOutputParameterTest.java

@Test
public void testInsertDestination() throws Exception {
    FileDataOutputParameter p = new FileDataOutputParameter();
    File f = TempFileUtils.createTrackedFile(testName.getMethodName(), "", p);
    p.setDestination(new ConfiguredProduceDestination("file:///" + f.getCanonicalPath()));
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    p.insert(TEXT, msg);//from  w w w .  jav a2 s . c  o  m
    // It doesn't insert into the msg; so message should still be blank
    assertNotSame(TEXT, msg.getContent());
    assertEquals(TEXT, FileUtils.readFileToString(f));
}

From source file:com.adaptris.core.lms.LargeFsProducer.java

private void tryRename(FileBackedMessage msg, File t) throws Exception {
    log.trace("Rename/Copy {} to {}", msg.currentSource().getCanonicalPath(), t.getCanonicalPath());
    if (useRenameTo()) {
        if (!msg.currentSource().renameTo(t)) {
            copy(msg, t);/*from ww  w  .  j av a  2s  . c  o m*/
        }
    } else {
        copy(msg, t);
    }
}

From source file:name.martingeisse.ecobuild.moduletool.eco32.EosApplicationTool.java

@Override
protected void onModuleOutdated(IModuleToolContext context) throws IOException {

    File moduleSourceFolder = context.getModuleSourceFolder();
    File moduleBuildFolder = context.getModuleBuildFolder();
    AbstractLogger logger = context.getLogger();

    String executableName = getOutputFileName(context);
    String executablePath = moduleBuildFolder.getCanonicalPath() + "/" + executableName;
    String mapFilePath = EcobuildFileUtil.replaceFilenameExtension(executablePath, ".bin", ".map");

    String sourceFiles = StringUtils.join(moduleSourceFolder.list(new SuffixFileFilter(".c")), ' ');
    String command = LccInvocation.getLccCommand(context) + " -A -Wl-m $-Wl" + mapFilePath + "$ -o $"
            + moduleBuildFolder.getCanonicalPath() + "/" + executableName + "$ " + sourceFiles;
    new LccInvocation(context, moduleSourceFolder, command, logger).invoke();

}

From source file:com.adaptris.core.common.FileDataOutputParameterTest.java

@Test
public void testInsertDestination_Exception() throws Exception {
    FileDataOutputParameter p = new FileDataOutputParameter();
    File f = TempFileUtils.createTrackedFile(testName.getMethodName(), "", p);
    p.setDestination(new ConfiguredProduceDestination("file:///" + f.getCanonicalPath()));
    AdaptrisMessage msg = mock(AdaptrisMessage.class);
    doThrow(new RuntimeException()).when(msg).getContentEncoding();
    try {/*from  w  w  w  . j a va  2s .com*/
        p.insert(TEXT, msg);
        fail();
    } catch (CoreException expected) {

    }
}

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

@Test
public void testCompress() throws IOException {

    TarInputStream tin = null;/*from   ww w  .  j  av a2s  . c  om*/

    try {
        String testDir = SAMPLE_DIR + "qclive/compression/tarGz/";
        File file1 = new File(testDir + "file1.txt");
        File file2 = new File(testDir + "file2.txt");
        File file3 = new File(testDir + "file3.txt");
        List<File> files = new ArrayList<File>();
        files.add(file1);
        files.add(file2);
        files.add(file3);
        // pass in a list of files and verify that a tar.gz file is made
        ArchiveCompressor compressor = new ArchiveCompressorTarGzImpl();
        String archiveName = "test";
        File createdFile = compressor.createArchive(files, archiveName, new File(testDir), true);
        File testFile = new File(testDir + File.separator + archiveName + compressor.getExtension());
        assertEquals(testFile.getCanonicalPath(), createdFile.getCanonicalPath());
        assertTrue(testFile.exists());
        // look at tar entries and make sure expected files are there, with just
        // archive name as the path
        GZIPInputStream gzipStream = new GZIPInputStream(new FileInputStream(testFile));
        //noinspection IOResourceOpenedButNotSafelyClosed
        tin = new TarInputStream(gzipStream);
        List<String> tarEntryNames = new ArrayList<String>();
        TarEntry tarEntry;
        while ((tarEntry = tin.getNextEntry()) != null) {
            tarEntryNames.add(tarEntry.getName());
        }
        tin.close();
        gzipStream.close();
        assertTrue(tarEntryNames.contains(archiveName + File.separator + "file1.txt"));
        assertTrue(tarEntryNames.contains(archiveName + File.separator + "file2.txt"));
        assertTrue(tarEntryNames.contains(archiveName + File.separator + "file2.txt"));
        testFile.deleteOnExit();
    } finally {
        IOUtils.closeQuietly(tin);
    }
}

From source file:com.greenpepper.repository.FileSystemRepository.java

private String normalizedPath(File file) throws IOException {
    return file.getCanonicalPath().replaceAll("\\" + File.separator, "/");
}

From source file:gallery.service.rss.RssServiceImpl.java

public void setPath(Resource res) {
    try {//from  w w w .  ja v  a2 s  .  c o m
        File f = res.getFile();
        if (f.exists() && f.isDirectory())
            path = f.getCanonicalPath() + "/";
        else
            throw new NullPointerException("xml path not found for RSS");
    } catch (IOException e) {
        path = null;
        throw new NullPointerException("xml path not found for RSS");
    }
    //System.out.println("----------------------------path = "+this.path);
}

From source file:no.dusken.aranea.web.control.RssCacheController.java

/**
 * Takes a file and tries to parse it to a SyndFeed.
 * If it does so successfully it stores the file.
 * @param feedFile//from w ww  .  j  av a 2s.co m
 * @return Syndfeed
 * @throws FeedException if parsing fails
 * @throws IOException if there is IO error with file.
 */
private SyndFeed getFeed(File feedFile) throws FeedException, IOException {
    SyndFeedInput input = new SyndFeedInput();
    SyndFeed feed = input.build(new XmlReader(feedFile));
    feed.setEncoding("UTF-8");
    //the new feedfile is valid, save it.
    File storeFeedFile = new File(cacheDirectory + "/" + feedFile.getName());
    if (!storeFeedFile.getCanonicalPath().equals(feedFile.getCanonicalPath())) {
        FileUtils.copyFile(feedFile, storeFeedFile);
    }
    return feed;
}

From source file:com.orchestra.portale.controller.ImageBackupRestoreController.java

@RequestMapping(value = "/restoreimg")
public ModelAndView restore(HttpServletRequest request) throws IOException {

    ModelAndView model = new ModelAndView("showResult");
    HttpSession session = request.getSession();
    ServletContext sc = session.getServletContext();
    File root = new File(sc.getRealPath("/"));
    File dir = new File(sc.getRealPath("/") + "dist");
    copy(root.getParentFile().getParentFile().getParentFile().getPath() + File.separator + "BackupImg"
            + File.separator + "poi", dir.getCanonicalPath());
    copy(root.getParentFile().getParentFile().getParentFile().getPath() + File.separator + "BackupImg"
            + File.separator + "page", dir.getCanonicalPath());
    copy(root.getParentFile().getParentFile().getParentFile().getPath() + File.separator + "BackupImg"
            + File.separator + "dpage", dir.getCanonicalPath());
    copy(root.getParentFile().getParentFile().getParentFile().getPath() + File.separator + "BackupImg"
            + File.separator + "user", dir.getCanonicalPath());

    model.addObject("mess", "Tutte le immagini sono state ripristinate");
    return model;
}

From source file:ch.vorburger.exec.ManagedProcessBuilder.java

/**
 * Adds a File as a argument to the command. This uses {@link File#getCanonicalPath()}, which is
 * usually what you'll actually want when launching external processes.
 * //from w  w  w .ja v  a2 s.c o m
 * @param arg the File to add
 * @return this
 * @throws IOException if File getCanonicalPath() fails
 * @see ProcessBuilder
 */
public ManagedProcessBuilder addArgument(File arg) throws IOException {
    addArgument(arg.getCanonicalPath(), true);
    return this;
}