Java Code Examples for com.esotericsoftware.kryo.Kryo.readObject()

The following are Jave code examples for showing how to use readObject() of the com.esotericsoftware.kryo.Kryo class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: gdx-cclibs   File: PerspectiveCameraSerializer.java   Source Code and License Vote up 6 votes
@Override
public PerspectiveCamera read (Kryo kryo, Input input, Class<PerspectiveCamera> type) {
    PerspectiveCamera camera = new PerspectiveCamera();
    Vector3 position = kryo.readObject(input, Vector3.class);
    Vector3 direction = kryo.readObject(input, Vector3.class);
    Vector3 up = kryo.readObject(input, Vector3.class);
    camera.position.set(position);
    camera.direction.set(direction);
    camera.up.set(up);
    camera.near = input.readFloat();
    camera.far = input.readFloat();
    camera.viewportWidth = input.readFloat();
    camera.viewportHeight = input.readFloat();
    camera.fieldOfView = input.readFloat();
    camera.update();
    return camera;
}
 
Example 2
Project: cas-5.1.0   File: GoogleAccountsServiceSerializer.java   Source Code and License Vote up 6 votes
@Override
protected GoogleAccountsService createService(final Kryo kryo, final Input input, final String id,
        final String originalUrl, final String artifactId) {

    final String requestId = kryo.readObject(input, String.class);
    final String relayState = kryo.readObject(input, String.class);
    try {
        return (GoogleAccountsService) CONSTRUCTOR.newInstance(
                id,
                originalUrl,
                artifactId,
                relayState,
                requestId,
                this.privateKey,
                this.publicKey,
                this.alternateUsername);
    } catch (final Exception e) {
        throw new IllegalStateException("Error creating SamlService", e);
    }
}
 
Example 3
Project: lionrpc   File: MessageDecoder.java   Source Code and License Vote up 5 votes
protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf in, List<Object> out) throws Exception {

        if(in.readableBytes() < 4){
            return;
        }
        in.markReaderIndex();
        int dataLength = in.readInt();
        if(in.readableBytes() < dataLength){
            in.resetReaderIndex();
            return;
        }
        byte[] data = new byte[dataLength];
        in.readBytes(data);
        
        Kryo kryo = null;
        try{
	        kryo = pool.borrow();
	        Input input = new Input(data);
	        Object obj = kryo.readObject(input,this.clazz);
	        out.add(obj);
        }catch(Exception e){
        	LOG.warn("MessageDecoder happen exception.",e);
        }finally{
        	if(kryo != null){
        		pool.release(kryo);
        	}
        }
    }
 
Example 4
Project: T2KMatch   File: WebTables.java   Source Code and License Vote up 5 votes
public static WebTables deserialise(File location) throws FileNotFoundException {
	System.out.println("Deserialising Web Tables");
	
       Kryo kryo = KryoFactory.createKryoInstance();
       
       Input input = new Input(new FileInputStream(location));
       WebTables web = kryo.readObject(input, WebTables.class);
       input.close();
       
       return web;
}
 
Example 5
Project: springboot-shiro-cas-mybatis   File: RegisteredServiceSerializer.java   Source Code and License Vote up 5 votes
/**
 * Read object by reflection.
 *
 * @param <T>   the type parameter
 * @param kryo  the kryo
 * @param input the input
 * @param type  the type
 * @return the t
 */
