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:com.github.chenxiaolong.dualbootpatcher.RootFile.java

public void moveTo(File dest) {
    moveTo(new RootFile(dest.toString()));
}

From source file:com.github.chenxiaolong.dualbootpatcher.RootFile.java

public void copyTo(File dest) {
    copyTo(new RootFile(dest.toString()));
}

From source file:codegen.CodeGeneratorTest.java

private void copy(String source, String dest) throws IOException {
    File fileToCopy = new File(source).getAbsoluteFile();
    assertTrue("File " + fileToCopy.toString() + " doesn't exist", fileToCopy.exists());
    File destination = new File(dest).getAbsoluteFile();
    destination.getParentFile().mkdirs();
    FileUtils.copyFile(fileToCopy, destination);
}

From source file:org.opennms.ng.dao.support.NodeSnmpResourceType.java

/** {@inheritDoc} */
@Override//  w w w . jav a2  s . co  m
public List<OnmsResource> getResourcesForNodeSource(String nodeSource, int nodeId) {
    ArrayList<OnmsResource> resources = new ArrayList<OnmsResource>();
    File relPath = new File(DefaultResourceDao.SNMP_DIRECTORY,
            ResourceTypeUtils.getRelativeNodeSourceDirectory(nodeSource).toString());

    Set<OnmsAttribute> attributes = ResourceTypeUtils
            .getAttributesAtRelativePath(m_resourceDao.getRrdDirectory(), relPath.toString());

    OnmsResource resource = new OnmsResource("", "Node-level Performance Data", this, attributes);
    resources.add(resource);
    return resources;
}

From source file:com.wakatime.eclipse.plugin.Dependencies.java

public boolean downloadFile(String url, String saveAs) {
    File outFile = new File(saveAs);

    // create output directory if does not exist
    File outDir = outFile.getParentFile();
    if (!outDir.exists())
        outDir.mkdirs();// w  w  w . j a v  a2s. c om

    WakaTime.log("Downloading " + url + " to " + outFile.toString());

    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet(url);
    try {

        // download file
        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();

        // save file contents
        DataOutputStream os = new DataOutputStream(new FileOutputStream(outFile));
        entity.writeTo(os);
        os.close();

        return true;

    } catch (ClientProtocolException e) {
        WakaTime.error("Error", e);
    } catch (FileNotFoundException e) {
        WakaTime.error("Error", e);
    } catch (IOException e) {
        WakaTime.error("Error", e);
    }

    return false;
}

From source file:com.CodeSeance.JSeance.CodeGenXML.DependencyTracking.DependencyManager.java

public DependencyManager(File targetDir) {
    final String DEPENDENCY_FILENAME = ".jseance-dependencies.xml";

    // Output directory must exist already
    assert targetDir.exists();

    // Load the dependencies from disk
    dependencyFile = new File(targetDir, DEPENDENCY_FILENAME);
    if (dependencyFile.exists()) {
        boolean deleteFile = false;
        try {//w ww  . j a v a  2s  .c  o m
            // Load the dependencies file
            XMLLoader xmLoader = XMLLoader.build(false);
            Document document = xmLoader.loadXML(targetDir, DEPENDENCY_FILENAME);

            // Get the root node
            Element rootNode = document.getDocumentElement();
            NodeList templateChildren = rootNode.getChildNodes();

            // Iterate through the "Template" children
            for (int i = 0; i < templateChildren.getLength(); i++) {
                if (templateChildren.item(i) instanceof Element) {
                    Element templateChild = (Element) templateChildren.item(i);

                    // Load the template file entry and store it in this class hashtable
                    File templateFile = new File(templateChild.getAttribute("fileName"));
                    TemplateDependencies templateDependency = new TemplateDependencies(templateFile);
                    templateDependencies.put(templateFile.toString(), templateDependency);

                    // Iterate through the child nodes
                    NodeList dependencyNodes = templateChild.getChildNodes();
                    for (int j = 0; j < dependencyNodes.getLength(); j++) {
                        if (dependencyNodes.item(j) instanceof Element) {
                            Element dependencyChild = (Element) dependencyNodes.item(j);
                            String localName = dependencyChild.getLocalName();
                            File dependencyChildFile = new File(dependencyChild.getAttribute("fileName"));
                            if (localName.equals("Input")) {
                                templateDependency.addInputFile(dependencyChildFile);
                            } else if (localName.equals("Output")) {
                                templateDependency.addOutputFile(dependencyChildFile);
                            } else {
                                throw new RuntimeException(
                                        String.format("Unexpected dependency node:[%s] in file:[%s]", localName,
                                                dependencyFile));
                            }
                        }
                    }
                }
            }

        } catch (Exception ex) {
            log.warn(String.format("Cannot parse dependency file:[%s], deleting. Cause:[%s]", dependencyFile,
                    ex.getMessage()));
            deleteFile = true;
        }

        if (deleteFile) {
            if (!dependencyFile.delete()) {
                throw new RuntimeException(
                        String.format("Cannot delete corrupt dependency file:[%s]", dependencyFile));
            }
        }
    }
}

From source file:com.CodeSeance.JSeance2.CodeGenXML.XMLElements.Test.OutputTest.java

