Example usage for java.io File getAbsoluteFile

List of usage examples for java.io File getAbsoluteFile

Introduction

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

Prototype

public File getAbsoluteFile() 

Source Link

Document

Returns the absolute form of this abstract pathname.

Usage

From source file:function.GettingPhotos.java

public void writeIntoDocument(List<Photo> listPhoto) {

    try {//from w  w w.  j  a  v a2  s.c  o m
        File myFile = new File("photos.txt");
        for (Photo photo : listPhoto) {
            if (myFile.exists()) {
                FileWriter fw = new FileWriter(myFile.getAbsoluteFile(), true);
                BufferedWriter bw = new BufferedWriter(fw);
                bw.write(photo.getId() + " ");
                bw.write(photo.getUserId() + " ");
                bw.write(photo.getSecret() + " ");
                bw.write(photo.getServer() + " ");
                bw.write(photo.getTitle() + " ");
                bw.write(photo.getLocation() + " ");
                bw.write("\n");
                bw.close();
                System.out.println("Success!");
            } else {
                FileWriter fw = new FileWriter(myFile.getAbsoluteFile(), true);
                BufferedWriter bw = new BufferedWriter(fw);
                bw.write(photo.getId() + " ");
                bw.write(photo.getUserId() + " ");
                bw.write(photo.getSecret() + " ");
                bw.write(photo.getServer() + " ");
                bw.write(photo.getTitle() + " ");
                bw.write(photo.getLocation() + " ");
                bw.write("\n");
                bw.close();
                System.out.println("Written for the first time!");
            }
        }

    } catch (IOException ioe) {
        ioe.printStackTrace();
    }

}

From source file:Ch12FileBrowserComposite.java

String[] getSelectedFiles() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    List fileNameList = new LinkedList();
    Iterator iterator = selection.iterator();
    while (iterator.hasNext()) {
        File file = (File) iterator.next();
        fileNameList.add(file.getAbsoluteFile().toString());
    }//from  ww  w .  j  a v a  2s . c o m
    return (String[]) fileNameList.toArray(new String[fileNameList.size()]);
}

From source file:com.izforge.izpack.installer.unpacker.AbstractFileUnpackerTest.java

/**
 * Verifies that a blockable file is queued rather than copied to the target directory.
 *
 * @param blockable the blockable type/* w  w  w.j a  v a 2  s  .com*/
 * @throws IOException        for any I/O error
 * @throws InstallerException for any installer error
 */
private void checkQueue(Blockable blockable) throws IOException, InstallerException {
    File baseDir = temporaryFolder.getRoot();
    File sourceDir = baseDir.getAbsoluteFile();

    File source = createSourceFile(baseDir);
    File target = getTargetFile(baseDir);

    FileQueue queue = new FileQueueFactory(Platforms.WINDOWS, librarian).create();
    PackFile file = createPackFile(baseDir, source, target, blockable);

    FileUnpacker unpacker = createUnpacker(sourceDir, queue);
    unpacker.unpack(file, createPackStream(source), target);
    assertNotNull(queue);
    assertEquals(1, queue.getOperations().size());
    assertFalse(target.exists());
}

From source file:com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptorBuilder.java

public GoPluginDescriptor build(File pluginJarFile, boolean isBundledPlugin) {
    if (!pluginJarFile.exists()) {
        throw new RuntimeException(
                String.format("Plugin jar does not exist: %s", pluginJarFile.getAbsoluteFile()));
    }//from   w  w w  .  j a  va 2  s .  c o m
    InputStream pluginXMLStream = null;
    JarFile jarFile = null;
    try {
        jarFile = new JarFile(pluginJarFile);
        ZipEntry entry = jarFile.getEntry(PLUGIN_XML);

        if (entry == null) {
            return GoPluginDescriptor.usingId(pluginJarFile.getName(), pluginJarFile.getAbsolutePath(),
                    getBundleLocation(bundlePathLocation, pluginJarFile.getName()), isBundledPlugin);
        }

        pluginXMLStream = jarFile.getInputStream(entry);
        return GoPluginDescriptorParser.parseXML(pluginXMLStream, pluginJarFile.getAbsolutePath(),
                getBundleLocation(bundlePathLocation, pluginJarFile.getName()), isBundledPlugin);
    } catch (Exception e) {
        LOGGER.warn("Could not load plugin with jar filename:" + pluginJarFile.getName(), e);
        String cause = e.getCause() != null
                ? String.format("%s. Cause: %s", e.getMessage(), e.getCause().getMessage())
                : e.getMessage();
        return GoPluginDescriptor
                .usingId(pluginJarFile.getName(), pluginJarFile.getAbsolutePath(),
                        getBundleLocation(bundlePathLocation, pluginJarFile.getName()), isBundledPlugin)
                .markAsInvalid(Arrays.asList(
                        String.format("Plugin with ID (%s) is not valid: %s", pluginJarFile.getName(), cause)),
                        e);
    } finally {
        IOUtils.closeQuietly(pluginXMLStream);
        closeQuietly(jarFile);
    }
}

