Package com.esotericsoftware.kryo

Examples of com.esotericsoftware.kryo.Kryo


    dfa.setPropertyValue("tupleToStringConverter", tupleToJsonStringConverter);
  }

  @Override
  protected Kryo getKryoInstance() {
    Kryo kryo = new Kryo();
    kryo.setInstantiatorStrategy(new StdInstantiatorStrategy());
    kryo.register(DefaultTuple.class);
    return kryo;
  }
View Full Code Here


    return new File(file.getPath());
  }

  @Override
  protected Kryo getKryoInstance() {
    Kryo kryo = new Kryo();
    kryo.register(File.class);
    kryo.setInstantiatorStrategy(new StdInstantiatorStrategy());
    return kryo;
  }
View Full Code Here

  }

  @Override
  public Kryo newKryo() {
    try {
      Kryo k = reflectingInst.newKryo();
      // register all the carbonite serializers
      enhanceRegistry(k);

      k.register(ArrayList.class);
      k.register(HashMap.class);
      k.register(HashSet.class);

      k.setReferences(config.getBoolean("cascalog.kryo.setreferences", false));
      k.setClassLoader(Thread.currentThread().getContextClassLoader());

      return k;

    } catch (Exception e) {
      throw new RuntimeException("unable to create new Kryo: " + e);
View Full Code Here

    }

    private Triple<Kryo, SerializerFactory[], UnregisteredClassHandler[]> createKryo( final ClassLoader classLoader,
            final String[] customConverterClassNames, final boolean copyCollectionsForSerialization ) {
       
        final Kryo kryo = new KryoReflectionFactorySupport() {
           
            @Override
            @SuppressWarnings( { "rawtypes", "unchecked" } )
            public Serializer newSerializer(final Class clazz) {
                final Serializer customSerializer = loadCustomSerializer( clazz );
                if ( customSerializer != null ) {
                    return customSerializer;
                }
                if ( EnumSet.class.isAssignableFrom( clazz ) ) {
                    return new EnumSetSerializer( this );
                }
                if ( EnumMap.class.isAssignableFrom( clazz ) ) {
                    return new EnumMapSerializer( this );
                }
                if ( SubListSerializer.canSerialize( clazz ) ) {
                    return new SubListSerializer( this, clazz );
                }
                if ( copyCollectionsForSerialization ) {
                    final Serializer copyCollectionSerializer = loadCopyCollectionSerializer( clazz, this );
                    if ( copyCollectionSerializer != null ) {
                        return copyCollectionSerializer;
                    }
                }
                if ( Date.class.isAssignableFrom( clazz ) ) {
                    return new DateSerializer( clazz );
                }
                return super.newSerializer( clazz );
            }
           
            @SuppressWarnings( { "rawtypes" } )
            @Override
            protected void handleUnregisteredClass( final Class clazz ) {
                if ( _unregisteredClassHandlers != null ) {
                    for( int i = 0; i < _unregisteredClassHandlers.length; i++ ) {
                        final boolean handled = _unregisteredClassHandlers[i].handleUnregisteredClass( clazz );
                        if ( handled ) {
                            if ( LOG.isDebugEnabled() ) {
                                LOG.debug( "UnregisteredClassHandler " + _unregisteredClassHandlers[i].getClass().getName() + " handled class " + clazz );
                            }
                            return;
                        }
                    }
                }
                super.handleUnregisteredClass( clazz );
            }
           
            @Override
            protected Serializer newDefaultSerializer( @SuppressWarnings( "rawtypes" ) final Class type ) {
                return _defaultSerializerFactory.newDefaultSerializer( this, type );
            }

        };
       
        if ( classLoader != null ) {
            kryo.setClassLoader( classLoader );
        }
       
        // com.esotericsoftware.minlog.Log.TRACE = true;
       
        kryo.setRegistrationOptional( true );
        kryo.register( ArrayList.class );
        kryo.register( LinkedList.class );
        kryo.register( HashSet.class );
        kryo.register( HashMap.class );
        kryo.register( Arrays.asList( "" ).getClass(), new ArraysAsListSerializer( kryo ) );
        kryo.register( Currency.class, new CurrencySerializer( kryo ) );
        kryo.register( StringBuffer.class, new StringBufferSerializer( kryo ) );
        kryo.register( StringBuilder.class, new StringBuilderSerializer( kryo ) );
        kryo.register( Collections.EMPTY_LIST.getClass(), new CollectionsEmptyListSerializer() );
        kryo.register( Collections.EMPTY_MAP.getClass(), new CollectionsEmptyMapSerializer() );
        kryo.register( Collections.EMPTY_SET.getClass(), new CollectionsEmptySetSerializer() );
        kryo.register( Collections.singletonList( "" ).getClass(), new CollectionsSingletonListSerializer( kryo ) );
        kryo.register( Collections.singleton( "" ).getClass(), new CollectionsSingletonSetSerializer( kryo ) );
        kryo.register( Collections.singletonMap( "", "" ).getClass(), new CollectionsSingletonMapSerializer( kryo ) );
        kryo.register( Class.class, new ClassSerializer( kryo ) );
        kryo.register( BigDecimal.class, new BigDecimalSerializer() );
        kryo.register( BigInteger.class, new BigIntegerSerializer() );
        kryo.register( GregorianCalendar.class, new GregorianCalendarSerializer() );
        kryo.register( InvocationHandler.class, new JdkProxySerializer( kryo ) );
        UnmodifiableCollectionsSerializer.registerSerializers( kryo );
        SynchronizedCollectionsSerializer.registerSerializers( kryo );
        kryo.register( Locale.class, new LocaleSerializer() );
       
        final Triple<KryoCustomization[], SerializerFactory[], UnregisteredClassHandler[]> pair = loadCustomConverter( customConverterClassNames,
                classLoader, kryo );
       
        final KryoCustomization[] customizations = pair.a;
View Full Code Here

public class SpringSecurityUserSerializerTest {

  @Test
  public void testSpringSecurityUserSerializer() {
    final Kryo kryo = new KryoReflectionFactorySupport();
    kryo.setRegistrationOptional(true);
   
    new SpringSecurityUserRegistration().customize(kryo);
   
    final Collection<? extends GrantedAuthority> authorities = Arrays.asList(new SimpleGrantedAuthority("foo"));
    final User user = new User("foo", "bar", authorities);
View Full Code Here

*/
public class HibernateCollectionsSerializerFactoryTest {

    @Test
    public void test() {
        HibernateCollectionsSerializerFactory factory = new HibernateCollectionsSerializerFactory(new Kryo());

        Serializer serializer = factory.newSerializer(PersistentList.class);
        assertNotNull(serializer);
    }
View Full Code Here

  /**
   * Test method for {@link org.apache.niolex.commons.stream.KryoOutstream#writeObject(java.lang.Object)}.
   */
  @Test
  public void testWriteObject() {
    Kryo kryo = new Kryo();
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    KryoOutstream ooo = new KryoOutstream(kryo, bos);
    One<Long> o = One.<Long>create(8743244964238596L);
    Bean p = new Bean(324, "One", 8967, new Date(8743244964238596L));
    Bean q = new Bean(5, "Another", 523212, new Date(1338008328334L));
View Full Code Here

   * Create a simple kryo to process this output stream.
   *
   * @param out the output stream
   */
  public KryoOutstream(OutputStream out) {
    this(new Kryo(), out);
  }
View Full Code Here

   * Create a simple kryo to process this input stream.
   *
   * @param in the input stream
   */
  public KryoInstream(InputStream in) {
    this(new Kryo(), in);
  }
View Full Code Here

    return new ValueComparator<T>(ascendingComparison, type);
  }
 
  private void checkKryoInitialized() {
    if (this.kryo == null) {
      this.kryo = new Kryo();
      this.kryo.setAsmEnabled(true);
      this.kryo.register(type);
    }
  }
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.