/** * Convenient ctor that opens the file, wraps with with BGZF reader, and closes after reading index. */ public TabixIndex(final File tabixFile) throws IOException { this(new BlockCompressedInputStream(tabixFile), true); }
/** * Convenient ctor that opens the file, wraps with with BGZF reader, and closes after reading index. */ public TabixIndex(final File tabixFile) throws IOException { this(new BlockCompressedInputStream(tabixFile), true); }
/** * Convenient ctor that opens the path, wraps with with BGZF reader, and closes after reading index. */ public TabixIndex(final Path tabixPath) throws IOException { this(new BlockCompressedInputStream(Files.newInputStream(tabixPath)), true); }
/** * Convenient ctor that opens the path, wraps with with BGZF reader, and closes after reading index. */ public TabixIndex(final Path tabixPath) throws IOException { this(new BlockCompressedInputStream(Files.newInputStream(tabixPath)), true); }
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; } }
public TabixReader(String fileName, boolean debug) throws IOException { this.fileName = fileName; this.debug = debug; fileInputStream = new BlockCompressedInputStream(new File(fileName)); readIndex(); }
public final static boolean canDecodeFile(final String potentialInput, final String MAGIC_HEADER_LINE) { try { return isVCFStream(new FileInputStream(potentialInput), MAGIC_HEADER_LINE) || isVCFStream(new GZIPInputStream(new FileInputStream(potentialInput)), MAGIC_HEADER_LINE) || isVCFStream(new BlockCompressedInputStream(new FileInputStream(potentialInput)), MAGIC_HEADER_LINE); } catch ( FileNotFoundException e ) { return false; } catch ( IOException e ) { return false; } }
public BGZFSplitCompressionInputStream(InputStream in, long start, long end) throws IOException { super(in, start, end); bufferedIn = new BufferedInputStream(super.in); this.startingPos = super.getPos(); input = new BlockCompressedInputStream(bufferedIn); this.updatePos(false); }
public BGZFSplitCompressionInputStream(InputStream in, long start, long end) throws IOException { super(in, start, end); bufferedIn = new BufferedInputStream(super.in); this.startingPos = super.getPos(); input = new BlockCompressedInputStream(bufferedIn); this.updatePos(false); }
CompressedIndexFileBuffer(File file) { try { mCompressedStream = new BlockCompressedInputStream(file); binaryCodec = new BinaryCodec(mCompressedStream); } catch (IOException ioe) { throw(new RuntimeIOException("Construction error of CSI compressed stream: " + ioe)); } }
public int execute() throws IOException { final byte[] uncompressedBuffer = new byte[65536]; final BlockCompressedInputStream gunzipper = new BlockCompressedInputStream(blockFile); gunzipper.setCheckCrcs(true); gunzipper.read(uncompressedBuffer); gunzipper.close(); System.out.printf("SUCCESS!%n"); return 0; }
public static long getNumberOfClusters(final File file) { InputStream stream = null; try { if (isBlockGzipped(file)) stream = new BlockCompressedInputStream(IOUtil.maybeBufferedSeekableStream(file)); else if (isGzipped(file)) stream = new GZIPInputStream(IOUtil.maybeBufferInputStream(new FileInputStream(file))); else stream = IOUtil.maybeBufferInputStream(new FileInputStream(file)); return getNumberOfClusters(file.getAbsolutePath(), stream); } catch (final IOException ioe) { throw new PicardException("Could not open file " + file.getAbsolutePath() + " to get its cluster count: " + ioe.getMessage(), ioe); } finally { CloserUtil.close(stream); } }
@DataProvider(name = "fromStream") public Object[][] getFromStreamData() { return new Object[][]{ { new BlockCompressedInputStream(new ByteArrayInputStream(new byte[10])), BlockCompressedAsciiLineReader.class }, { new PositionalBufferedStream(new ByteArrayInputStream(new byte[10])), AsciiLineReader.class }, { new ByteArrayInputStream(new byte[10]), AsciiLineReader.class } }; }
@Test public void testTruncatedStream() throws Exception { byte[] compressed = Files.readAllBytes(BLOCK_COMPRESSED.toPath()); byte[] truncated = Arrays.copyOf(compressed, compressed.length * 2 / 3); try (BlockCompressedInputStream stream = new BlockCompressedInputStream(new ByteArrayInputStream(truncated))) { Assert.expectThrows(FileTruncatedException.class, () -> InputStreamUtils.readFully(stream)); } }
@Test public void testWriteHeader() throws IOException { final SAMRecordSetBuilder builder = new SAMRecordSetBuilder(true, SAMFileHeader.SortOrder.coordinate); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); BAMFileWriter.writeHeader(baos, builder.getHeader()); baos.close(); try (BinaryCodec binaryCodec = new BinaryCodec(new DataInputStream(new BlockCompressedInputStream(new ByteArrayInputStream(baos.toByteArray()))))) { SAMFileHeader samFileHeader = BAMFileReader.readHeader(binaryCodec, ValidationStringency.STRICT, null); Assert.assertEquals(samFileHeader, builder.getHeader()); } } }
@Test public void decompression_should_cross_block_boundries() throws Exception { byte[] uncompressed = Files.readAllBytes(BLOCK_UNCOMPRESSED.toPath()); try (BlockCompressedInputStream stream = new BlockCompressedInputStream(new FileInputStream(BLOCK_COMPRESSED))) { byte[] decompressed = new byte[uncompressed.length]; stream.read(decompressed); Assert.assertEquals(decompressed, uncompressed); Assert.assertTrue(stream.endOfBlock()); Assert.assertEquals(stream.read(), -1); } } @Test
@Test public void testFilePointer() throws Exception { BlockCompressedInputStream sync = new BlockCompressedInputStream(BAM_FILE); Assert.assertEquals(sync.getFilePointer(), 0); sync.close(); } }
@Override public Iterator<T> iterator() { return this; } }
@Override public Iterator<T> iterator() { return this; } }