From source file:com.fatwire.dta.sscrawler.reporting.reporters.PageCollectingReporter.java

public void addToReport(final ResultPage page) {
    if (page.getResponseCode() != 200) {
        return; // bail out
    }//from w w w.j a v a  2  s.  co m
    final long id = idGen.incrementAndGet();
    FileWriter writer = null;

    try {
        final String p = (page.getPageName() != null ? page.getPageName() : "") + "-" + id + ".txt";
        final File pFile = new File(dir, p);
        pwriter.println(page.getUri() + "\t" + path + File.separator + p.replace('/', File.separatorChar));
        pwriter.flush();
        pFile.getAbsoluteFile().getParentFile().mkdirs();
        writer = new FileWriter(pFile);
        writer.write(page.getUri().toString());
        writer.write(PageCollectingReporter.CRLF);
        writer.write(PageCollectingReporter.CRLF);
        final Header[] headers = page.getResponseHeaders();
        for (final Header header : headers) {
            writer.write(header.toExternalForm());
        }
        writer.write(PageCollectingReporter.CRLF);
        writer.write(page.getBody());
    } catch (final IOException e) {
        log.error(e, e);
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (final IOException ignored) {
                // ignored
            }
        }
    }

}

From source file:com.izforge.izpack.installer.unpacker.AbstractFileUnpackerTest.java

/**
 * Tests unpacking a loose file./*from   ww w.  j  a v  a 2 s  .  c om*/
 *
 * @throws Exception throws exception for any error
 */
@Test
public void testUnpack() throws Exception {
    File baseDir = temporaryFolder.getRoot();
    File sourceDir = baseDir.getAbsoluteFile();

    File source = createSourceFile(baseDir);
    File target = getTargetFile(baseDir);

    FileQueue queue = new FileQueueFactory(Platforms.WINDOWS, librarian).create();

    PackFile file = createPackFile(baseDir, source, target, Blockable.BLOCKABLE_NONE);
    assertFalse(target.exists());

    FileUnpacker unpacker = createUnpacker(sourceDir, queue);
    InputStream packStream = createPackStream(source);

    unpacker.unpack(file, packStream, target);
    assertTrue(queue.isEmpty());

    checkTarget(source, target);
}

From source file:com.cloudera.recordservice.tests.ClusterController.java

/**
 * This method populates a JobConf with the information in the HadoopConfDir
 *///w ww.ja v a  2s . com
public JobConf populateJobConf(JobConf conf) throws MalformedURLException {
    File[] files = new File(clusterConfiguration_.getHadoopConfDir()).listFiles();
    for (File file : files) {
        if (file.getName().endsWith(".xml")) {
            conf.addResource(file.getAbsoluteFile().toURI().toURL());
        }
    }
    String[] bs = clusterConfiguration_.getHadoopConfDir().split("/");
    String newPath = "/";
    for (int i = 0; i < bs.length - 1; i++) {
        newPath += bs[i] + "/";
    }
    newPath += "recordservice-conf/recordservice-site.xml";
    conf.addResource(new File(newPath).getAbsoluteFile().toURI().toURL());
    return conf;
}

From source file:de.ingrid.interfaces.csw.config.ConfigurationProvider.java

/**
 * Set the configuration file.//from w  w  w  .  j  a v  a2 s.  c o m
 * 
 * @param configurationFile
 */
public void setConfigurationFile(File configurationFile) {
    this.configurationFile = configurationFile.getAbsoluteFile();
}

From source file:de.doering.dwca.arkive.ChecklistBuilder.java

public File build() throws IOException {
    // new writer
    File dwcaDir = FileUtils.createTempDir("arkive-", "");
    File dwcaZip = new File(dwcaDir.getAbsoluteFile() + ".zip");
    log.info("Writing archive files to temporary folder " + dwcaDir);
    writer = new DwcaWriter(DwcTerm.Taxon, dwcaDir);

    // metadata/*from   w  w  w .  jav  a2  s.  c o m*/
    Eml eml = new Eml();
    eml.setTitle(TITLE);
    eml.setDescription(DESCRIPTION);
    eml.setLanguage(LANGUAGE);
    eml.setHomepageUrl(HOMEPAGE);
    eml.setLogoUrl(LOGO);
    org.gbif.metadata.eml.Agent contact = new org.gbif.metadata.eml.Agent();
    contact.setOrganisation(CONTACT_ORG);
    contact.setEmail(CONTACT_EMAIL);
    eml.setContact(contact);

    // parse file and some metadata
    parseData();

    // finish archive and zip it
    log.info("Bundling archive at {}", dwcaZip);
    writer.setEml(eml);
    writer.close();

    // compress
    CompressionUtil.zipDir(dwcaDir, dwcaZip);
    // remove temp folder
    //org.apache.commons.io.FileUtils.deleteDirectory(dwcaDir);

    log.info("Dwc archive completed at {} !", dwcaZip);

    return dwcaZip;
}

