@SuppressWarnings("unchecked") public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException { try { GZIPCompressedMessage result = new GZIPCompressedMessage(); byte[] byteArray = new byte[data.remaining()]; data.get(byteArray); GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(byteArray)); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] tmp = new byte[9012]; int read; while (in.available() > 0 && ((read = in.read(tmp)) > 0)) { out.write(tmp, 0, read); } result.setMessage((Message)Serializer.readClassAndObject(ByteBuffer.wrap(out.toByteArray()))); return (T)result; } catch (Exception e) { e.printStackTrace(); throw new IOException(e.toString()); } }
final byte[] tmp = new byte[TEMP_BUFFER_SIZE]; while( gzReader.available() != 0 )
final byte[] tmp = new byte[TEMP_BUFFER_SIZE]; while( gzReader.available() != 0 )
/** * (non-Javadoc) * * @see java.io.InputStream#available() */ @Override public int available() throws IOException { return zippedInputStream.available(); }
private boolean isEof() throws IOException { return ((GZIPInputStream)io).available() != 1; }
public static byte[] decompress(byte[] contentBytes){ ByteArrayOutputStream out = new ByteArrayOutputStream(); try{ GZIPInputStream stream = new GZIPInputStream(new ByteArrayInputStream(contentBytes)); while (stream.available()>0) { out.write(stream.read()); } } catch(IOException e){ throw new RuntimeException(e); } return out.toByteArray(); } }
public static byte[] uncompress(byte[] src) throws IOException { byte[] buffer = new byte[1024]; // 1k buffer ByteArrayInputStream bin = new ByteArrayInputStream(src); GZIPInputStream gzipIn = new GZIPInputStream(bin); ByteArrayOutputStream bout = new ByteArrayOutputStream(); while (gzipIn.available() > 0) { int len = gzipIn.read(buffer); if (len <= 0) break; if (len < buffer.length) { bout.write(buffer, 0, len); } else { bout.write(buffer); } } bout.flush(); return bout.toByteArray(); }
public static byte[] uncompress(byte[] src) throws IOException{ byte[] buffer = new byte[1024]; // 1k buffer ByteArrayInputStream bin = new ByteArrayInputStream(src); GZIPInputStream gzipIn = new GZIPInputStream(bin); ByteArrayOutputStream bout = new ByteArrayOutputStream(); while(gzipIn.available()>0){ int len = gzipIn.read(buffer); if (len<=0) break; if (len<buffer.length){ bout.write(buffer, 0, len); } else{ bout.write(buffer); } } bout.flush(); return bout.toByteArray(); }
public static byte[] uncompress(byte[] src) throws IOException { byte[] buffer = new byte[1024]; // 1k buffer ByteArrayInputStream bin = new ByteArrayInputStream(src); GZIPInputStream gzipIn = new GZIPInputStream(bin); ByteArrayOutputStream bout = new ByteArrayOutputStream(); while (gzipIn.available() > 0) { int len = gzipIn.read(buffer); if (len <= 0) break; if (len < buffer.length) { bout.write(buffer, 0, len); } else { bout.write(buffer); } } bout.flush(); return bout.toByteArray(); }
/** * Deflate a gzip byte array. * * @param inputBytes a gzip compressed byte array * @return a deflated byte array * @throws IOException error in gzip input stream */ public static byte[] deflateGzip(byte[] inputBytes) throws IOException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); try (GZIPInputStream gzipInputStream = new GZIPInputStream( new ByteArrayInputStream(inputBytes))) { byte[] buffer = new byte[BYTE_BUFFER_CHUNK_SIZE]; while (gzipInputStream.available() == 1) { int size = gzipInputStream.read(buffer); if (size == -1) { break; } byteArrayOutputStream.write(buffer, 0, size); } return byteArrayOutputStream.toByteArray(); } }
/** * Deflate a gzip byte array. * @param inputBytes a gzip compressed byte array * @return a deflated byte array * @throws IOException error in gzip input stream */ public static byte[] deflateGzip(byte[] inputBytes) throws IOException { // Start the byte input stream ByteArrayInputStream byteInputStream = new ByteArrayInputStream(inputBytes); GZIPInputStream gzipInputStream; ByteArrayOutputStream byteArrayOutputStream = null; try { gzipInputStream = new GZIPInputStream(byteInputStream); byteArrayOutputStream = new ByteArrayOutputStream(); // Make a buffer byte[] buffer = new byte[BYTE_BUFFER_CHUNK_SIZE]; while (gzipInputStream.available() == 1) { int size = gzipInputStream.read(buffer); if(size==-1){ break; } byteArrayOutputStream.write(buffer, 0, size); } } finally { if (byteArrayOutputStream != null) { byteArrayOutputStream.close(); } } return byteArrayOutputStream.toByteArray(); }
public PacketMEInventoryUpdate(final ByteBuf stream) throws IOException { data = null; compressFrame = null; list = new LinkedList<IAEItemStack>(); ref = stream.readByte(); final GZIPInputStream gzReader = new GZIPInputStream(new InputStream() { @Override public int read() throws IOException { if (stream.readableBytes() <= 0) { return -1; } return stream.readByte() & STREAM_MASK; } }); final ByteBuf uncompressed = Unpooled.buffer(stream.readableBytes()); final byte[] tmp = new byte[TEMP_BUFFER_SIZE]; while (gzReader.available() != 0) { final int bytes = gzReader.read(tmp); if (bytes > 0) { uncompressed.writeBytes(tmp, 0, bytes); } } gzReader.close(); while (uncompressed.readableBytes() > 0) { list.add(AEItemStack.fromPacket(uncompressed)); } empty = list.isEmpty(); }
@SuppressWarnings("unchecked") public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException { try { GZIPCompressedMessage result = new GZIPCompressedMessage(); byte[] byteArray = new byte[data.remaining()]; data.get(byteArray); GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(byteArray)); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] tmp = new byte[9012]; int read; while (in.available() > 0 && ((read = in.read(tmp)) > 0)) { out.write(tmp, 0, read); } result.setMessage((Message)Serializer.readClassAndObject(ByteBuffer.wrap(out.toByteArray()))); return (T)result; } catch (Exception e) { e.printStackTrace(); throw new IOException(e.toString()); } }
@SuppressWarnings("unchecked") public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException { try { GZIPCompressedMessage result = new GZIPCompressedMessage(); byte[] byteArray = new byte[data.remaining()]; data.get(byteArray); GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(byteArray)); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] tmp = new byte[9012]; int read; while (in.available() > 0 && ((read = in.read(tmp)) > 0)) { out.write(tmp, 0, read); } result.setMessage((Message)Serializer.readClassAndObject(ByteBuffer.wrap(out.toByteArray()))); return (T)result; } catch (Exception e) { e.printStackTrace(); throw new IOException(e.toString()); } }
/** * Replays the recorded data through the scenario's reporters. Any instance of {@link RawReporter} is ignored. * * @throws IOException * When there was an error reading the replay data. */ public void replay() throws IOException { try ( final ObjectInputStream ois = new ObjectInputStream(gzip); ) { final RunInfo originalRunInfo = (RunInfo) ois.readObject(); runInfo = new ReplayRunInfo(originalRunInfo); reportManager.setRunInfo(runInfo); try { while (gzip.available() > 0) { report(MeasurementUnit.streamIn(ois)); } } catch (EOFException eof) { // nothing wrong, we just stop reporting here, gzip actually keeps some excessive buffer at the end } resetLastTimes(); publishResults(lastTime); } catch (ClassNotFoundException cnfe) { throw new IOException("Unknown class in the recorded data. Make sure all the plugins are loaded that were used during recording: ", cnfe); } }