@Override public void close() throws IOException { SnappyOutputStream zos = (SnappyOutputStream) delegate; zos.flush(); zos.close(); }
snappyOut.close();
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 ); } }
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(); }
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 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); } }
baos.flush(); baos.close(); sos.close(); snappySize += baos.toByteArray().length;