/** * Compress the input array data * * @param f * @throws IOException */ public void write(float[] f) throws IOException { write(f, 0, f.length); }
/** * Compress the input array data * * @param f * @throws IOException */ public void write(double[] f) throws IOException { write(f, 0, f.length); }
/** * Compress the input array data * * @param f * @throws IOException */ public void write(int[] f) throws IOException { write(f, 0, f.length); }
/** * Compress the input array data * * @param d * @throws IOException */ public void write(long[] d) throws IOException { write(d, 0, d.length); }
/** * Compress the input array data * * @param f * @throws IOException */ public void write(short[] f) throws IOException { write(f, 0, f.length); }
@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); } }
break; snappyOut.write(buf, 0, read);
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 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); } }
break; snappyOut.write(buf, 0, read);
sos.write(raw); baos.flush(); baos.close();