Java Code Examples for org.apache.tinkerpop.shaded.kryo.Kryo#readClassAndObject()
The following examples show how to use
org.apache.tinkerpop.shaded.kryo.Kryo#readClassAndObject() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GryoMapperTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test public void shouldRegisterMultipleIoRegistryToSerialize() throws Exception { final GryoMapper mapper = builder.get().addRegistry(IoXIoRegistry.InstanceBased.instance()) .addRegistry(IoYIoRegistry.InstanceBased.instance()).create(); final Kryo kryo = mapper.createMapper(); try (final OutputStream stream = new ByteArrayOutputStream()) { final Output out = new Output(stream); final IoX x = new IoX("x"); final IoY y = new IoY(100, 200); kryo.writeClassAndObject(out, x); kryo.writeClassAndObject(out, y); try (final InputStream inputStream = new ByteArrayInputStream(out.toBytes())) { final Input input = new Input(inputStream); final IoX readX = (IoX) kryo.readClassAndObject(input); final IoY readY = (IoY) kryo.readClassAndObject(input); assertEquals(x, readX); assertEquals(y, readY); } } }
Example 2
Source File: GryoMapperTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test public void shouldSerializeWithoutRegistration() throws Exception { final GryoMapper mapper = builder.get().registrationRequired(false).create(); final Kryo kryo = mapper.createMapper(); try (final OutputStream stream = new ByteArrayOutputStream()) { final Output out = new Output(stream); final IoX x = new IoX("x"); final IoY y = new IoY(100, 200); kryo.writeClassAndObject(out, x); kryo.writeClassAndObject(out, y); try (final InputStream inputStream = new ByteArrayInputStream(out.toBytes())) { final Input input = new Input(inputStream); final IoX readX = (IoX) kryo.readClassAndObject(input); final IoY readY = (IoY) kryo.readClassAndObject(input); assertEquals(x, readX); assertEquals(y, readY); } } }
Example 3
Source File: GryoMapperTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test public void shouldSerializeWithCustomClassResolverToHashMap() throws Exception { final Supplier<ClassResolver> classResolver = new CustomClassResolverSupplier(); final GryoMapper mapper = builder.get().classResolver(classResolver).create(); final Kryo kryo = mapper.createMapper(); try (final OutputStream stream = new ByteArrayOutputStream()) { final Output out = new Output(stream); final IoY y = new IoY(100, 200); kryo.writeClassAndObject(out, y); final GryoMapper mapperWithoutKnowledgeOfIoy = builder.get().create(); final Kryo kryoWithoutKnowledgeOfIox = mapperWithoutKnowledgeOfIoy.createMapper(); try (final InputStream inputStream = new ByteArrayInputStream(out.toBytes())) { final Input input = new Input(inputStream); final Map readY = (HashMap) kryoWithoutKnowledgeOfIox.readClassAndObject(input); assertEquals("100-200", readY.get("y")); } } }
Example 4
Source File: GryoMapperTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test public void shouldSerializeWithCustomClassResolverToDetachedVertex() throws Exception { final Supplier<ClassResolver> classResolver = new CustomClassResolverSupplier(); final GryoMapper mapper = builder.get().classResolver(classResolver).create(); final Kryo kryo = mapper.createMapper(); try (final OutputStream stream = new ByteArrayOutputStream()) { final Output out = new Output(stream); final IoX x = new IoX("no-way-this-will-ever-work"); kryo.writeClassAndObject(out, x); final GryoMapper mapperWithoutKnowledgeOfIox = builder.get().create(); final Kryo kryoWithoutKnowledgeOfIox = mapperWithoutKnowledgeOfIox.createMapper(); try (final InputStream inputStream = new ByteArrayInputStream(out.toBytes())) { final Input input = new Input(inputStream); final DetachedVertex readX = (DetachedVertex) kryoWithoutKnowledgeOfIox.readClassAndObject(input); assertEquals("no-way-this-will-ever-work", readX.value("x")); } } }
Example 5
Source File: GryoMapperTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test public void shouldSerializeDeserialize() throws Exception { final GryoMapper mapper = builder.get().create(); final Kryo kryo = mapper.createMapper(); try (final OutputStream stream = new ByteArrayOutputStream()) { final Output out = new Output(stream); final Map<String,Object> props = new HashMap<>(); final List<Map<String, Object>> propertyNames = new ArrayList<>(1); final Map<String,Object> propertyName = new HashMap<>(); propertyName.put(GraphSONTokens.ID, "x"); propertyName.put(GraphSONTokens.KEY, "x"); propertyName.put(GraphSONTokens.VALUE, "no-way-this-will-ever-work"); propertyNames.add(propertyName); props.put("x", propertyNames); final DetachedVertex v = new DetachedVertex(100, Vertex.DEFAULT_LABEL, props); kryo.writeClassAndObject(out, v); try (final InputStream inputStream = new ByteArrayInputStream(out.toBytes())) { final Input input = new Input(inputStream); final DetachedVertex readX = (DetachedVertex) kryo.readClassAndObject(input); assertEquals("no-way-this-will-ever-work", readX.value("x")); } } }
Example 6
Source File: WrappedArraySerializer.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public WrappedArray<T> read(final Kryo kryo, final Input input, final Class<WrappedArray<T>> aClass) { final int size = input.readVarInt(true); final Object[] array = new Object[size]; for (int i = 0; i < size; i++) { array[i] = kryo.readClassAndObject(input); } return new WrappedArray.ofRef<>((T[]) array); }
Example 7
Source File: GryoMapperTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test public void shouldExpectReadFailureAsIoRegistryOrderIsNotRespected() throws Exception { final GryoMapper mapperWrite = builder.get().addRegistry(IoXIoRegistry.InstanceBased.instance()) .addRegistry(IoYIoRegistry.InstanceBased.instance()).create(); final GryoMapper mapperRead = GryoMapper.build() .addRegistry(IoYIoRegistry.InstanceBased.instance()) .addRegistry(IoXIoRegistry.InstanceBased.instance()).create(); final Kryo kryoWriter = mapperWrite.createMapper(); final Kryo kryoReader = mapperRead.createMapper(); try (final OutputStream stream = new ByteArrayOutputStream()) { final Output out = new Output(stream); final IoX x = new IoX("x"); final IoY y = new IoY(100, 200); kryoWriter.writeClassAndObject(out, x); kryoWriter.writeClassAndObject(out, y); try (final InputStream inputStream = new ByteArrayInputStream(out.toBytes())) { final Input input = new Input(inputStream); // kryo will read a IoY instance as we've reversed the registries. it is neither an X or a Y // so assert that both are incorrect final IoY readY = (IoY) kryoReader.readClassAndObject(input); assertNotEquals(y, readY); assertNotEquals(x, readY); } } }
Example 8
Source File: AbstractGryoMessageSerializerV1d0.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public ResponseMessage deserializeResponse(final ByteBuf msg) throws SerializationException { try { final Kryo kryo = kryoThreadLocal.get(); final byte[] payload = new byte[msg.capacity()]; msg.readBytes(payload); try (final Input input = new Input(payload)) { final UUID requestId = kryo.readObjectOrNull(input, UUID.class); final int status = input.readShort(); final String statusMsg = input.readString(); final Map<String,Object> statusAttributes = (Map<String,Object>) kryo.readClassAndObject(input); final Object result = kryo.readClassAndObject(input); final Map<String,Object> metaAttributes = (Map<String,Object>) kryo.readClassAndObject(input); return ResponseMessage.build(requestId) .code(ResponseStatusCode.getFromValue(status)) .statusMessage(statusMsg) .statusAttributes(statusAttributes) .result(result) .responseMetaData(metaAttributes) .create(); } } catch (Exception ex) { logger.warn(String.format("Response [%s] could not be deserialized by %s.", msg, AbstractGryoMessageSerializerV1d0.class.getName()), ex); throw new SerializationException(ex); } }
Example 9
Source File: HugeGryoModule.java From hugegraph with Apache License 2.0 | 5 votes |
@SuppressWarnings("unused") private static Map<HugeKeys, Object> readEntry(Kryo kryo, Input input) { int columnSize = input.readInt(); Map<HugeKeys, Object> map = new LinkedHashMap<>(); for (int i = 0; i < columnSize; i++) { HugeKeys key = kryo.readObject(input, HugeKeys.class); Object val = kryo.readClassAndObject(input); map.put(key, val); } return map; }
Example 10
Source File: GryoLiteMessageSerializerV1d0.java From tinkerpop with Apache License 2.0 | 4 votes |
@Override public Path read(final Kryo kryo, final Input input, final Class<Path> pathClass) { return (Path) kryo.readClassAndObject(input); }
Example 11
Source File: UtilSerializers.java From tinkerpop with Apache License 2.0 | 4 votes |
@Override public Map.Entry read(final Kryo kryo, final Input input, final Class<Map.Entry> entryClass) { return new AbstractMap.SimpleEntry(kryo.readClassAndObject(input), kryo.readClassAndObject(input)); }
Example 12
Source File: GryoLiteMessageSerializerV1d0.java From tinkerpop with Apache License 2.0 | 4 votes |
@Override public VertexProperty read(final Kryo kryo, final Input input, final Class<VertexProperty> vertexPropertyClass) { return (VertexProperty) kryo.readClassAndObject(input); }
Example 13
Source File: GryoLiteMessageSerializerV1d0.java From tinkerpop with Apache License 2.0 | 4 votes |
@Override public Property read(final Kryo kryo, final Input input, final Class<Property> propertyClass) { return (Property) kryo.readClassAndObject(input); }
Example 14
Source File: GryoLiteMessageSerializerV1d0.java From tinkerpop with Apache License 2.0 | 4 votes |
@Override public Vertex read(final Kryo kryo, final Input input, final Class<Vertex> vertexClass) { return (Vertex) kryo.readClassAndObject(input); }
Example 15
Source File: GryoLiteMessageSerializerV1d0.java From tinkerpop with Apache License 2.0 | 4 votes |
@Override public Edge read(final Kryo kryo, final Input input, final Class<Edge> edgeClass) { final Object o = kryo.readClassAndObject(input); return (Edge) o; }
Example 16
Source File: Tuple2Serializer.java From tinkerpop with Apache License 2.0 | 4 votes |
@Override public Tuple2<A, B> read(final Kryo kryo, final Input input, final Class<Tuple2<A, B>> clazz) { return new Tuple2(kryo.readClassAndObject(input), kryo.readClassAndObject(input)); }
Example 17
Source File: Tuple3Serializer.java From tinkerpop with Apache License 2.0 | 4 votes |
@Override public Tuple3<A, B, C> read(final Kryo kryo, final Input input, final Class<Tuple3<A, B, C>> clazz) { return new Tuple3(kryo.readClassAndObject(input), kryo.readClassAndObject(input), kryo.readClassAndObject(input)); }
Example 18
Source File: HugeGryoModule.java From hugegraph with Apache License 2.0 | 4 votes |
@Override public Optional<?> read(Kryo kryo, Input input, Class<Optional<?>> c) { Object value = kryo.readClassAndObject(input); return value == null ? Optional.empty() : Optional.of(value); }