public void readBytes(byte[] buffer, int offset, int count) throws EOFException { try { input.readBytes(buffer, offset, count); } catch (KryoException e) { throw maybeEndOfStream(e); } }
public BigInteger read(Kryo kryo, Input input, Class<BigInteger> type) { int length = input.readVarInt(true); if (length == NULL) return null; byte[] bytes = input.readBytes(length - 1); if (type != BigInteger.class && type != null) { // For subclasses, use reflection try { Constructor<BigInteger> constructor = type.getConstructor(byte[].class); if (!constructor.isAccessible()) { try { constructor.setAccessible(true); } catch (SecurityException se) { } } return constructor.newInstance(bytes); } catch (Exception ex) { throw new KryoException(ex); } } if (length == 2) { // fast-path optimizations for BigInteger constants switch (bytes[0]) { case 0: return BigInteger.ZERO; case 1: return BigInteger.ONE; case 10: return BigInteger.TEN; } } return new BigInteger(bytes); }
public void testSmallBuffers() throws Exception { ByteBuffer buf = ByteBuffer.allocate(1024); ByteBufferOutputStream byteBufferOutputStream = new ByteBufferOutputStream(buf); Output testOutput = new Output(byteBufferOutputStream); testOutput.writeBytes(new byte[512]); testOutput.writeBytes(new byte[512]); testOutput.flush(); ByteBufferInputStream testInputs = new ByteBufferInputStream(); buf.flip(); testInputs.setByteBuffer(buf); Input input = new Input(testInputs, 512); byte[] toRead = new byte[512]; input.readBytes(toRead); input.readBytes(toRead); }
public byte[] readBinary() throws IOException { try { int length = input.readInt(true); byte[] result = new byte[length]; input.readBytes(result); return result; } catch (KryoException e) { throw maybeEndOfStream(e); } }
@Override protected VideoChunk readObject( Kryo kryo, Input input, Class<VideoChunk> clas, long requestId, String streamId, long sequenceNr) throws Exception { long duration = input.readLong(); int length = input.readInt(); byte[] video = input.readBytes(length); String container = input.readString(); VideoChunk chunk = new VideoChunk(streamId, sequenceNr, duration, video, container); chunk.setRequestId(requestId); return chunk; }
/** Reads bytes.length bytes and writes them to the specified byte[], starting at index 0. */ public void readBytes(byte[] bytes) throws KryoException { readBytes(bytes, 0, bytes.length); }
/** Reads the specified number of bytes into a new byte[]. */ public byte[] readBytes(int length) throws KryoException { byte[] bytes = new byte[length]; readBytes(bytes, 0, length); return bytes; }