protected byte[] decompress(ByteSequence dataSequence) throws IOException { Inflater inflater = new Inflater(); ByteArrayOutputStream decompressed = new ByteArrayOutputStream(); try { length = ByteSequenceData.readIntBig(dataSequence); dataSequence.offset = 0; byte[] data = Arrays.copyOfRange(dataSequence.getData(), 4, dataSequence.getLength()); inflater.setInput(data); byte[] buffer = new byte[length]; int count = inflater.inflate(buffer); decompressed.write(buffer, 0, count); return decompressed.toByteArray(); } catch (Exception e) { throw new IOException(e); } finally { inflater.end(); decompressed.close(); } }
/** * Creates a <code>StoreByteArrayInputStream</code>. * * @param sequence the input buffer. */ public DataByteArrayInputStream(ByteSequence sequence) { this.buf = sequence.getData(); this.offset = sequence.getOffset(); this.pos = this.offset; this.length = sequence.length; this.work = new byte[8]; }
private void trace(DataStructure command) { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(maxTraceDatagramSize); DataOutputStream out = new DataOutputStream(baos); wireFormat.marshal(brokerId, out); wireFormat.marshal(command, out); out.close(); ByteSequence sequence = baos.toByteSequence(); DatagramPacket datagram = new DatagramPacket(sequence.getData(), sequence.getOffset(), sequence.getLength(), address); socket.send(datagram); } catch (Throwable e) { LOG.debug("Failed to trace: {}", command, e); } }