protected void advanceFile() { currentFileName = !fileNames.isEmpty() ? fileNames.remove(0) : null; nextLineNumber = 0; nextLine = null; reader = new BufferedLineReader(inputs.remove(0)); }
/** * Returns a {@link BufferedLineReader} that gets its input from a String. No charset conversion * is necessary because the String is in unicode. */ public static BufferedLineReader fromString(final String s) { return new BufferedLineReader(new ByteArrayInputStream(s.getBytes())); }
/** * Returns a {@link BufferedLineReader} that gets its input from a String. No charset conversion * is necessary because the String is in unicode. */ public static BufferedLineReader fromString(final String s) { return new BufferedLineReader(new ByteArrayInputStream(s.getBytes())); }
protected void advanceFile() { currentFileName = !fileNames.isEmpty() ? fileNames.remove(0) : null; nextLineNumber = 0; nextLine = null; reader = new BufferedLineReader(inputs.remove(0)); }
/** * Prepare to read a SAM text file. * * @param stream Need not be buffered, as this class provides buffered reading. */ public SAMTextReader(final InputStream stream, final ValidationStringency validationStringency, final SAMRecordFactory factory) { mReader = new BufferedLineReader(stream); this.validationStringency = validationStringency; this.samRecordFactory = factory; readHeader(); }
/** * Prepare to read a SAM text file. * * @param stream Need not be buffered, as this class provides buffered reading. */ public SAMTextReader(final InputStream stream, final ValidationStringency validationStringency, final SAMRecordFactory factory) { mReader = new BufferedLineReader(stream); this.validationStringency = validationStringency; this.samRecordFactory = factory; readHeader(); }
/** * Prepare to read a SAM text file. * @param stream Need not be buffered, as this class provides buffered reading. */ public SAMTextReader(final InputStream stream, final ValidationStringency validationStringency, final SAMRecordFactory factory) { mReader = new BufferedLineReader(stream); this.validationStringency = validationStringency; this.samRecordFactory = factory; readHeader(); }
/** * Constructor. Opens up a buffered reader and reads the first line. * * @param inputStreams the file(s) to parse, in order */ public BasicInputParser(final boolean treatGroupedDelimitersAsOne, final InputStream... inputStreams) { if (inputStreams.length == 0) { throw new IllegalArgumentException("At least one input must be specified."); } this.inputs.addAll(Arrays.asList(inputStreams)); reader = new BufferedLineReader(this.inputs.remove(0)); this.setTreatGroupedDelimitersAsOne(treatGroupedDelimitersAsOne); }
/** * Constructor. Opens up a buffered reader and reads the first line. * * @param inputStreams the file(s) to parse, in order */ public BasicInputParser(final boolean treatGroupedDelimitersAsOne, final InputStream... inputStreams) { if (inputStreams.length == 0) { throw new IllegalArgumentException("At least one input must be specified."); } this.inputs.addAll(Arrays.asList(inputStreams)); reader = new BufferedLineReader(this.inputs.remove(0)); this.setTreatGroupedDelimitersAsOne(treatGroupedDelimitersAsOne); }
@Override protected SAMFileHeader readHeader(InputStream is) { SAMFileHeader samFileHeader = new SAMTextHeaderCodec().decode(new BufferedLineReader(is), null); return samFileHeader; } },
LineReader lr = new BufferedLineReader(new FileReader(...)); lr.readLine(); LineReader lr2 = new SpecialLineReader(); lr2.readLine();
@Override SAMSequenceDictionary extractDictionary(final Path dictionary) { try (BufferedLineReader bufferedLineReader = new BufferedLineReader(ParsingUtils.openInputStream(dictionary.toUri().toString()))) { final SAMTextHeaderCodec codec = new SAMTextHeaderCodec(); final SAMFileHeader header = codec.decode(bufferedLineReader, dictionary.toString()); return header.getSequenceDictionary(); } catch (final IOException e) { throw new SAMException("Could not open sequence dictionary file: " + dictionary, e); } } },
@Override SAMSequenceDictionary extractDictionary(final Path dictionary) { try (BufferedLineReader bufferedLineReader = new BufferedLineReader(ParsingUtils.openInputStream(dictionary.toUri().toString()))) { final SAMTextHeaderCodec codec = new SAMTextHeaderCodec(); final SAMFileHeader header = codec.decode(bufferedLineReader, dictionary.toString()); return header.getSequenceDictionary(); } catch (final IOException e) { throw new SAMException("Could not open sequence dictionary file: " + dictionary, e); } } },
/** * Read all the chains and load into an OverlapDetector. * @param chainFile File in UCSC chain format. * @return OverlapDetector will all Chains from reader loaded into it. */ static OverlapDetector<Chain> loadChains(final File chainFile) { final BufferedLineReader reader = new BufferedLineReader(IOUtil.openFileForReading(chainFile)); final OverlapDetector<Chain> ret = new OverlapDetector<Chain>(0, 0); Chain chain; while ((chain = Chain.loadChain(reader, chainFile.toString())) != null) { ret.addLhs(chain, chain.interval); } reader.close(); return ret; }
/** * Read all the chains and load into an OverlapDetector. * @param chainFile File in UCSC chain format. * @return OverlapDetector will all Chains from reader loaded into it. */ static OverlapDetector<Chain> loadChains(final File chainFile) { final BufferedLineReader reader = new BufferedLineReader(IOUtil.openFileForReading(chainFile)); final OverlapDetector<Chain> ret = new OverlapDetector<Chain>(0, 0); Chain chain; while ((chain = Chain.loadChain(reader, chainFile.toString())) != null) { ret.addLhs(chain, chain.interval); } reader.close(); return ret; }
@Test public void testCanLoadAndRoundTripWithSnappy() throws IOException { final SnappyLoader snappyLoader = new SnappyLoader(false); Assert.assertTrue(snappyLoader.isSnappyAvailable()); final File tempFile = File.createTempFile("snappyOutput", ".txt"); tempFile.deleteOnExit(); final String toWrite = "Hello Filesystem"; try(Writer out = new OutputStreamWriter(snappyLoader.wrapOutputStream(new FileOutputStream(tempFile)))) { out.write(toWrite); } try(LineReader in = new BufferedLineReader(snappyLoader.wrapInputStream(new FileInputStream(tempFile)))){ final String recoveredString = in.readLine(); Assert.assertEquals(recoveredString, toWrite); } }
@Test public void testSeek() throws Exception { String expectedLine = "ccccccccc"; File testFile = new File("src/test/resources/htsjdk/samtools/seekablestream/seekTest.txt"); SeekableFileStream is = new SeekableFileStream(testFile); is.seek(20); BufferedLineReader reader = new BufferedLineReader(is); String nextLine = reader.readLine(); Assert.assertEquals(expectedLine, nextLine); reader.close(); } }
/** * Loads the sequence dictionary from a FASTA file input stream. * * @param in the FASTA file input stream. * @return the sequence dictionary, or <code>null</code> if the header has no dictionary or it was empty. */ public static SAMSequenceDictionary loadDictionary(final InputStream in) { final SAMTextHeaderCodec codec = new SAMTextHeaderCodec(); final BufferedLineReader reader = new BufferedLineReader(in); final SAMFileHeader header = codec.decode(reader, null); if (header.getSequenceDictionary().isEmpty()) { return null; } return header.getSequenceDictionary(); }
/** * Loads the sequence dictionary from a FASTA file input stream. * * @param in the FASTA file input stream. * @return the sequence dictionary, or <code>null</code> if the header has no dictionary or it was empty. */ public static SAMSequenceDictionary loadDictionary(final InputStream in) { final SAMTextHeaderCodec codec = new SAMTextHeaderCodec(); final BufferedLineReader reader = new BufferedLineReader(in); final SAMFileHeader header = codec.decode(reader, null); if (header.getSequenceDictionary().isEmpty()) { return null; } return header.getSequenceDictionary(); }
@Test(dataProvider = "compressedVcfsToTest") public void testWrappedSeekableStreamInGZIPinputStream(final File input, final long nLines) throws Exception { try (final LineReader reader = new BufferedLineReader(new GZIPInputStream(new SeekableFileStream(input)))) { for (int i = 0; i < nLines; i++) { Assert.assertNotNull(reader.readLine(), "line #" + reader.getLineNumber()); } Assert.assertNull(reader.readLine()); Assert.assertEquals(reader.getLineNumber(), nLines); } }