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:it.univaq.disim.connectorOTF.utils.SpringAlterationListener.java

@Override
public void onFileCreate(File file) {
    try {// w w w.  jav a2  s .  c o m
        // "file" is the reference to the newly created file
        System.out.println("File created: " + file.getCanonicalPath());
    } catch (IOException e) {
        e.printStackTrace(System.err);
    }
}

From source file:com.adaptris.core.runtime.MessageDigestErrorEntry.java

public void setFileSystemFile(File f) throws IOException {
    if (f != null) {
        fileSystemPath = f.getCanonicalPath();
    }/*from w ww  .  j  av a  2  s .  c o  m*/
}

From source file:cppsensor.utils.UnitTestIOFilter.java

@Override
public boolean accept(File file) {
    if (!file.isFile()) {
        return false;
    }/*from  w ww.  j a va 2 s  .  c o  m*/

    String path = "";
    try {
        path = file.getCanonicalPath();
    } catch (IOException e) {
        log.error("Failed to get canonical path for file " + file, e);
        return false;
    }
    if (path.endsWith(".h")) {
        m_incDirs.add(file.getParent());
        return true;
    } else if (path.endsWith(".cc") || path.endsWith(".c")) {
        return true;
    } else {
        return false;
    }
}

From source file:it.univaq.disim.connectorOTF.utils.SpringAlterationListener.java

@Override
public void onFileChange(File file) {
    try {//from w  w w  .j a v  a  2s . c  o m
        // "file" is the reference to the changed file
        System.out.println("File changed: " + file.getCanonicalPath());
        BufferedReader br = new BufferedReader(new FileReader(file));
        String sCurrentLine, result = "";
        while ((sCurrentLine = br.readLine()) != null) {
            result += sCurrentLine;
        }
        System.out.println(file.getName());
        fileContent.put(file.getName(), result);
    } catch (IOException e) {
        e.printStackTrace(System.err);
    }
}

From source file:cinematicketsim.MovieClassParser.java

public ArrayList<Movie> loadMovies(String filename) {

    ArrayList<Movie> movieList = new ArrayList<Movie>();

    try {//from   w ww .  j ava 2  s  . c  o  m
        File f = new File(filename);
        filename = f.getCanonicalPath();

    } catch (Exception e) {
        e.printStackTrace();
    }

    FileResource file = new FileResource(filename);

    CSVParser parser = file.getCSVParser();

    for (CSVRecord record : parser) {
        String movieId = record.get("id");

        String movieTitle = record.get("title");

        String movieYear = record.get("year");

        String movieCountry = record.get("country");

        String movieGenre = record.get("genre");

        String movieDirector = record.get("director");

        int movieMinutes = Integer.parseInt(record.get("minutes"));

        String moviePoster = record.get("poster");

        Movie movie = new Movie(movieId, movieTitle, movieYear, movieGenre, movieDirector, movieCountry,
                moviePoster, movieMinutes);
        movieList.add(movie);
    }

    for (Movie temp : movieList) {
        String movieId = temp.getID();

        String movieTitle = temp.getTitle();

        idToMovies.put(movieId, movieTitle);
    }

    return movieList;
}

From source file:org.alfresco.bm.file.FileDataServiceTest.java

@BeforeClass
public static void setUp() throws IOException {
    // Create a test file
    File tempDir = new File(System.getProperty("java.io.tmpdir"));
    File testFiles = new File(tempDir, "FileDataServiceTest");
    testFiles.mkdirs();/*from w ww . j a va 2  s  . c  om*/
    File testFile = new File(testFiles, "test.txt");
    if (!testFile.exists()) {
        String text = "SOME TEXT";
        Files.write(text, testFile, Charsets.UTF_8);
    }

    File localDir = new File(System.getProperty("java.io.tmpdir") + "/" + "fileset-123");
    if (localDir.exists()) {
        localDir.delete();
    }

    Properties props = new Properties();
    props.put("test.mongoCollection", COLLECTION_BM_FILE_DATA_SERVICE);
    props.put("test.localDir", localDir.getCanonicalFile());
    props.put("test.ftpHost", "ftp.mirrorservice.org");
    props.put("test.ftpPort", "21");
    props.put("test.ftpUsername", "anonymous");
    props.put("test.ftpPassword", "");
    props.put("test.ftpPath", "/sites/www.linuxfromscratch.org/images");
    props.put("test.testFileDir", testFiles.getCanonicalPath());

    ctx = new ClassPathXmlApplicationContext(new String[] { "test-MongoFileDataTest-context.xml" }, false);
    ctx.getEnvironment().getPropertySources().addFirst(new PropertiesPropertySource("TestProps", props));
    ctx.refresh();
    ctx.start();

    // Get the new beans
    fileDataService = ctx.getBean(FileDataService.class);
    ftpTestFileService = ctx.getBean(FtpTestFileService.class);
    localTestFileService = ctx.getBean(LocalTestFileService.class);

    // Do a directory listing and use that as the dataset
    File randomDir = new File(System.getProperty("user.dir"));
    File[] localFiles = randomDir.listFiles(new FileFilter() {
        @Override
        public boolean accept(File pathname) {
            return !pathname.isDirectory();
        }
    });
    fileDatas = new FileData[localFiles.length];
    for (int i = 0; i < localFiles.length; i++) {
        String remoteName = localFiles[i].getName();
        if (remoteName.length() == 0) {
            continue;
        }
        fileDatas[i] = FileDataServiceTest.createFileData(remoteName);
    }
}

