Package com.esotericsoftware.kryo

Examples of com.esotericsoftware.kryo.Kryo


         return kryo;
      }
   };
  
   private static Kryo getCurrentThreadKryo() {
      Kryo kryo = threadKryo.get();
      return kryo;
   }
View Full Code Here


      return kryo;
   }
  
   @Override
   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();
View Full Code Here

      return extByteBuffer;
   }

   @Override
   public Object createObjectFromBytes(byte[] bytes) {
      Kryo kryo = getCurrentThreadKryo();
     
      Object obj = null;
      Input in = new Input(bytes);
      obj = (Object) kryo.readClassAndObject(in);
      in.close();
      return obj;
   }
View Full Code Here

      return obj;
   }

   @Override
   public Object createObjectFromByteBufferWithLengthHeader(ByteBuffer buffer) {
      Kryo kryo = getCurrentThreadKryo();
     
      // skip the buffer length parameter
      buffer.position(buffer.position() + 4);
     
      Input in = new Input(new ByteBufferInputStream(buffer));
      Message msg = (Message) kryo.readClassAndObject(in);
      in.close();
      msg.rewind();
      return msg;
   }
View Full Code Here

      return msg;
   }

   @Override
   public Object deepDuplicate(Object o) {
      Kryo kryo = getCurrentThreadKryo();
      return kryo.copy(o);
   }
View Full Code Here

        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());
        assertEquals(2, des.size());
        assertEquals(0.9, des.getCoordinate("foo"), eps);
        assertEquals(-1.8, des.getCoordinate("bar"), eps);
        des.incrementIteration();
View Full Code Here

    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);
        assertFalse(des.getFreezeKeySet());
        assertEquals(2, des.size());
        assertEquals(1.0, des.getCoordinate("foo"), eps);
        assertEquals(-2.0, des.getCoordinate("bar"), eps);
View Full Code Here

            }
            final UserProfile profile3 = ProfileHelper.buildProfile(profile2.getTypedId(), newAttributes);
            verifyProfile(profile3);

            // Kryo serialization
            final Kryo kryo = new Kryo();
            kryo.register(HashMap.class);
            kryo.register(Locale.class, new LocaleSerializer());
            kryo.register(Date.class);
            kryo.register(FormattedDate.class, new FormattedDateSerializer());
            kryo.register(Gender.class);
            kryo.register(Color.class, new ColorSerializer());
            kryo.register(ArrayList.class);
            registerForKryo(kryo);
            bytes = TestsHelper.serializeKryo(kryo, profile);
            final UserProfile profile4 = (UserProfile) TestsHelper.unserializeKryo(kryo, bytes);
            verifyProfile(profile4);
        } finally {
View Full Code Here

  static public final short PLAYER = 1;
  static public final short CHAT_FRAME = 2;

  // This registers objects that are going to be sent over the network.
  static public void register (EndPoint endPoint) {
    Kryo kryo = endPoint.getKryo();
    // This must be called in order to use ObjectSpaces.
    ObjectSpace.registerClasses(kryo);
    // The interfaces that will be used as remote objects must be registered.
    kryo.register(IPlayer.class);
    kryo.register(IChatFrame.class);
    // The classes of all method parameters and return values
    // for remote objects must also be registered.
    kryo.register(String[].class);
  }
View Full Code Here

  private final Output output;
  private final ByteBufferInputStream byteBufferInputStream = new ByteBufferInputStream();
  private final ByteBufferOutputStream byteBufferOutputStream = new ByteBufferOutputStream();

  public KryoSerialization () {
    this(new Kryo());
    kryo.setReferences(false);
    kryo.setRegistrationRequired(true);
  }
View Full Code Here

TOP

Related Classes of com.esotericsoftware.kryo.Kryo

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.