/** * Compress the input char array * * @param input * @return the compressed data */ public static byte[] compress(char[] input) throws IOException { return rawCompress(input, input.length * 2); // char uses 2 bytes }
/** * Compress the input float array * * @param input * @return the compressed data */ public static byte[] compress(float[] input) throws IOException { return rawCompress(input, input.length * 4); // float uses 4 bytes }
/** * Compress the input double array * * @param input * @return the compressed data */ public static byte[] compress(double[] input) throws IOException { return rawCompress(input, input.length * 8); // double uses 8 bytes }
/** * Compress the input int array * * @param input * @return the compressed data */ public static byte[] compress(int[] input) throws IOException { return rawCompress(input, input.length * 4); // int uses 4 bytes }
/** * Compress the input short array * * @param input * @return the compressed data */ public static byte[] compress(short[] input) throws IOException { return rawCompress(input, input.length * 2); // short uses 2 bytes }
/** * Compress the input long array * * @param input * @return the compressed data */ public static byte[] compress(long[] input) throws IOException { return rawCompress(input, input.length * 8); // long uses 8 bytes }
/** * High-level API for compressing the input byte array. This method performs * array copy to generate the result. If you want to reduce the memory copy * cost, use {@link #compress(byte[], int, int, byte[], int)} or * {@link #compress(ByteBuffer, ByteBuffer)}. * * @param input the input data * @return the compressed byte array * @throws IOException */ public static byte[] compress(byte[] input) throws IOException { return rawCompress(input, input.length); }
/** * Compress the input buffer content in [inputOffset, * ...inputOffset+inputLength) then output to the specified output buffer. * * @param input * @param inputOffset * @param inputLength * @param output * @param outputOffset * @return byte size of the compressed data * @throws IOException when failed to access the input/output buffer */ public static int compress(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset) throws IOException { return rawCompress(input, inputOffset, inputLength, output, outputOffset); }
@Override protected void encode(ChannelHandlerContext ctx, FrameCodec.Frame msg, List<Object> out) throws Exception { // stay consistent with decoding party if (msg.size > MAX_SIZE) { logger.info("{}: outgoing frame size exceeds the limit ({} bytes), disconnect", channel, msg.size); channel.disconnect(ReasonCode.USELESS_PEER); return; } byte[] in = new byte[msg.size]; msg.payload.read(in); byte[] compressed = Snappy.rawCompress(in, in.length); out.add(new FrameCodec.Frame((int) msg.type, compressed)); }
public int compress(byte[] input, int inputOffset, int inputLength, ICompressor.WrappedArray output, int outputOffset) throws IOException { return Snappy.rawCompress(input, inputOffset, inputLength, output.buffer, outputOffset); }
@Override public byte[] compressByte(byte[] unCompInput) { try { return Snappy.rawCompress(unCompInput, unCompInput.length); } catch (IOException e) { LOGGER.error(e.getMessage(), e); throw new RuntimeException(e); } }
@Override public byte[] compressByte(byte[] unCompInput, int byteSize) { try { return Snappy.rawCompress(unCompInput, byteSize); } catch (IOException e) { LOGGER.error(e.getMessage(), e); throw new RuntimeException(e); } }
public static void initSnappy() { byte[] compressed = null; long startTime = System.currentTimeMillis(); try { String testMsg = "test"; compressed = Snappy.rawCompress(testMsg.getBytes(), testMsg.length()); } catch (UnsupportedEncodingException e) { LOGGER.error( "failed to compress using Snappy - " + e.toString()); } catch (IOException e) { LOGGER.error( "failed to compress using Snappy - " + e.toString()); } byte[] uncompressed = new byte[100]; int len = 0; try { len = Snappy.rawUncompress(compressed, 0, compressed.length, uncompressed, 0); } catch (Throwable t) { LOGGER.error( "failed to uncompress using Snappy - " + t.toString()); } }
compressed = Snappy.rawCompress(testMsg.getBytes(), testMsg.length());
epromise.setRawBytes(msglen); byte[] compressed = Snappy.rawCompress(chbuf.readBytes(msglen).array(), msglen);