@Override protected OutputStream createOutputStream(OutputStream parent) throws IOException { return new SnappyOutputStream(parent); }
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 ); } }
public static void compressFileSnappy(File src, File dst) throws IOException { if (!dst.getParentFile().exists()) dst.getParentFile().mkdirs(); FileOutputStream fos = new FileOutputStream(dst); FileInputStream fis = new FileInputStream(src); SnappyOutputStream os = new SnappyOutputStream(fos); IOUtils.copy(fis, os); os.flush(); os.close(); fis.close(); }
/** * Compress the input array data * * @param f * @throws IOException */ public void write(float[] f) throws IOException { write(f, 0, f.length); }
private byte[] done() throws IOException { compress.flush(); byte[] return_ = bos.toByteArray(); hasnext = false; IOUtils.closeQuietly(compress); IOUtils.closeQuietly(bos); IOUtils.closeQuietly(origin); return return_; }
/** * Compress the input array data * * @param f * @throws IOException */ public void write(double[] f) throws IOException { write(f, 0, f.length); }
/** * close the stream */ /* (non-Javadoc) * @see java.io.OutputStream#close() */ @Override public void close() throws IOException { if (closed) { return; } try { flush(); out.close(); } finally { closed = true; inputBufferAllocator.release(inputBuffer); outputBufferAllocator.release(outputBuffer); inputBuffer = null; outputBuffer = null; } } }
private static SnappyOutputStream getDelegate( OutputStream out ) throws IOException { SnappyOutputStream delegate; if ( out instanceof SnappyOutputStream ) { delegate = (SnappyOutputStream) out; } else { delegate = new SnappyOutputStream( out ); } return delegate; }
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 ); } }
/** * Compress the input array data * * @param f * @throws IOException */ public void write(int[] f) throws IOException { write(f, 0, f.length); }
public ChunkedStream(InputStream is, long chunkSize) throws IOException { this.origin = is; this.bos = new ByteArrayOutputStream(); this.compress = new SnappyOutputStream(bos); this.chunkSize = chunkSize; }
in = new BufferedInputStream(new FileInputStream(uncompressed)); out = new FileOutputStream(compressed); snappyOut = new SnappyOutputStream(out); break; snappyOut.write(buf, 0, read); snappyOut.close();
/** * Compress the input array data * * @param d * @throws IOException */ public void write(long[] d) throws IOException { write(d, 0, d.length); }
break; case COMPRESSION_FORMAT_SNAPPY: compressionOut = new SnappyOutputStream(bufferedOut); mimeTypeRef = "application/x-snappy"; break;
@Override public ByteBuffer toByteBuffer(String obj) { if (obj == null) { return null; } ByteArrayOutputStream out = new ByteArrayOutputStream(); SnappyOutputStream snappy; try { snappy = new SnappyOutputStream(out); snappy.write(StringUtils.getBytesUtf8(obj)); snappy.close(); return ByteBuffer.wrap(out.toByteArray()); } catch (IOException e) { throw new RuntimeException("Error compressing column data", e); } }
/** * Compress the input array data * * @param f * @throws IOException */ public void write(short[] f) throws IOException { write(f, 0, f.length); }
break; case COMPRESSION_FORMAT_SNAPPY: compressionOut = new SnappyOutputStream(bufferedOut); mimeTypeRef.set("application/x-snappy"); break;
public Compress(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 { SnappyOutputStream sos = new SnappyOutputStream(new FileOutputStream(out)); FileInputStream fis = new FileInputStream(in); int len; while ((len = fis.read(buffer)) > 0) { sos.write(buffer, 0, len); } sos.close(); fis.close(); } catch (IOException e) { logger.error(e); } long end = System.currentTimeMillis(); logger.info("compression done in " + df.format(end - begin) + " ms (" + new Date() + ")"); }
@Override public byte[] next() { try { byte data[] = new byte[BYTES_TO_READ]; int count; while ((count = origin.read(data, 0, data.length)) != -1) { compress.write(data, 0, count); if (bos.size() >= chunkSize) return returnSafe(); } // We don't have anything else to read hence set to false. return done(); } catch (IOException e) { throw new RuntimeException(e); } }