/** * Create packet with given header. * * @param header Packet header */ public Packet(Header header) { if (log.isTraceEnabled()) { log.trace("Header: {}", header); } this.header = header; data = IoBuffer.allocate(header.getSize()).setAutoExpand(true); }
private byte[] read(byte[] data, int pos) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayInputStream bis = new ByteArrayInputStream(data); Header header = new Header(); header.read(data, pos); bis.skip(pos + header.getSize()); InflaterInputStream inflater = new InflaterInputStream(bis); byte[] chunk = new byte[4096]; int count; while ((count = inflater.read(chunk)) >= 0) { out.write(chunk, 0, count); } inflater.close(); return out.toByteArray(); }
@Override public byte[] getData() { try { byte[] rawdata = getRawData(); ByteArrayOutputStream out = new ByteArrayOutputStream(); InputStream is = new ByteArrayInputStream(rawdata); Header header = new Header(); header.read(rawdata, CHECKSUM_SIZE); is.skip(header.getSize() + CHECKSUM_SIZE); InflaterInputStream inflater = new InflaterInputStream(is); byte[] chunk = new byte[4096]; int count; while ((count = inflater.read(chunk)) >= 0) { out.write(chunk, 0, count); } inflater.close(); return out.toByteArray(); } catch (IOException e) { throw new HSLFException(e); } }
/** * Create packet with given header * * @param header Packet header */ public Packet(Header header) { this.header = header; data = ByteBuffer.allocate(header.getSize() + (header.getTimer() == 0xffffff ? 4 : 0)); }