From source file:eu.edisonproject.classification.tfidf.mapreduce.TFIDFDriverImpl.java

/**
 *
 * @param inputPath/*  w  w  w.j av  a2 s.c  o  m*/
 */
public void executeTFIDF(String inputPath) {
    try {
        File items = new File(INPUT_ITEMSET);
        if (!items.exists()) {
            throw new IOException(items.getAbsoluteFile() + " not found");
        }

        String OUTPUT_PATH1 = System.currentTimeMillis() + "_" + UUID.randomUUID()
                + "-TFIDFDriverImpl-1-word-freq";

        if (items.length() < 200000000) {
            String AVRO_FILE = System.currentTimeMillis() + "_" + UUID.randomUUID() + "-TFIDFDriverImpl-avro";
            Logger.getLogger(TFIDFDriverImpl.class.getName()).log(Level.INFO, "Starting text2Avro");
            text2Avro(inputPath, AVRO_FILE);

            Logger.getLogger(TFIDFDriverImpl.class.getName()).log(Level.INFO,
                    "Starting WordFrequencyInDocDriver: {0},{1},{2},{3},{4}",
                    new Object[] { AVRO_FILE, OUTPUT_PATH1, INPUT_ITEMSET, NUM_OF_LINES, STOPWORDS_PATH });
            String[] args1 = { AVRO_FILE, OUTPUT_PATH1, INPUT_ITEMSET, STOPWORDS_PATH };
            ToolRunner.run(new WordFrequencyInDocDriver(), args1);
        } else {
            Logger.getLogger(TFIDFDriverImpl.class.getName()).log(Level.INFO, "Starting TermWordFrequency");
            String[] args1 = { INPUT_ITEMSET, OUTPUT_PATH1, inputPath, STOPWORDS_PATH, NUM_OF_LINES };
            ToolRunner.run(new TermWordFrequency(), args1);
        }
        String OUTPUT_PATH2 = System.currentTimeMillis() + "_" + UUID.randomUUID()
                + "-TFIDFDriverImpl-2-word-counts";
        ;
        String[] args2 = { OUTPUT_PATH1, OUTPUT_PATH2 };
        ToolRunner.run(new WordCountsForDocsDriver(), args2);

        File docs = new File(inputPath);
        File[] files = docs.listFiles(new FilenameFilter() {
            @Override
            public boolean accept(File dir, String name) {
                return name.toLowerCase().endsWith(".txt");
            }
        });
        Logger.getLogger(TFIDFDriverImpl.class.getName()).log(Level.INFO, "docs:{0}", docs.getAbsolutePath());
        int numberOfDocuments = files.length;
        String OUTPUT_PATH3 = System.currentTimeMillis() + "_" + UUID.randomUUID()
                + "-TFIDFDriverImpl-3-tf-idf";
        String[] args3 = { OUTPUT_PATH2, OUTPUT_PATH3, String.valueOf(numberOfDocuments) };
        ToolRunner.run(new WordsInCorpusTFIDFDriver(), args3);

        StringBuilder fileNames = new StringBuilder();
        String prefix = "";
        for (File name : files) {
            if (name.isFile() && FilenameUtils.getExtension(name.getName()).endsWith("txt")) {
                fileNames.append(prefix);
                prefix = ",";
                fileNames.append(FilenameUtils.removeExtension(name.getName()).replaceAll("_", ""));
            }
        }
        String OUTPUT_PATH4 = System.currentTimeMillis() + "_" + UUID.randomUUID()
                + "-TFIDFDriverImpl-4-distances";
        String[] args4 = { OUTPUT_PATH3, OUTPUT_PATH4, COMPETENCES_PATH, fileNames.toString() };
        Logger.getLogger(TFIDFDriverImpl.class.getName()).log(Level.INFO, "args4:{0}", Arrays.toString(args4));
        ToolRunner.run(new CompetencesDistanceDriver(), args4);

        Configuration conf = new Configuration();
        FileSystem fs = FileSystem.get(conf);
        Path hdfsRes = new Path(OUTPUT_PATH4);
        FileStatus[] results = fs.listStatus(hdfsRes);
        for (FileStatus s : results) {
            Path dest = new Path(OUT + "/" + s.getPath().getName());
            Logger.getLogger(TFIDFDriverImpl.class.getName()).log(Level.INFO, "Copy: {0} to: {1}",
                    new Object[] { s.getPath(), dest });
            fs.copyToLocalFile(s.getPath(), dest);
        }
        fs.delete(hdfsRes, true);

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

}