protected void advanceFile() { currentFileName = !fileNames.isEmpty() ? fileNames.remove(0) : null; nextLineNumber = 0; nextLine = null; reader = new BufferedLineReader(inputs.remove(0)); }
@Override public void close() { if (mReader != null) { try { mReader.close(); } finally { mReader = null; } } }
private String advanceLine() { mCurrentLine = mReader.readLine(); return mCurrentLine; }
/** * Non-destructive one-character look-ahead. * * @return If not eof, the next character that would be read. If eof, -1. */ @Override public int peek() { try { mark(2); // Two characters required here as the next read will collapse \r\n to a single \n final int ret = read(); reset(); return ret; } catch (IOException e) { throw new RuntimeIOException(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; }
@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(); } }
final BufferedLineReader reader = new BufferedLineReader(new GZIPInputStream(new FileInputStream(outputVcfFile.toFile()))); final Iterator<String> actualLines; while (-1 != reader.peek()) { lines.add(reader.readLine()); reader.close(); actualLines = lines.iterator();
/** * various test cases where there is no input, except perhaps a line terminator * @param terminator what the terminator should be in the input * @param lastLineTerminated does the input have a terminator */ private void fromStringEmptyTestHelper(final String terminator, final boolean lastLineTerminated) { final String input; if (lastLineTerminated) { input = terminator; } else { input = ""; } final BufferedLineReader blr = BufferedLineReader.fromString(input); blr.peek(); final String output = blr.readLine(); if (lastLineTerminated) { Assert.assertEquals(output, ""); } blr.peek(); Assert.assertNull(blr.readLine()); }
String line; while (true) { line = reader.readLine(); if (line == null) { return null; throwChainFileParseException("chain line has wrong number of fields", chainFile, reader.getLineNumber()); throwChainFileParseException("chain line does not start with 'chain'", chainFile, reader.getLineNumber()); id = Integer.parseInt(chainFields[12]); } catch (NumberFormatException e) { throwChainFileParseException("Invalid field", chainFile, reader.getLineNumber()); boolean sawLastLine = false; while (true) { line = reader.readLine(); if (line == null || line.equals("")) { if (!sawLastLine) { throwChainFileParseException("Reached end of chain without seeing terminal block", chainFile, reader.getLineNumber()); throwChainFileParseException("Terminal block seen before end of chain", chainFile, reader.getLineNumber()); sawLastLine = true; } else if (blockFields.length != 3) { throwChainFileParseException("Block line has unexpected number of fields", chainFile, reader.getLineNumber());
@Override protected void writeHeader(final String textHeader) { writeHeader(new SAMTextHeaderCodec().decode(BufferedLineReader.fromString(textHeader),fileName != null ? fileName : null)); }
private SAMRecord parseLine() { return parser.parseLine(mCurrentLine, mReader.getLineNumber()); }
/** * 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; }
input = input.concat(terminator); final BufferedLineReader blr = BufferedLineReader.fromString(input); for (int i = 0; i < lines.length - 1; ++i) { blr.peek(); final String s = blr.readLine(); String expected = lines[i]; Assert.assertEquals(s, expected); blr.peek(); String s = blr.readLine(); if (!lastLineTerminated && emptyLineState == EmptyLineState.LAST_LINE) { Assert.assertEquals(s, expected); blr.peek(); s = blr.readLine(); Assert.assertNull(s);
String line = reader.readLine(); if (line == null) { return null; throwChainFileParseException("chain line has wrong number of fields", chainFile, reader.getLineNumber()); throwChainFileParseException("chain line does not start with 'chain'", chainFile, reader.getLineNumber()); id = Integer.parseInt(chainFields[12]); } catch (NumberFormatException e) { throwChainFileParseException("Invalid field", chainFile, reader.getLineNumber()); boolean sawLastLine = false; while (true) { line = reader.readLine(); if (line == null || line.equals("")) { if (!sawLastLine) { throwChainFileParseException("Reached end of chain without seeing terminal block", chainFile, reader.getLineNumber()); throwChainFileParseException("Terminal block seen before end of chain", chainFile, reader.getLineNumber()); sawLastLine = true; } else if (blockFields.length != 3) { throwChainFileParseException("Block line has unexpected number of fields", chainFile, reader.getLineNumber());
@Override protected void writeHeader(final String textHeader) { writeHeader(new SAMTextHeaderCodec().decode(BufferedLineReader.fromString(textHeader),fileName != null ? fileName : null)); }
/** * Non-destructive one-character look-ahead. * * @return If not eof, the next character that would be read. If eof, -1. */ @Override public int peek() { try { mark(2); // Two characters required here as the next read will collapse \r\n to a single \n final int ret = read(); reset(); return ret; } catch (IOException e) { throw new RuntimeIOException(e); } }
private SAMRecord parseLine() { return parser.parseLine(mCurrentLine, mReader.getLineNumber()); }
protected void advanceFile() { currentFileName = !fileNames.isEmpty() ? fileNames.remove(0) : null; nextLineNumber = 0; nextLine = null; reader = new BufferedLineReader(inputs.remove(0)); }
/** * 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 Set<Integer> ids = new HashSet<Integer>(); 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) { if (ids.contains(chain.id)) { throw new SAMException("Chain id " + chain.id + " appears more than once in chain file."); } ids.add(chain.id); ret.addLhs(chain, chain.interval); } reader.close(); return ret; }
String line; while (true) { line = reader.readLine(); if (line == null) { return null; throwChainFileParseException("chain line has wrong number of fields", chainFile, reader.getLineNumber()); throwChainFileParseException("chain line does not start with 'chain'", chainFile, reader.getLineNumber()); id = Integer.parseInt(chainFields[12]); } catch (NumberFormatException e) { throwChainFileParseException("Invalid field", chainFile, reader.getLineNumber()); boolean sawLastLine = false; while (true) { line = reader.readLine(); if (line == null || line.equals("")) { if (!sawLastLine) { throwChainFileParseException("Reached end of chain without seeing terminal block", chainFile, reader.getLineNumber()); throwChainFileParseException("Terminal block seen before end of chain", chainFile, reader.getLineNumber()); sawLastLine = true; } else if (blockFields.length != 3) { throwChainFileParseException("Block line has unexpected number of fields", chainFile, reader.getLineNumber());