@Override public FeatureCodecHeader readHeader(final PositionalBufferedStream stream) throws IOException { // Construct a reader that does not read ahead (because we don't want to consume data from the stream that is not the header) final AsciiLineReader nonReadAheadLineReader = new AsciiLineReader(stream); final List<String> headerLines = new ArrayList<String>(); long headerLengthInBytes = 0; while (stream.peek() == ('#' & 0xff)) { // Look for header lines, which are prefixed by '#'. headerLines.add(nonReadAheadLineReader.readLine()); headerLengthInBytes = stream.getPosition(); } return new FeatureCodecHeader(headerLines, headerLengthInBytes); }
/** * Returns either 1 or 2, representing the number of * bytes used to end a line. Reads only from first line of a file * * @param filePath * @return * @throws IOException */ public static int getBytesAtEnd(String filePath) throws IOException { InputStream is = new FileInputStream(filePath); AsciiLineReader reader = new AsciiLineReader(is); String line = reader.readLine(); int bytesThisLine = (int) reader.getPosition(); reader.close(); return bytesThisLine - line.length(); }
@Test public void voidTestLineEndingLengthAtEof() throws Exception { final String input = "Hello\nWorld\r\n"; final InputStream is = new ByteArrayInputStream(input.getBytes()); final AsciiLineReader in = AsciiLineReader.from(is); Assert.assertEquals(in.getLineTerminatorLength(), -1); Assert.assertEquals(in.readLine(), "Hello"); Assert.assertEquals(in.getLineTerminatorLength(), 1); Assert.assertEquals(in.readLine(), "World"); Assert.assertEquals(in.getLineTerminatorLength(), 2); }
@Override protected Tuple<String, Long> advance() { final String line; final long position = asciiLineReader.getPosition(); // A line's position is where it starts, so get it before reading the line. try { line = asciiLineReader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } return line == null ? null : new Tuple<String, Long>(line, position); }
public static boolean parsableMAGE_TAB(ResourceLocator file) throws IOException { AsciiLineReader reader = null; try { reader = ParsingUtils.openAsciiReader(file); String nextLine = null; //skip first row reader.readLine(); //check second row for MAGE_TAB identifiers if ((nextLine = reader.readLine()) != null && (nextLine.contains("Reporter REF") || nextLine.contains("Composite Element REF") || nextLine.contains("Term Source REF") || nextLine.contains("CompositeElement REF") || nextLine.contains("TermSource REF") || nextLine.contains("Coordinates REF"))) { return true; } } finally { if (reader != null) { reader.close(); } } return false; }
@Override public LocationAware makeIndexableSourceFromStream(final InputStream bufferedInputStream) { final PositionalBufferedStream pbs; if (bufferedInputStream instanceof PositionalBufferedStream) { pbs = (PositionalBufferedStream) bufferedInputStream; } else { pbs = new PositionalBufferedStream(bufferedInputStream); } return new AsciiLineReaderIterator(new AsciiLineReader(pbs)); }
is = new GZIPInputStream(is); bufReader = new AsciiLineReader(is); while ((nextLine = bufReader.readLine()) != null) { String[] tokens = nextLine.split("\t"); probes.add(tokens[0]); } finally { if (bufReader != null) { bufReader.close();
AsciiLineReader reader = new AsciiLineReader(bis); while ((nextLine = reader.readLine()) != null) { lastFilePosition = reader.getPosition();
while (nSkip-- > 0 && reader.readLine() != null) { long startPos = reader.getPosition(); while ((nextLine = reader.readLine()) != null & lines < 100) { lines++; double bytesPerLine = (double) ((reader.getPosition() - startPos) / lines); int nLines = (int) (fileLength / bytesPerLine); return nLines; } finally { try { reader.close(); } catch (Exception e) {
try(final AsciiLineReader in = AsciiLineReader.from(IOUtil.openFileForReading(fastaFile))) { String previous = in.readLine(); if (previous == null) { throw new SAMException("Cannot index empty file: " + fastaFile); long location = in.getPosition(); for (String line = in.readLine(); previous != null; line = in.readLine()) { entry = new FaiEntryBuilder(sequenceIndex++, previous, line, in.getLineTerminatorLength(), location); } else if (line != null && line.charAt(0) == '>') { location = in.getPosition(); } else if (line != null && !line.isEmpty()) { entry.updateWithSequence(line, in.getLineTerminatorLength());
/** A VCFHeader is read from the input Path. */ public VCFRecordWriter( Path output, Path input, boolean writeHeader, TaskAttemptContext ctx) throws IOException { final AsciiLineReader r = new AsciiLineReader( input.getFileSystem(ctx.getConfiguration()).open(input)); final FeatureCodecHeader h = codec.readHeader(new AsciiLineReaderIterator(r)); if (h == null || !(h.getHeaderValue() instanceof VCFHeader)) throw new IOException("No VCF header found in "+ input); r.close(); init(output, (VCFHeader) h.getHeaderValue(), writeHeader, ctx); } public VCFRecordWriter(
printStatus("BufferedReader", lineCount, rate, dt); reader2.close(); printStatus("BufferedReader", lineCount, rate, dt); longLineBufferedReader.close(); final LineReader reader = new AsciiLineReader(pbs); t0 = System.currentTimeMillis(); lineCount = 0; printStatus("PositionalBufferedStream", lineCount, rate, dt); pbs.close();
/** * Test that we read the correct number of lines * from a file * @throws Exception */ @Test public void testReadLines() throws Exception { String filePath = TestUtils.DATA_DIR + "gwas/smallp.gwas"; InputStream is = new FileInputStream(filePath); AsciiLineReader reader = AsciiLineReader.from(is); int actualLines = 0; int expectedNumber = 20; String nextLine = ""; while((nextLine = reader.readLine()) != null && actualLines < (expectedNumber + 5)){ actualLines++; //This particular test file has no empty lines assertTrue(nextLine.length() > 0); } assertEquals(expectedNumber, actualLines); }
/** Returns the byte position at the beginning of the next line. */ @Override public long getPosition() { final Tuple<String, Long> peek = peek(); // Be careful: peek will be null at the end of the stream. return peek != null ? peek.b : asciiLineReader.getPosition(); } }
@Override public LocationAware makeIndexableSourceFromStream(final InputStream inputStream) { return new AsciiLineReaderIterator(AsciiLineReader.from(inputStream)); }
/** * Load attributes from an ascii file in "Sample Info" format. */ public void loadSampleInfo(ResourceLocator locator) { AsciiLineReader reader = null; try { reader = ParsingUtils.openAsciiReader(locator); loadSampleTable(reader, locator.getPath()); loadedResources.add(locator); if (!Globals.isHeadless()) { IGV.getInstance().resetOverlayTracks(); IGV.getInstance().doRefresh(); } } catch (IOException ex) { log.error("Error loading attribute file", ex); throw new DataLoadException("Error reading attribute file", locator.getPath()); } finally { if (reader != null) { reader.close(); } firePropertyChange(this, ATTRIBUTES_LOADED_PROPERTY, null, null); } }
public GeraldIterator() { this.chr = null; reader = new AsciiLineReader(is); readNextRecord(); }
public static boolean parsableMAGE_TAB(ResourceLocator file) throws IOException { AsciiLineReader reader = null; try { reader = ParsingUtils.openAsciiReader(file); String nextLine = null; //skip first row reader.readLine(); //check second row for MAGE_TAB identifiers if ((nextLine = reader.readLine()) != null && (nextLine.contains("Reporter REF") || nextLine.contains("Composite Element REF") || nextLine.contains("Term Source REF") || nextLine.contains("CompositeElement REF") || nextLine.contains("TermSource REF") || nextLine.contains("Coordinates REF"))) { int count = 0; // check if this mage_tab data matrix can be parsed by this class while ((nextLine = reader.readLine()) != null && count < 5) { nextLine = nextLine.trim(); if (nextLine.startsWith("SNP_A") || nextLine.startsWith("CN_")) { return true; } count++; } return false; } } finally { if (reader != null) { reader.close(); } } return false; }
PrintWriter allWriter = null; try { reader = new AsciiLineReader(new FileInputStream(inputFile)); reader.readLine(); String nextLine; File dir = inputFile.getParentFile(); allWriter.println("track name=\"Repeat Masker\" \" gffTags=\"on\""); while ((nextLine = reader.readLine()) != null) { String[] tokens = Globals.tabPattern.split(nextLine, -1); String chr = tokens[chrCol]; e.printStackTrace(); } finally { reader.close();