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:it.scoppelletti.security.keypairgen.KeyPairGeneratorBean.java

/**
 * Apre un flusso di output.// w ww  .  j ava2  s  . co m
 * 
 * @param  Nome del file.
 * @return Flusso.
 */
private OutputStream openOutput(File file) throws IOException {
    OutputStream out;
    IOResources ioRes = new IOResources();

    if (file.exists()) {
        if (myOverwrite) {
            myUI.display(MessageType.WARNING, ioRes.getFileOverwriteMessage(file.toString()));
        } else {
            throw new FileAlreadyExistException(file.toString());
        }
    }

    out = new PrintStream(file);

    return out;
}

From source file:de.berber.kindle.annotator.lib.KindleAnnotationReader.java

/**
 * Creates a new annotation reader for PDR files generated by the kindle
 * device.//from  w  ww . j  av  a 2s.  c  om
 * 
 * @param pdfFile
 *            The pdf file you want to read annotations for.
 */
public KindleAnnotationReader(final @Nonnull CompositeConfiguration cc, final @Nonnull File pdfFile) {
    assert pdfFile.toString().endsWith(".pdf");

    pdrFile = new File(pdfFile.toString().substring(0, pdfFile.toString().length() - 1) + "r");
    this.cc = cc;

    if (!pdrFile.exists()) {
        LOG.error("Cannot find PDR-file for " + pdfFile);
    }

    if (isDebuggingEnabled()) {
        try {
            debugStream = new FileOutputStream(pdfFile.toString() + ".log");
        } catch (final FileNotFoundException e) {
            debugStream = null;
        }
    }
}

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

/**
 * Test conversion of a compact file with quality scores to FASTA format.
 * @throws IOException if the files cannot be read/written properly
 *///from   w w  w  .  j  a  v a2s.  c  o m
@Test
public void toFastaWithQuality() throws IOException {
    final String inputFilename = "test-data/compact-reads/five-with-quality.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("Seqence for entry " + index + " is not correct", expectedSequence[index],
                entry.getSequence().toString());
        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(5, index);
    reader.close();
}

From source file:spring.osgi.io.OsgiBundleResourceTest.java

@Test
public void testNonBundleUrlWhichExists() throws Exception {
    File tmp = File.createTempFile("foo", "bar");
    tmp.deleteOnExit();//  ww w  . j  a va  2 s.  c  om
    resource = new OsgiBundleResource(bundle, "file:" + tmp.toString());
    assertNotNull(resource.getURL());
    assertTrue(resource.exists());
    tmp.delete();
}

From source file:com.totsp.mavenplugin.gwt.scripting.ScriptWriterUnix.java

/**
 * Write test scripts./*w  ww.j a v  a 2s  .c  om*/
 */
public void writeTestScripts(AbstractGWTMojo mojo) throws MojoExecutionException {

    // get extras
    String extra = (mojo.getExtraJvmArgs() != null) ? mojo.getExtraJvmArgs() : "";
    if (AbstractGWTMojo.OS_NAME.startsWith("mac") && (extra.indexOf("-XstartOnFirstThread") == -1)) {
        extra = "-XstartOnFirstThread " + extra;
    }
    String testExtra = mojo.getExtraTestArgs() != null ? mojo.getExtraTestArgs() : "";

    // make sure output dir is present
    File outputDir = new File(mojo.getBuildDir(), "gwtTest");
    outputDir.mkdirs();
    outputDir.mkdir();

    // for each test compile source root, build a test script
    List<String> testCompileRoots = mojo.getProject().getTestCompileSourceRoots();
    for (String currRoot : testCompileRoots) {

        // TODO better file filter here
        Collection<File> coll = FileUtils.listFiles(new File(currRoot),
                new WildcardFileFilter(mojo.getTestFilter()), HiddenFileFilter.VISIBLE);

        for (File currFile : coll) {

            String testName = currFile.toString();
            mojo.getLog().debug(("gwtTest test match found (after filter applied) - " + testName));

            // parse off the extension
            if (testName.lastIndexOf('.') > testName.lastIndexOf(File.separatorChar)) {
                testName = testName.substring(0, testName.lastIndexOf('.'));
            }
            if (testName.startsWith(currRoot)) {
                testName = testName.substring(currRoot.length());
            }
            if (testName.startsWith(File.separator)) {
                testName = testName.substring(1);
            }
            testName = StringUtils.replace(testName, File.separatorChar, '.');
            mojo.getLog().debug("testName after parsing - " + testName);

            // start script inside gwtTest output dir, and name it with test class name
            File file = new File(mojo.getBuildDir() + File.separator + "gwtTest",
                    "gwtTest-" + testName + ".sh");
            PrintWriter writer = this.getPrintWriterWithClasspath(mojo, file, DependencyScope.TEST);

            // build Java command
            writer.print("\"" + mojo.getJavaCommand() + "\" ");
            if (extra.length() > 0) {
                writer.print(" " + extra + " ");
            }
            if (testExtra.length() > 0) {
                writer.print(" " + testExtra + " ");
            }

            writer.print("-cp \"$CP\" ");

            writer.print("-Dcatalina.base=\"" + mojo.getTomcat().getAbsolutePath() + "\" ");

            writer.print("junit.textui.TestRunner ");
            writer.print(testName);

            // write script out                
            writer.flush();
            writer.close();
            this.chmodUnixFile(file);
        }
    }
}

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

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

    final FastXReader reader = new FastXReader(outputFilename);
    assertEquals("File should be in FASTQ format", "fq", 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 some quality values", 35, quality.length());
        // check quality scores
        for (int i = 0; i < 35; i++) {
            final char qualityCharacter = quality.charAt(i);
            assertEquals("Entry " + index + " has incorrect quality score at index " + i, 40,
                    QualityEncoding.SANGER.asciiEncodingToPhredQualityScore(qualityCharacter));
        }
        assertTrue("Entry " + index + " is not complete", entry.isEntryComplete());
        index++;
    }

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

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

