/** * @return If Defaults.BUFFER_SIZE > 0, wrap is in BufferedInputStream, else return is itself. */ public static InputStream maybeBufferInputStream(final InputStream is) { return maybeBufferInputStream(is, Defaults.BUFFER_SIZE); }
/** * @return If Defaults.BUFFER_SIZE > 0, wrap is in BufferedInputStream, else return is itself. */ public static InputStream maybeBufferInputStream(final InputStream is) { return maybeBufferInputStream(is, Defaults.BUFFER_SIZE); }
/** * @return If Defaults.BUFFER_SIZE > 0, wrap is in BufferedInputStream, else return is itself. */ public static InputStream maybeBufferInputStream(final InputStream is) { return maybeBufferInputStream(is, Defaults.BUFFER_SIZE); }
FileValueIterator(final File file) { this.file = file; try { is = new DataInputStream(IOUtil.maybeBufferInputStream(new FileInputStream(file))); next(); } catch (FileNotFoundException e) { throw new RuntimeIOException(file.getAbsolutePath(), e); } }
FileValueIterator(final Path file) { this.file = file; try { is = new DataInputStream(IOUtil.maybeBufferInputStream(Files.newInputStream(file))); next(); } catch (IOException e) { throw new RuntimeIOException(file.toUri().toString(), e); } }
FileValueIterator(final Path file) { this.file = file; try { is = new DataInputStream(IOUtil.maybeBufferInputStream(Files.newInputStream(file))); next(); } catch (IOException e) { throw new RuntimeIOException(file.toUri().toString(), e); } }
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); } }
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); } }
InputStream open(final File file, final boolean seekable, final boolean isGzip, final boolean isBgzf) { final String filePath = file.getAbsolutePath(); try { // Open up a buffered stream to read from the file and optionally wrap it in a gzip stream if necessary if (isBgzf) { // Only BlockCompressedInputStreams can seek, and only if they are fed a SeekableStream. return new BlockCompressedInputStream(IOUtil.maybeBufferedSeekableStream(file)); } else if (isGzip) { if (seekable) { throw new IllegalArgumentException( String.format("Cannot create a seekable reader for gzip bcl: %s.", filePath) ); } return (IOUtil.maybeBufferInputStream(new GZIPInputStream(new FileInputStream(file), Defaults.BUFFER_SIZE / 2), Defaults.BUFFER_SIZE / 2)); } else { if (seekable) { throw new IllegalArgumentException( String.format("Cannot create a seekable reader for provided bcl: %s.", filePath) ); } return IOUtil.maybeBufferInputStream(new FileInputStream(file)); } } catch (final FileNotFoundException fnfe) { throw new PicardException("File not found: (" + filePath + ")", fnfe); } catch (final IOException ioe) { throw new PicardException("Error reading file: (" + filePath + ")", ioe); } }
/** * Constructs BinaryCodec from a file and set its mode to writing or not * * @param path file to be written to or read from * @param writing whether the file is being written to */ public BinaryCodec(final Path path, final boolean writing) { this(); try { this.isWriting = writing; if (this.isWriting) { this.outputStream = IOUtil.maybeBufferOutputStream(Files.newOutputStream(path)); this.outputFileName = path.getFileName().toString(); } else { this.inputStream = IOUtil.maybeBufferInputStream(Files.newInputStream(path)); this.inputFileName = path.getFileName().toString(); } } catch (FileNotFoundException e) { throw new RuntimeIOException("File not found: " + path, e); } catch (IOException e) { throw new RuntimeIOException("Error opening: " + path, e); } }
/** * Constructs BinaryCodec from a file and set its mode to writing or not * * @param path file to be written to or read from * @param writing whether the file is being written to */ public BinaryCodec(final Path path, final boolean writing) { this(); try { this.isWriting = writing; if (this.isWriting) { this.outputStream = IOUtil.maybeBufferOutputStream(Files.newOutputStream(path)); this.outputFileName = path.getFileName().toString(); } else { this.inputStream = IOUtil.maybeBufferInputStream(Files.newInputStream(path)); this.inputFileName = path.getFileName().toString(); } } catch (FileNotFoundException e) { throw new RuntimeIOException("File not found: " + path, e); } catch (IOException e) { throw new RuntimeIOException("Error opening: " + path, e); } }
TileIndex(final File tileIndexFile) { try { this.tileIndexFile = tileIndexFile; final InputStream is = IOUtil.maybeBufferInputStream(new FileInputStream(tileIndexFile)); final ByteBuffer buf = ByteBuffer.allocate(8); buf.order(ByteOrder.LITTLE_ENDIAN); int absoluteRecordIndex = 0; int numTiles = 0; while (readTileIndexRecord(buf.array(), buf.capacity(), is)) { buf.rewind(); buf.limit(buf.capacity()); final int tile = buf.getInt(); // Note: not handling unsigned ints > 2^31, but could if one of these exceptions is thrown. if (tile < 0) throw new PicardException("Tile number too large in " + tileIndexFile.getAbsolutePath()); final int numClusters = buf.getInt(); if (numClusters < 0) throw new PicardException("Cluster size too large in " + tileIndexFile.getAbsolutePath()); tiles.add(new TileIndexRecord(tile, numClusters, absoluteRecordIndex, numTiles++)); absoluteRecordIndex += numClusters; } CloserUtil.close(is); } catch (final IOException e) { throw new PicardException("Problem reading " + tileIndexFile.getAbsolutePath(), e); } }
InputStream open(final File file, final boolean seekable, final boolean isGzip, final boolean isBgzf) { final String filePath = file.getAbsolutePath(); try { // Open up a buffered stream to read from the file and optionally wrap it in a gzip stream if necessary if (isBgzf) { // Only BlockCompressedInputStreams can seek, and only if they are fed a SeekableStream. return new BlockCompressedInputStream(IOUtil.maybeBufferedSeekableStream(file)); } else if (isGzip) { if (seekable) { throw new IllegalArgumentException( String.format("Cannot create a seekable reader for gzip bcl: %s.", filePath) ); } return (IOUtil.maybeBufferInputStream(new GZIPInputStream(new FileInputStream(file), Defaults.BUFFER_SIZE / 2), Defaults.BUFFER_SIZE / 2)); } else { if (seekable) { throw new IllegalArgumentException( String.format("Cannot create a seekable reader for provided bcl: %s.", filePath) ); } return IOUtil.maybeBufferInputStream(new FileInputStream(file)); } } catch (final FileNotFoundException fnfe) { throw new PicardException("File not found: (" + filePath + ")", fnfe); } catch (final IOException ioe) { throw new PicardException("Error reading file: (" + filePath + ")", ioe); } }
TileIndex(final File tileIndexFile) { try { this.tileIndexFile = tileIndexFile; final InputStream is = IOUtil.maybeBufferInputStream(new FileInputStream(tileIndexFile)); final ByteBuffer buf = ByteBuffer.allocate(8); buf.order(ByteOrder.LITTLE_ENDIAN); int absoluteRecordIndex = 0; int numTiles = 0; while (readTileIndexRecord(buf.array(), buf.capacity(), is)) { buf.rewind(); buf.limit(buf.capacity()); final int tile = buf.getInt(); // Note: not handling unsigned ints > 2^31, but could if one of these exceptions is thrown. if (tile < 0) throw new PicardException("Tile number too large in " + tileIndexFile.getAbsolutePath()); final int numClusters = buf.getInt(); if (numClusters < 0) throw new PicardException("Cluster size too large in " + tileIndexFile.getAbsolutePath()); tiles.add(new TileIndexRecord(tile, numClusters, absoluteRecordIndex, numTiles++)); absoluteRecordIndex += numClusters; } CloserUtil.close(is); } catch (final IOException e) { throw new PicardException("Problem reading " + tileIndexFile.getAbsolutePath(), e); } }
/** * Wrap the given InputStream in a SnappyInputStream if available. * @return If Snappy is available, a SnappyInputStream wrapping inputStream. * If not, and bufferSize > 0, a BufferedInputStream. * Otherwise inputStream is returned. */ public InputStream wrapTempInputStream(final InputStream inputStream, final int bufferSize) { InputStream is = IOUtil.maybeBufferInputStream(inputStream, bufferSize); if (getSnappyLoader().SnappyAvailable) { try { return getSnappyLoader().wrapInputStream(is); } catch (Exception e) { throw new SAMException("Error creating SnappyInputStream", e); } } else { return is; } }
/** * Wrap the given InputStream in a SnappyInputStream if available. * @return If Snappy is available, a SnappyInputStream wrapping inputStream. * If not, and bufferSize > 0, a BufferedInputStream. * Otherwise inputStream is returned. */ public InputStream wrapTempInputStream(final InputStream inputStream, final int bufferSize) { InputStream is = IOUtil.maybeBufferInputStream(inputStream, bufferSize); if (getSnappyLoader().isSnappyAvailable()) { try { return getSnappyLoader().wrapInputStream(is); } catch (Exception e) { throw new SAMException("Error creating SnappyInputStream", e); } } else { return is; } }
/** * Wrap the given InputStream in a SnappyInputStream if available. * @return If Snappy is available, a SnappyInputStream wrapping inputStream. * If not, and bufferSize > 0, a BufferedInputStream. * Otherwise inputStream is returned. */ public InputStream wrapTempInputStream(final InputStream inputStream, final int bufferSize) { InputStream is = IOUtil.maybeBufferInputStream(inputStream, bufferSize); if (getSnappyLoader().isSnappyAvailable()) { try { return getSnappyLoader().wrapInputStream(is); } catch (Exception e) { throw new SAMException("Error creating SnappyInputStream", e); } } else { return is; } }
IOUtil.maybeBufferInputStream( data.asUnbufferedInputStream(), Math.max(Defaults.BUFFER_SIZE, BlockCompressedStreamConstants.MAX_COMPRESSED_BLOCK_SIZE)
} else { InputStream bufferedStream = IOUtil.maybeBufferInputStream( data.asUnbufferedInputStream(), Math.max(Defaults.BUFFER_SIZE, BlockCompressedStreamConstants.MAX_COMPRESSED_BLOCK_SIZE)
} else { InputStream bufferedStream = IOUtil.maybeBufferInputStream( data.asUnbufferedInputStream(), Math.max(Defaults.BUFFER_SIZE, BlockCompressedStreamConstants.MAX_COMPRESSED_BLOCK_SIZE)