예제 #1
0
 public void readBytes(byte[] buffer, int offset, int count) throws EOFException {
   try {
     input.readBytes(buffer, offset, count);
   } catch (KryoException e) {
     throw maybeEndOfStream(e);
   }
 }
예제 #2
0
 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);
 }
예제 #3
0
  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);
  }
예제 #4
0
 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);
   }
 }
예제 #5
0
 @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;
 }
예제 #6
0
파일: Input.java 프로젝트: BoBinLee/kryo
 /** 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);
 }
예제 #7
0
파일: Input.java 프로젝트: BoBinLee/kryo
 /** 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;
 }