@Override protected InputStream createInputStream(InputStream parent) throws IOException { return new SnappyInputStream(parent); }
try { in = new BufferedInputStream(new FileInputStream(compressed)); snappyIn = new SnappyInputStream(in); out = new FileOutputStream(decompressed); int read = snappyIn.read(buf); if (read == -1) { break; snappyIn.close();
/** * Reads the next byte of uncompressed data from the input stream. The value * byte is returned as an int in the range 0 to 255. If no byte is available * because the end of the stream has been reached, the value -1 is returned. * This method blocks until input data is available, the end of the stream * is detected, or an exception is thrown. */ /* (non-Javadoc) * @see java.io.InputStream#read() */ @Override public int read() throws IOException { if (uncompressedCursor < uncompressedLimit) { return uncompressed[uncompressedCursor++] & 0xFF; } else { if (hasNextChunk()) { return read(); } else { return -1; } } }
private void decompress(InputStream input, OutputStream output) throws IOException { byte data[] = new byte[BUFFER]; try (BufferedOutputStream dest1 = new BufferedOutputStream(output, BUFFER); SnappyInputStream is = new SnappyInputStream(new BufferedInputStream(input))) { int c; while ((c = is.read(data, 0, BUFFER)) != -1) { dest1.write(data, 0, c); } } } }
/** * Read int array from the stream * * @param d * @return the total number of bytes read into the buffer, or -1 if there is * no more data because the end of the stream has been reached. * @throws IOException */ public int read(int[] d) throws IOException { return read(d, 0, d.length); }
@Override public void close() throws IOException { ( (SnappyInputStream) delegate ).close(); }
final ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (final SnappyInputStream sis = new SnappyInputStream(new ByteArrayInputStream(flowFile.toByteArray())); final OutputStream out = baos) { final byte[] buffer = new byte[8192]; int len; while ((len = sis.read(buffer)) > 0) { out.write(buffer, 0, len);
/** * Read float array from the stream * * @param d * @return the total number of bytes read into the buffer, or -1 if there is * no more data because the end of the stream has been reached. * @throws IOException */ public int read(float[] d) throws IOException { return read(d, 0, d.length); }
protected static SnappyInputStream getDelegate( InputStream in ) throws IOException { SnappyInputStream delegate = null; if ( in instanceof SnappyInputStream ) { delegate = (SnappyInputStream) in; } else { delegate = new SnappyInputStream( in ); } return delegate; }
public Decompress(File in, File out) { long begin = System.currentTimeMillis(); logger.info("decompressing" + new Date() + "..."); logger.info("in:\t" + in + " (" + df.format(in.length()) + ")"); logger.info("out:\t" + out); byte[] buffer = new byte[1024]; try { SnappyInputStream sis = new SnappyInputStream(new FileInputStream(in)); FileOutputStream fos = new FileOutputStream(out); int len; while ((len = sis.read(buffer)) > 0) { fos.write(buffer, 0, len); } sis.close(); fos.close(); } catch (IOException e) { logger.error(e); } long end = System.currentTimeMillis(); logger.info("decompression done in " + df.format(end - begin) + " ms (" + new Date() + ")"); }
@Override public void decompress(InputStream source, OutputStream destination) throws IOException { SnappyInputStream compressedInputStream = null; BufferedOutputStream output = null; try { compressedInputStream = new SnappyInputStream( new BufferedInputStream(source)); output = new BufferedOutputStream(destination, DEFAULT_BUFFER_SIZE); int bytesRead; byte[] data = new byte[DEFAULT_BUFFER_SIZE]; while ((bytesRead = compressedInputStream.read(data, 0, DEFAULT_BUFFER_SIZE)) != -1) { output.write(data, 0, bytesRead); } } finally { IOUtils.closeQuietly(compressedInputStream); IOUtils.closeQuietly(output); } } }
/** * Read long array from the stream * * @param d * @return the total number of bytes read into the buffer, or -1 if there is * no more data because the end of the stream has been reached. * @throws IOException */ public int read(long[] d) throws IOException { return read(d, 0, d.length); }
@Override InputStream getInputStream(final InputStream source) throws IOException { return new SnappyInputStream(source); } }
try { ByteBuffer dup = byteBuffer.duplicate(); snappy = new SnappyInputStream( new ByteArrayInputStream(dup.array(), 0, dup.limit())); value = snappy.read(); if (value != -1) { baos.write(value); snappy.close(); baos.close(); return StringUtils.newStringUtf8(baos.toByteArray()); if (snappy != null) { try { snappy.close(); } catch (IOException e) {
/** * Read double array from the stream * * @param d * @return the total number of bytes read into the buffer, or -1 if there is * no more data because the end of the stream has been reached. * @throws IOException */ public int read(double[] d) throws IOException { return read(d, 0, d.length); }
private SnappyInputStream createSnappyInputStream() throws IOException { // Create an in-memory ZIP output stream for use by the input stream (to avoid exceptions) ByteArrayOutputStream baos = new ByteArrayOutputStream(); SnappyOutputStream sos = new SnappyOutputStream( baos ); byte[] testBytes = "Test".getBytes(); sos.write( testBytes ); ByteArrayInputStream in = new ByteArrayInputStream( baos.toByteArray() ); sos.close(); return new SnappyInputStream( in ); } }
try { in = new BufferedInputStream(new FileInputStream(compressed)); snappyIn = new SnappyInputStream(in); out = new FileOutputStream(decompressed); int read = snappyIn.read(buf); if (read == -1) { break; snappyIn.close();
/** * Read short array from the stream * * @param d * @return the total number of bytes read into the buffer, or -1 if there is * no more data because the end of the stream has been reached. * @throws IOException */ public int read(short[] d) throws IOException { return read(d, 0, d.length); }
private SnappyInputStream createSnappyInputStream() throws IOException { // Create an in-memory ZIP output stream for use by the input stream (to avoid exceptions) ByteArrayOutputStream baos = new ByteArrayOutputStream(); SnappyOutputStream sos = new SnappyOutputStream( baos ); byte[] testBytes = "Test".getBytes(); sos.write( testBytes ); ByteArrayInputStream in = new ByteArrayInputStream( baos.toByteArray() ); sos.close(); return new SnappyInputStream( in ); } }
@Override public int read() throws IOException { return ( (SnappyInputStream) delegate ).read(); }