List of usage examples for java.util.zip Deflater getTotalOut
public int getTotalOut()
From source file:com.nary.Debug.java
public static void saveClass(OutputStream _out, Object _class, boolean _compress) throws IOException { if (_compress) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream OOS = new ObjectOutputStream(bos); OOS.writeObject(_class); byte[] dataArray = bos.toByteArray(); byte[] test = new byte[dataArray.length]; // this is where the byte array gets compressed to Deflater def = new Deflater(Deflater.BEST_COMPRESSION); def.setInput(dataArray);/* w ww . jav a 2s . c o m*/ def.finish(); def.deflate(test); _out.write(test, 0, def.getTotalOut()); } else { ObjectOutputStream OS = new ObjectOutputStream(_out); OS.writeObject(_class); } }
From source file:info.fetter.logstashforwarder.protocol.LumberjackClient.java
public int sendCompressedFrame(List<Map<String, byte[]>> keyValuesList) throws IOException { output.writeByte(PROTOCOL_VERSION);/*from w w w . j a v a 2 s . co m*/ output.writeByte(FRAME_COMPRESSED); ByteArrayOutputStream uncompressedBytes = new ByteArrayOutputStream(); DataOutputStream uncompressedOutput = new DataOutputStream(uncompressedBytes); for (Map<String, byte[]> keyValues : keyValuesList) { logger.trace("Adding data frame"); sendDataFrame(uncompressedOutput, keyValues); } uncompressedOutput.close(); Deflater compressor = new Deflater(); byte[] uncompressedData = uncompressedBytes.toByteArray(); if (logger.isDebugEnabled()) { logger.debug("Deflating data : " + uncompressedData.length + " bytes"); } if (logger.isTraceEnabled()) { HexDump.dump(uncompressedData, 0, System.out, 0); } compressor.setInput(uncompressedData); compressor.finish(); ByteArrayOutputStream compressedBytes = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; while (!compressor.finished()) { int count = compressor.deflate(buffer); compressedBytes.write(buffer, 0, count); } compressedBytes.close(); byte[] compressedData = compressedBytes.toByteArray(); if (logger.isDebugEnabled()) { logger.debug("Deflated data : " + compressor.getTotalOut() + " bytes"); } if (logger.isTraceEnabled()) { HexDump.dump(compressedData, 0, System.out, 0); } output.writeInt(compressor.getTotalOut()); output.write(compressedData); output.flush(); if (logger.isDebugEnabled()) { logger.debug("Sending compressed frame : " + keyValuesList.size() + " frames"); } return 6 + compressor.getTotalOut(); }
From source file:se.kth.infosys.lumberjack.protocol.LumberjackClient.java
public int sendCompressedFrame(List<Map<String, byte[]>> keyValuesList) throws IOException { output.writeByte(PROTOCOL_VERSION);//from w w w . j av a2 s . c om output.writeByte(FRAME_COMPRESSED); ByteArrayOutputStream uncompressedBytes = new ByteArrayOutputStream(); DataOutputStream uncompressedOutput = new DataOutputStream(uncompressedBytes); for (Map<String, byte[]> keyValues : keyValuesList) { logger.trace("Adding data frame"); sendDataFrame(uncompressedOutput, keyValues); } uncompressedOutput.close(); Deflater compressor = new Deflater(); byte[] uncompressedData = uncompressedBytes.toByteArray(); logger.trace("Deflating data: {} bytes", uncompressedData.length); if (logger.isTraceEnabled()) { HexDump.dump(uncompressedData, 0, System.out, 0); } compressor.setInput(uncompressedData); compressor.finish(); ByteArrayOutputStream compressedBytes = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; while (!compressor.finished()) { int count = compressor.deflate(buffer); compressedBytes.write(buffer, 0, count); } compressedBytes.close(); byte[] compressedData = compressedBytes.toByteArray(); logger.trace("Deflated data: {} bytes", compressor.getTotalOut()); if (logger.isTraceEnabled()) { HexDump.dump(compressedData, 0, System.out, 0); } output.writeInt(compressor.getTotalOut()); output.write(compressedData); output.flush(); logger.trace("Sending compressed frame: {} frames", keyValuesList.size()); return 6 + compressor.getTotalOut(); }