/**
 * Test conversion of a compact file with no quality scores to Illumina/FASTQ format.
 * @throws IOException if the files cannot be read/written properly
 *///from w  ww .j  av  a2 s.  c  o m
@Test
public void toFastqIlluminaNoQuality() throws IOException {
    final String inputFilename = "test-data/compact-reads/s_1_sequence_short.compact-reads";
    final File fastqFile = createTempFile("llumina", ".fastq");
    final String outputFilename = fastqFile.toString();
    final CompactToFastaMode compactToFastaMode = new CompactToFastaMode();
    compactToFastaMode.setInputFilename(inputFilename);
    compactToFastaMode.setOutputFilename(outputFilename);
    compactToFastaMode.setOutputFormat(CompactToFastaMode.OutputFormat.FASTQ);
    compactToFastaMode.setQualityEncoding(QualityEncoding.ILLUMINA);
    compactToFastaMode.execute();

    final FastXReader reader = new FastXReader(outputFilename);
    assertEquals("File should be in FASTQ format", "fq", 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 some quality values", 35, quality.length());
        // check quality scores
        for (int i = 0; i < 35; i++) {
            final char qualityCharacter = quality.charAt(i);
            assertEquals("Entry " + index + " has incorrect quality score at index " + i, 40,
                    QualityEncoding.ILLUMINA.asciiEncodingToPhredQualityScore(qualityCharacter));
        }
        assertTrue("Entry " + index + " is not complete", entry.isEntryComplete());
        index++;
    }

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

From source file:it.polimi.diceH2020.SPACE4CloudWS.solvers.AbstractSolver.java

protected void sendFiles(@NotNull String remoteDirectory, List<File> lstFiles) {
    try {/*from   ww  w  . j av a  2 s .c om*/
        connector.exec("mkdir -p " + remoteDirectory, getClass());
    } catch (JSchException | IOException e1) {
        logger.error("Cannot create new Simulation Folder!", e1);
    }

    lstFiles.forEach((File file) -> {
        try {
            connector.sendFile(file.getAbsolutePath(), remoteDirectory + File.separator + file.getName(),
                    getClass());
        } catch (JSchException | IOException e) {
            logger.error("Error sending file: " + file.toString(), e);
        }
    });
}

From source file:fi.smaa.jsmaa.gui.JSMAAMainFrame.java

private String getCanonicalPath(File selectedFile) {
    try {//from www .  j a va  2 s.c  o m
        return selectedFile.getCanonicalPath();
    } catch (Exception e) {
        return selectedFile.toString();
    }
}

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

/**
 * Display the alignments as text files.
 *
 * @throws java.io.IOException error reading / writing
 *//*  w w w . j a v  a  2 s .  com*/
@Override
public void execute() throws IOException {
    PrintStream writer = null;
    try {
        numberOfSkippedReads = 0;
        numberOfObservedReads = 0;
        writer = outputFile == null ? System.out : new PrintStream(new FileOutputStream(outputFile));
        final Int2ObjectMap<ReadQualityStats> qualityStats = new Int2ObjectOpenHashMap<ReadQualityStats>();
        final ProgressLogger progress = new ProgressLogger(LOG);
        progress.start();
        final MersenneTwister random = new MersenneTwister(37);
        final boolean doSample = sampleFraction < 1.0d;
        writer.println("basename\treadIndex\t25%-percentile\tmedian\taverageQuality\t75%-percentile");
        for (final File filename : inputFiles) {
            final ReadsReader reader = new ReadsReader(filename);
            final String basename = ReadsReader.getBasename(filename.toString());
            for (final Reads.ReadEntry entry : reader) {
                if (!doSample || random.nextDouble() < sampleFraction) {
                    final ByteString qualityScores = entry.getQualityScores();
                    final int size = qualityScores.size();
                    for (int readIndex = 0; readIndex < size; readIndex++) {
                        final byte code = qualityScores.byteAt(readIndex);
                        ReadQualityStats stats = qualityStats.get(readIndex);
                        if (stats == null) {
                            stats = new ReadQualityStats(1.0d);
                            qualityStats.put(readIndex, stats);
                            stats.readIndex = readIndex;
                        }
                        stats.observe(code);
                    }
                    numberOfObservedReads++;
                } else {
                    numberOfSkippedReads++;
                }
                progress.lightUpdate();
            }

            for (final ReadQualityStats stat : qualityStats.values()) {
                if (!stat.sampleIsEmpty()) {
                    stat.evaluatePercentiles();
                    writer.printf("%s\t%d\t%d\t%d\t%f\t%d%n", basename, stat.readIndex, stat.percentile(25),
                            stat.percentile(50), stat.averageQuality / stat.observedCount, stat.percentile(75));
                }
            }
        }
        progress.updateAndDisplay();
        progress.stop();

    } finally {
        if (writer != System.out) {
            IOUtils.closeQuietly(writer);
        }
    }
}