@Test
public void fileOutputTest_AutoCreateParentDirsError() {
    CleanupAutoCreateParentDirs();//from w  w  w  . j a  v a  2 s.  co m
    ExecutionError.simulate_CANNOT_CREATE_PARENT_DIRS = true;

    File outputFile = new File(
            "A" + File.separator + "B" + File.separator + "C" + File.separator + "Output.txt");
    template.append(String.format("!Output(\"%s\")!",
            org.apache.commons.lang.StringEscapeUtils.escapeJavaScript(outputFile.toString())));
    template.append("Test");
    template.append("!End!");
    expectError(ExecutionError.CANNOT_WRITE_TARGET_FILE, true, true, true, false, null, false);
    CleanupAutoCreateParentDirs();
}

From source file:com.norconex.committer.solr.SolrCommitterSolrIntegrationTest.java

@Before
public void setup() throws Exception {
    File solrHome = tempFolder.newFolder("solr");
    initCore("src/test/resources/solrconfig.xml", "src/test/resources/schema.xml", solrHome.toString());

    committer = new SolrCommitter(new ISolrServerFactory() {
        private static final long serialVersionUID = 4648990433469043210L;

        @Override//from w  w w  .ja v a 2s . c om
        public SolrClient createSolrServer(SolrCommitter solrCommitter) {
            return server;
        }
    });
    committer.setUpdateUrlParam("commitWithin", "1");

    queue = tempFolder.newFolder("queue");
    committer.setQueueDir(queue.toString());
    server.deleteByQuery("*:*");
    server.commit();
}

From source file:de.unidue.ltl.flextag.features.ngram.LuceneNgramUnitTest.java

private File runFeatureExtractor(File luceneFolder) throws Exception {
    File outputPath = folder.newFolder();

    Object[] parameters = new Object[] { TokenContext.PARAM_TARGET_INDEX, "1",
            TokenContext.PARAM_UNIQUE_EXTRACTOR_NAME, EXTRACTOR_NAME, TokenContext.PARAM_SOURCE_LOCATION,
            luceneFolder.toString(), LuceneUniGramMetaCollector.PARAM_TARGET_LOCATION,
            luceneFolder.toString() };/*from  ww  w.j  a  v a  2s .c o m*/

    ExternalResourceDescription featureExtractor = ExternalResourceFactory
            .createExternalResourceDescription(TokenContext.class, parameters);
    List<ExternalResourceDescription> fes = new ArrayList<>();
    fes.add(featureExtractor);

    CollectionReaderDescription reader = CollectionReaderFactory.createReaderDescription(
            TestReaderSingleLabel.class, TestReaderSingleLabel.PARAM_LANGUAGE, "en",
            TestReaderSingleLabel.PARAM_SOURCE_LOCATION, "src/test/resources/text/input.txt",
            TestReaderSingleLabel.PARAM_SUPPRESS_DOCUMENT_ANNOTATION, true);

    AnalysisEngineDescription segmenter = AnalysisEngineFactory
            .createEngineDescription(BreakIteratorSegmenter.class);

    AnalysisEngineDescription unitAnno = AnalysisEngineFactory
            .createEngineDescription(EachTokenAsUnitAnnotator.class);

    AnalysisEngineDescription featExtractorConnector = TaskUtils.getFeatureExtractorConnector(
            outputPath.getAbsolutePath(), JsonDataWriter.class.getName(), Constants.LM_SINGLE_LABEL,
            Constants.FM_UNIT, DenseFeatureStore.class.getName(), false, false, false, new ArrayList<>(), false,
            fes);

    SimplePipeline.runPipeline(reader, segmenter, unitAnno, featExtractorConnector);

    return outputPath;
}

From source file:edu.cornell.med.icb.goby.modes.TestCompactToFastaMode.java

/**
 * Test conversion of a compact file with no quality scores to FASTA format.
 * @throws IOException if the files cannot be read/written properly
 *///from   w w  w.j  a  v a  2  s . c o  m
@Test
public void toFastaNoQuality() throws IOException {
    final String inputFilename = "test-data/compact-reads/s_1_sequence_short.compact-reads";
    final File fastaFile = createTempFile("toFasta", ".fasta");
    final String outputFilename = fastaFile.toString();
    final CompactToFastaMode compactToFastaMode = new CompactToFastaMode();
    compactToFastaMode.setInputFilename(inputFilename);
    compactToFastaMode.setOutputFilename(outputFilename);
    compactToFastaMode.setOutputFormat(CompactToFastaMode.OutputFormat.FASTA);
    compactToFastaMode.execute();

    final FastXReader reader = new FastXReader(outputFilename);
    assertEquals("File should be in FASTA format", "fa", reader.getFileType());

    int index = 0;
    for (final FastXEntry entry : reader) {
        assertEquals("Entry " + index + "symbol is not correct", '>', entry.getHeaderSymbol());
        assertEquals("Read length is not correct", 35, entry.getReadLength());
        final MutableString quality = entry.getQuality();
        assertNotNull("Quality string should never be null", quality);
        assertEquals("There should be no quality values", 0, quality.length());
        assertTrue("Entry " + index + " is not complete", entry.isEntryComplete());
        index++;
    }

    assertEquals(73, index);
    reader.close();
}