Package com.esotericsoftware.kryo.io

Examples of com.esotericsoftware.kryo.io.Output


      earliest = Math.min(d.getTimeStamp().getTime(), earliest);
      latest = Math.max(d.getTimeStamp().getTime(), latest);
    }
    Kryo kryo = SerializeUtil.createKryo();
    b.position(MonitoringDataStorage.FIRST_RECORD_POSITION);
    Output output = new Output(new ByteBufferOutputStream(b));
    for (MonitoringData data : values) {
      kryo.writeClassAndObject(output, data);
    }
    output.close();
    int limit = b.position();
   
    b.putLong(MonitoringDataStorage.EARLIEST_POSITION, earliest);
    b.putLong(MonitoringDataStorage.LATEST_POSITION, latest);
    b.putInt(MonitoringDataStorage.LIMIT_POSITION, limit);
View Full Code Here


  @Test
  public void test_kryo(){
    Kryo kryo = new Kryo();
    kryo.register(AdapterWfLaunchInfo.class);
    {
      Output output = new Output(1024);
      final AdapterWfLaunchInfo object = new AdapterWfLaunchInfo();
      object.setAdapterName("abc");
      kryo.writeClassAndObject(output, object);
      kryo.writeClassAndObject(output, new LogEvent());
      assertTrue(output.getBuffer().length>0);
     
      Input input = new Input(output.getBuffer());
      assertEquals(AdapterWfLaunchInfo.class, kryo.readClassAndObject(input).getClass());
      assertEquals(LogEvent.class, kryo.readClassAndObject(input).getClass());
    }
  }
View Full Code Here

  public synchronized ChunkObjectSend generateMessages(IUniqueObject bean) {
    ChunkObjectSend msg = null;
    try {
      ByteArrayOutputStream stream = new ByteArrayOutputStream();
      Output output = new Output(stream);
      kryo.writeObjectOrNull(output, bean, bean.getClass());
      output.close(); // Also calls output.flush()

      // Serialization done, get bytes
      byte[] buffer = stream.toByteArray();
      msg = new ChunkObjectSend(bean.getClass().getName(), bean.getId(),
          buffer, chunkSize);
View Full Code Here

   * @param expr Expression.
   * @return Bytes.
   */
  public static byte[] serializeExpressionToKryo(ExprNodeGenericFuncDesc expr) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Output output = new Output(baos);
    runtimeSerializationKryo.get().writeObject(output, expr);
    output.close();
    return baos.toByteArray();
  }
View Full Code Here

  /**
   * @param plan Usually of type MapredWork, MapredLocalWork etc.
   * @param out stream in which serialized plan is written into
   */
  private static void serializeObjectByKryo(Kryo kryo, Object plan, OutputStream out) {
    Output output = new Output(out);
    kryo.writeObject(output, plan);
    output.close();
  }
View Full Code Here

   public byte[] getBytes(Object m) {
      Kryo kryo = getCurrentThreadKryo();     
     
      byte[] bytes = null;
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      Output out = new Output(bos);
      try {
         kryo.writeClassAndObject(out, m);
         out.flush();
         bytes = bos.toByteArray();
         bos.close();
      } catch (IOException e) {
         e.printStackTrace();
      } finally {
View Full Code Here

    public void testKryoSerialization() throws Exception {
        LazyVector skv = buildLV();
        skv.incrementIteration();
        // Serialize to a byte array in ram.
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        Output ko = new Output(bos);
        Kryo kry = new Kryo();
        kry.writeObject(ko, skv);
        ko.flush();
        // Deserialize.
        ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
        Input ki = new Input(bis);
        LazyVector des = (LazyVector)kry.readObject(ki, LazyVector.class);
        assertFalse(des.getFreezeKeySet());
View Full Code Here

    @Test
    public void testKryoSerialization() throws Exception {
        StringKeyedVector skv = buildSKV();
        // Serialize to a byte array in ram.
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        Output ko = new Output(bos);
        Kryo kry = new Kryo();
        kry.writeObject(ko, skv);
        ko.flush();
        // Deserialize.
        ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
        Input ki = new Input(bis);
        StringKeyedVector des = (StringKeyedVector)kry.readObject(ki,
                StringKeyedVector.class);
View Full Code Here

    public String key() {
        return this.base.key();
    }

    public void bsave(String filepath) {
        Output output = null;
        try {
            for (String vkey : vectorSets.keySet()) {
                vectorSets.get(vkey).clean();
            }

            output = new Output(new FileOutputStream(filepath));
            SerializerHelper serializerHelper = helper.get();
            serializerHelper.writeB(output, this.base);
            serializerHelper.writeVectorSets(output, this.vectorSets);
            serializerHelper.writeRecommendations(output, this.recommendations);
        } catch (Throwable e) {
            throw new SimException(e);
        } finally {
            if (output != null) {
                output.close();
            }
        }
    }
View Full Code Here

    kryo.register(KeepAlive.class);
    kryo.register(DiscoverHost.class);
    kryo.register(Ping.class);

    input = new Input(byteBufferInputStream, 512);
    output = new Output(byteBufferOutputStream, 512);
  }
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.