From source file:com.amaze.filemanager.filesystem.compressed.extractcontents.helpers.GzipExtractor.java

private void extractEntry(@NonNull final Context context, TarArchiveInputStream inputStream,
        TarArchiveEntry entry, String outputDir) throws IOException {

    File outputFile = new File(outputDir, fixEntryName(entry.getName()));
    if (!outputFile.getCanonicalPath().startsWith(outputDir)) {
        throw new IOException("Incorrect ZipEntry path!");
    }/*from   w w  w . j  a v a2 s .c  om*/

    if (entry.isDirectory()) {
        FileUtil.mkdir(outputFile, context);
        return;
    }

    if (!outputFile.getParentFile().exists()) {
        FileUtil.mkdir(outputFile.getParentFile(), context);
    }

    BufferedOutputStream outputStream = new BufferedOutputStream(FileUtil.getOutputStream(outputFile, context));
    try {
        int len;
        byte buf[] = new byte[GenericCopyUtil.DEFAULT_BUFFER_SIZE];
        while ((len = inputStream.read(buf)) != -1) {
            if (!listener.isCancelled()) {
                outputStream.write(buf, 0, len);
                ServiceWatcherUtil.position += len;
            } else
                break;
        }
    } finally {
        outputStream.close();
    }
}

From source file:com.amaze.filemanager.filesystem.compressed.extractcontents.helpers.TarExtractor.java

private void extractEntry(@NonNull final Context context, TarArchiveInputStream inputStream,
        TarArchiveEntry entry, String outputDir) throws IOException {
    File outputFile = new File(outputDir, fixEntryName(entry.getName()));

    if (!outputFile.getCanonicalPath().startsWith(outputDir)) {
        throw new IOException("Incorrect TarArchiveEntry path!");
    }/*from   ww  w.j  a  va 2s  .c  o  m*/

    if (entry.isDirectory()) {
        FileUtil.mkdir(outputFile, context);
        return;
    }

    if (!outputFile.getParentFile().exists()) {
        FileUtil.mkdir(outputFile.getParentFile(), context);
    }

    BufferedOutputStream outputStream = new BufferedOutputStream(FileUtil.getOutputStream(outputFile, context));
    try {
        int len;
        byte buf[] = new byte[GenericCopyUtil.DEFAULT_BUFFER_SIZE];
        while ((len = inputStream.read(buf)) != -1) {
            if (!listener.isCancelled()) {
                outputStream.write(buf, 0, len);
                ServiceWatcherUtil.position += len;
            } else
                break;
        }
    } finally {
        outputStream.close();
    }
}

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

@Test
public void testInsert() throws Exception {
    FileDataOutputParameter p = new FileDataOutputParameter();
    File f = TempFileUtils.createTrackedFile(testName.getMethodName(), "", p);
    p.setUrl("file:///" + f.getCanonicalPath());
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    p.insert(TEXT, msg);/* ww w .j  av 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.stevpet.sonar.plugins.dotnet.mscover.registry.SourceFilePathHelper.java

public void setProjectFile(File file) {
    try {//  ww  w  .ja  v  a2  s  . c o m
        String canonicalPath = file.getCanonicalPath();
        setProjectPath(canonicalPath);
    } catch (IOException e) {
        throw new SonarException("could not get canonicalPath for " + file.getName(), e);
    }
}