Package com.esotericsoftware.kryo.io

Examples of com.esotericsoftware.kryo.io.Output


    assertEquals(read.readDouble(1000, true), -8192d);
    assertEquals(1.23456d, read.readDouble());
  }

  public void testBooleans () throws IOException {
    runBooleanTest(new Output(4096));
    runBooleanTest(new Output(new ByteArrayOutputStream()));
  }
View Full Code Here


      assertEquals(false, read.readBoolean());
    }
  }

  public void testChars () throws IOException {
    runCharTest(new Output(4096));
    runCharTest(new Output(new ByteArrayOutputStream()));
  }
View Full Code Here

  }
 
  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);
View Full Code Here

    kryoWithoutF.register(B.class);
    kryoWithoutF.register(C.class);
    kryoWithoutF.register(D.class);
    kryoWithoutF.register(E.class);

    Output output = new Output(512);
    try {
      kryoWithoutF.writeClassAndObject(output, c);
      fail("Should have failed because F is not registered.");
    } catch (KryoException ignored) {
    }

    kryo.register(A.class);
    kryo.register(B.class);
    kryo.register(C.class);
    kryo.register(D.class);
    kryo.register(E.class);
    kryo.register(F.class);
    kryo.setRegistrationRequired(true);

    output.clear();
    kryo.writeClassAndObject(output, c);
    output.flush();
    assertEquals(14, output.total());

    Input input = new Input(output.getBuffer());
    kryo.readClassAndObject(input);

    try {
      input.setPosition(0);
      kryoWithoutF.readClassAndObject(input);
View Full Code Here

    catch(java.io.IOException iox) {
      throw new ConfigurationException("could not deserialize: " + base64Value, iox);
    }
  }
  protected static String serialize(Kryo k, KryoInstantiator ki) {
    Output out = new Output(1 << 10, 1 << 19); // 1 MB in config is too much
    k.writeClassAndObject(out, ki);
    return Base64.encodeBytes(out.toBytes());
  }
View Full Code Here

            message.put(SerTokens.TOKEN_RESULT, result);
            message.put(SerTokens.TOKEN_REQUEST, responseMessage.getRequestId() != null ? responseMessage.getRequestId() : null);

            final Kryo kryo = kryoThreadLocal.get();
            try (final OutputStream baos = new ByteArrayOutputStream()) {
                final Output output = new Output(baos);
                kryo.writeClassAndObject(output, message);

                final long size = output.total();
                if (size > Integer.MAX_VALUE)
                    throw new SerializationException(String.format("Message size of %s exceeds allocatable space", size));

                encodedMessage = allocator.buffer((int) output.total());
                encodedMessage.writeBytes(output.toBytes());
            }

            return encodedMessage;
        } catch (Exception ex) {
            if (encodedMessage != null) ReferenceCountUtil.release(encodedMessage);
View Full Code Here

    public ByteBuf serializeRequestAsBinary(final RequestMessage requestMessage, final ByteBufAllocator allocator) throws SerializationException {
        ByteBuf encodedMessage = null;
        try {
            final Kryo kryo = kryoThreadLocal.get();
            try (final OutputStream baos = new ByteArrayOutputStream()) {
                final Output output = new Output(baos);
                final String mimeType = serializeToString ? MIME_TYPE_STRINGD : MIME_TYPE;
                output.writeByte(mimeType.length());
                output.write(mimeType.getBytes(UTF8));

                final Map<String, Object> request = new HashMap<>();
                request.put(SerTokens.TOKEN_REQUEST, requestMessage.getRequestId());
                request.put(SerTokens.TOKEN_PROCESSOR, requestMessage.getProcessor());
                request.put(SerTokens.TOKEN_OP, requestMessage.getOp());
                request.put(SerTokens.TOKEN_ARGS, requestMessage.getArgs());

                kryo.writeClassAndObject(output, request);

                final long size = output.total();
                if (size > Integer.MAX_VALUE)
                    throw new SerializationException(String.format("Message size of %s exceeds allocatable space", size));

                encodedMessage = allocator.buffer((int) size);
                encodedMessage.writeBytes(output.toBytes());
            }

            return encodedMessage;
        } catch (Exception ex) {
            if (encodedMessage != null) ReferenceCountUtil.release(encodedMessage);
View Full Code Here

                    .bufferSize(batchSize).create();
        } catch (Exception ex) {
            throw new IOException("Could not instantiate BatchGraph wrapper", ex);
        }

        try (final Output output = new Output(new FileOutputStream(tempFile))) {
            final boolean supportedMemory = input.readBoolean();
            if (supportedMemory) {
                // if the graph that serialized the data supported sideEffects then the sideEffects needs to be read
                // to advance the reader forward.  if the graph being read into doesn't support the sideEffects
                // then we just setting the data to sideEffects.
View Full Code Here

 
 
  @Test
  public void test_measurepoint_save(){
    Kryo kryo = SerializeUtil.createKryo();
    Output output = new Output(66666);
   
    kryo.writeClassAndObject(output, new MeasurePointData("1111"));
    int oldPos = output.position();
    kryo.writeClassAndObject(output, new MeasurePointData("1111"));
    assertEquals(oldPos+19,output.position());//only key is written not string again
    kryo.writeClassAndObject(output, new MeasurePointData("1111"));
    kryo.writeClassAndObject(output, new MeasurePointData("2222"));
    kryo.writeClassAndObject(output, new MeasurePointData("2222"));
    kryo.writeClassAndObject(output, new MeasurePointData("1111"));
   
    Input input = new Input(output.getBuffer());
    assertEquals("1111", ((MeasurePointData)kryo.readClassAndObject(input)).getMeasurePointId());
    assertEquals("1111", ((MeasurePointData)kryo.readClassAndObject(input)).getMeasurePointId());
    assertEquals("1111", ((MeasurePointData)kryo.readClassAndObject(input)).getMeasurePointId());
    assertEquals("2222", ((MeasurePointData)kryo.readClassAndObject(input)).getMeasurePointId());
    assertEquals("2222", ((MeasurePointData)kryo.readClassAndObject(input)).getMeasurePointId());
View Full Code Here

 
 
  @Test
  public void test_write(){
    Kryo kryo = Mockito.mock(Kryo.class);
    Output output = Mockito.mock(Output.class);
   
    MeasurePointIdSerializer measurePointIdSerializer = new MeasurePointIdSerializer();
    measurePointIdSerializer.write(kryo, output, "111");
    Mockito.verify(output).writeInt(-1);
    Mockito.verify(output).writeString("111");
View Full Code Here

TOP

Related Classes of com.esotericsoftware.kryo.io.Output

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.