/** * @return an input stream from the given path * @throws IOException */ public static InputStream openInputStream(String path) throws IOException { return openInputStream(path, null); }
/** * @return an input stream from the given path * @throws IOException */ public static InputStream openInputStream(String path) throws IOException { return openInputStream(path, null); }
private static InputStream indexFileInputStream(final String indexFile, Function<SeekableByteChannel, SeekableByteChannel> indexWrapper) throws IOException { final InputStream inputStreamInitial = ParsingUtils.openInputStream(indexFile, indexWrapper); if (indexFile.endsWith(".gz")) { return new GZIPInputStream(inputStreamInitial); } else if (indexFile.endsWith(TabixUtils.STANDARD_INDEX_EXTENSION)) { return new BlockCompressedInputStream(inputStreamInitial); } else { return inputStreamInitial; } }
private static InputStream indexFileInputStream(final String indexFile, Function<SeekableByteChannel, SeekableByteChannel> indexWrapper) throws IOException { final InputStream inputStreamInitial = ParsingUtils.openInputStream(indexFile, indexWrapper); if (indexFile.endsWith(".gz")) { return new GZIPInputStream(inputStreamInitial); } else if (indexFile.endsWith(TabixUtils.STANDARD_INDEX_EXTENSION)) { return new BlockCompressedInputStream(inputStreamInitial); } else { return inputStreamInitial; } }
/** * creates a VCF iterator from a URI It detects if the stream is a BCF * stream or a GZipped stream. * * @param path the Path * @param wrapper wrapper for {@link htsjdk.samtools.seekablestream.SeekablePathStream}. Can be null. * @return the VCFIterator * @throws IOException */ public VCFIterator open(final String path, final Function<SeekableByteChannel, SeekableByteChannel> wrapper) throws IOException { return open(ParsingUtils.openInputStream(path, wrapper)); }
/** * creates a VCF iterator from a URI It detects if the stream is a BCF * stream or a GZipped stream. * * @param path the Path * @param wrapper wrapper for {@link htsjdk.samtools.seekablestream.SeekablePathStream}. Can be null. * @return the VCFIterator * @throws IOException */ public VCFIterator open(final String path, final Function<SeekableByteChannel, SeekableByteChannel> wrapper) throws IOException { return open(ParsingUtils.openInputStream(path, wrapper)); }
@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); } } },
private void tstStream(String path) throws IOException{ InputStream is = ParsingUtils.openInputStream(path); Assert.assertNotNull(is, "InputStream is null for " + path); int b = is.read(); Assert.assertNotSame(b, -1); }
/** * read the header from the file * * @throws IOException throws an IOException if we can't open the file */ private void readHeader() throws IOException { InputStream is = null; PositionalBufferedStream pbs = null; try { is = ParsingUtils.openInputStream(path, wrapper); if (IOUtil.hasBlockCompressedExtension(new URI(URLEncoder.encode(path, "UTF-8")))) { // TODO: TEST/FIX THIS! https://github.com/samtools/htsjdk/issues/944 // TODO -- warning I don't think this can work, the buffered input stream screws up position is = new GZIPInputStream(new BufferedInputStream(is)); } pbs = new PositionalBufferedStream(is); final SOURCE source = codec.makeSourceFromStream(pbs); header = codec.readHeader(source); } catch (Exception e) { throw new TribbleException.MalformedFeatureFile("Unable to parse header with error: " + e.getMessage(), path, e); } finally { if (pbs != null) pbs.close(); else if (is != null) is.close(); } }
/** * read the header from the file * * @throws IOException throws an IOException if we can't open the file */ private void readHeader() throws IOException { InputStream is = null; PositionalBufferedStream pbs = null; try { is = ParsingUtils.openInputStream(path); if (path.endsWith("gz")) { // TODO -- warning I don't think this can work, the buffered input stream screws up position is = new GZIPInputStream(new BufferedInputStream(is)); } pbs = new PositionalBufferedStream(is); final SOURCE source = codec.makeSourceFromStream(pbs); header = codec.readHeader(source); } catch (Exception e) { throw new TribbleException.MalformedFeatureFile("Unable to parse header with error: " + e.getMessage(), path, e); } finally { if (pbs != null) pbs.close(); else if (is != null) is.close(); } }
/** * read the header from the file * * @throws IOException throws an IOException if we can't open the file */ private void readHeader() throws IOException { InputStream is = null; PositionalBufferedStream pbs = null; try { is = ParsingUtils.openInputStream(path, wrapper); if (IOUtil.hasBlockCompressedExtension(new URI(URLEncoder.encode(path, "UTF-8")))) { // TODO: TEST/FIX THIS! https://github.com/samtools/htsjdk/issues/944 // TODO -- warning I don't think this can work, the buffered input stream screws up position is = new GZIPInputStream(new BufferedInputStream(is)); } pbs = new PositionalBufferedStream(is); final SOURCE source = codec.makeSourceFromStream(pbs); header = codec.readHeader(source); } catch (Exception e) { throw new TribbleException.MalformedFeatureFile("Unable to parse header with error: " + e.getMessage(), path, e); } finally { if (pbs != null) pbs.close(); else if (is != null) is.close(); } }
final LittleEndianInputStream dis = null; try { InputStream inputStream = ParsingUtils.openInputStream(indexFile); if (indexFile.endsWith(".gz")) { inputStream = new GZIPInputStream(inputStream);
htsjdk.tribble.util.ParsingUtils.openInputStream(path)))); } else { reader = ParsingUtils.openBufferedReader(path);
public Iterator<T> iterator() { return this; } }
/** * read the header * * @return a Object, representing the file header, if available * @throws IOException throws an IOException if we can't open the file */ private void readHeader() throws IOException { SOURCE source = null; try { source = codec.makeSourceFromStream(new PositionalBufferedStream(new BlockCompressedInputStream(ParsingUtils.openInputStream(path)))); header = codec.readHeader(source); } catch (Exception e) { throw new TribbleException.MalformedFeatureFile("Unable to parse header with error: " + e.getMessage(), path, e); } finally { if (source != null) { codec.close(source); } } }
@Test(dataProvider = "gzippedBedTestData") public void testReadActualHeader(final File gzippedBedFile, final int firstFeatureOffset) throws IOException { // Given an indexable SOURCE on a BED file, test that readActualHeader retains the correct offset // of the first feature, whether there is a header or not BEDCodec bedCodec = new BEDCodec(); try (final InputStream is = ParsingUtils.openInputStream(gzippedBedFile.getPath()); final BlockCompressedInputStream bcis = new BlockCompressedInputStream(is)) { AsciiLineReaderIterator it = (AsciiLineReaderIterator) bedCodec.makeIndexableSourceFromStream(bcis); Object header = bedCodec.readActualHeader(it); // BEDCodec doesn't model or return the BED header, even when there is one! Assert.assertNull(header); Assert.assertEquals(BlockCompressedFilePointerUtil.getBlockAddress(it.getPosition()), 0); Assert.assertEquals(BlockCompressedFilePointerUtil.getBlockOffset(it.getPosition()), firstFeatureOffset); } }