private static <T> T readObjectByReflection(final Kryo kryo, final Input input, final Class<? extends T> type) {
    try {
        final String className = kryo.readObject(input, String.class);
        final Class<T> clazz = (Class<T>) Class.forName(className);
        return kryo.readObject(input, clazz);
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 6
Project: dremio-oss   File: RelTraitSerializers.java   Source Code and License Vote up 5 votes
@Override
public T read(final Kryo kryo, final Input input, final Class<T> type) {
  final boolean isKnown = kryo.readObject(input, Boolean.class);
  final T result;
  if (isKnown) {
    final DistributionTrait.DistributionType kind = kryo.readObject(input, DistributionTrait.DistributionType.class);
    result = (T)distributionMap.get(kind);
  } else {
    result = super.read(kryo, input, type);
  }

  final T normalized = (T) result.getTraitDef().canonize(result);
  kryo.reference(normalized);
  return normalized;
}
 
Example 7
Project: springboot-shiro-cas-mybatis   File: URLSerializer.java   Source Code and License Vote up 5 votes
@Override
public URL read(final Kryo kryo, final Input input, final  Class<URL> type) {
    final String url = kryo.readObject(input, String.class);
    try {
        return new URL(url);
    } catch (final MalformedURLException e) {
        throw new RuntimeException(e);
    }
}
 
Example 8
Project: dremio-oss   File: SqlOperatorSerializer.java   Source Code and License Vote up 5 votes
@Override
public T read(final Kryo kryo, final Input input, final Class<T> type) {
  final boolean isKnown = kryo.readObject(input, Boolean.class);
  if (isKnown) {
    final Integer ordinal = kryo.readObject(input, Integer.class);
    final SqlOperator operator = OperatorPopulator.BACKWARD.get(ordinal);
    if (operator != null) {
      kryo.reference(operator);
      return (T)operator;
    }
    throw new IllegalStateException(String.format("Unable to locate operator with ordinal [%s]", ordinal));
  }

  return super.read(kryo, input, type);
}
 
Example 9
Project: springboot-shiro-cas-mybatis   File: SamlServiceSerializer.java   Source Code and License Vote up 5 votes
@Override
protected SamlService createService(final Kryo kryo, final Input input, final String id,
        final String originalUrl, final String artifactId) {

    final String requestId = kryo.readObject(input, String.class);
    try {
        return (SamlService) CONSTRUCTOR.newInstance(id, originalUrl, artifactId, new SimpleHttpClientFactoryBean().getObject(),
                requestId);
    } catch (final Exception e) {
        throw new IllegalStateException("Error creating SamlService", e);
    }
}
 
Example 10
Project: gdx-cclibs   File: ObjectFloatMapSerializer.java   Source Code and License Vote up 5 votes
public ObjectFloatMap read (Kryo kryo, Input input, Class<ObjectFloatMap> type) {
    int length = input.readVarInt(true);
    input.readBoolean(); // currently unused
    ObjectFloatMap map = create(length);

    Class keyClass = null;

    Serializer keySerializer = null;
    if (keyGenericType != null) {
        keyClass = keyGenericType;
        if (keySerializer == null) keySerializer = kryo.getSerializer(keyClass);
        keyGenericType = null;
    }

    kryo.reference(map);

    for (int i = 0; i < length; i++) {
        Object key;
        if (keySerializer != null) {
            key = kryo.readObject(input, keyClass, keySerializer);
        } else
            key = kryo.readClassAndObject(input);
        float value = input.readFloat();
        map.put(key, value);
    }
    return map;
}
 
Example 11
Project: springboot-shiro-cas-mybatis   File: SamlServiceSerializer.java   Source Code and License Vote up 5 votes
@Override
protected SamlService createService(final Kryo kryo, final Input input, final String id,
        final String originalUrl, final String artifactId) {

    final String requestId = kryo.readObject(input, String.class);
    try {
        return (SamlService) CONSTRUCTOR.newInstance(id, originalUrl, artifactId, new SimpleHttpClientFactoryBean().getObject(),
                requestId);
    } catch (final Exception e) {
        throw new IllegalStateException("Error creating SamlService", e);
    }
}
 
Example 12
Project: MobiRNN-EMDL17   File: DataUtilTest.java   Source Code and License Vote up 5 votes
@Test
    public void serialize() throws Exception {
        String testFilePath = getClass().getClassLoader().getResource("lstm_har-data").getFile();
        String inputFilePath =
                testFilePath + File.separator + "test_data" + File.separator + "sensor";
        final float[][][] inputs;

        final Kryo kryo = new Kryo();
        kryo.register(float[][][].class);
        final File dataBinFile = new File("data-small.bin");
        if (dataBinFile.exists()) {
            Input input = new Input(new FileInputStream(dataBinFile));
            inputs = kryo.readObject(input, float[][][].class);
            input.close();
        } else {
            inputs = DataUtil.parseInputData(inputFilePath);
            Output output = new Output(new FileOutputStream(dataBinFile));

            kryo.writeObject(output, inputs);
            output.close();
        }

//        Gson gson = new Gson();
//        final File dataBinFile = new File("data.json");
//        if (dataBinFile.exists()) {
//            inputs = gson.fromJson(FileUtils.readFileToString(dataBinFile), float[][][].class);
//        } else {
//            inputs = DataUtil.parseInputData(inputFilePath);
//            String result = gson.toJson(inputs);
//            FileUtils.writeStringToFile(new File("data.json"), result);
//        }


    }
 
Example 13
Project: cas-server-4.2.1   File: URLSerializer.java   Source Code and License Vote up 5 votes
@Override
public URL read(final Kryo kryo, final Input input, final  Class<URL> type) {
    final String url = kryo.readObject(input, String.class);
    try {
        return new URL(url);
    } catch (final MalformedURLException e) {
        throw new RuntimeException(e);
    }
}
 
Example 14
Project: cas-server-4.2.1   File: RegisteredServiceSerializer.java   Source Code and License Vote up 5 votes
/**
 * Read object by reflection.
 *
 * @param <T>   the type parameter
 * @param kryo  the kryo
 * @param input the input
 * @param type  the type
 * @return the t
 */
private static <T> T readObjectByReflection(final Kryo kryo, final Input input, final Class<? extends T> type) {
    try {
        final String className = kryo.readObject(input, String.class);
        final Class<T> clazz = (Class<T>) Class.forName(className);
        return kryo.readObject(input, clazz);
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 15
Project: T2KMatch   File: KnowledgeBase.java   Source Code and License Vote up 5 votes
public static KnowledgeBase deserialise(File location) throws FileNotFoundException {
	System.out.println("Deserialising Knowledge Base");
	
       Kryo kryo = KryoFactory.createKryoInstance();
       
       Input input = new Input(new FileInputStream(location));
       KnowledgeBase kb = kryo.readObject(input, KnowledgeBase.class);
       input.close();
       
       return kb;
}
 
Example 16
Project: dremio-oss   File: ImmutableCollectionSerializers.java   Source Code and License Vote up 5 votes
@Override
public ImmutableMap<Object, Object> read(Kryo kryo, Input input, Class<ImmutableMap<Object, ? extends Object>> type) {
  Map map = kryo.readObject(input, HashMap.class);
  final ImmutableMap<Object, Object> result = ImmutableMap.copyOf(map);
  kryo.reference(result);
  return result;
}
 
Example 17
Project: athena   File: DefaultPortSerializer.java   Source Code and License Vote up 5 votes
@Override
public DefaultPort read(Kryo kryo, Input input, Class<DefaultPort> aClass) {
    Element element = (Element) kryo.readClassAndObject(input);
    PortNumber number = kryo.readObject(input, PortNumber.class);
    boolean isEnabled = input.readBoolean();
    Port.Type type = kryo.readObject(input, Port.Type.class);
    long portSpeed = input.readLong();
    Annotations annotations = (Annotations) kryo.readClassAndObject(input);

    return new DefaultPort(element, number, isEnabled, type, portSpeed, annotations);
}
 
Example 18
Project: dremio-oss   File: RelTraitSerializers.java   Source Code and License Vote up 4 votes
@Override
public T read(final Kryo kryo, final Input input, final Class<T> type) {
  final int ordinal = kryo.readObject(input, Integer.class);
  return type.getEnumConstants()[ordinal];
}
 
Example 19
Project: springboot-shiro-cas-mybatis   File: SimpleWebApplicationServiceSerializer.java   Source Code and License Vote up 4 votes
@Override
public SimpleWebApplicationServiceImpl read(final Kryo kryo, final Input input, final Class<SimpleWebApplicationServiceImpl> type) {
    return new SimpleWebApplicationServiceImpl(kryo.readObject(input, String.class));
}
 
Example 20
Project: athena   File: DefaultApplicationIdSerializer.java   Source Code and License Vote up 4 votes
@Override
public DefaultApplicationId read(Kryo kryo, Input input, Class<DefaultApplicationId> type) {
    short id = kryo.readObject(input, Short.class);
    String name = kryo.readObject(input, String.class);
    return new DefaultApplicationId(id, name);
}