Package com.esotericsoftware.kryo.io

Examples of com.esotericsoftware.kryo.io.Input


    public RequestMessage deserializeRequest(final ByteBuf msg) throws SerializationException {
        try {
            final Kryo kryo = kryoThreadLocal.get();
            final byte[] payload = new byte[msg.readableBytes()];
            msg.readBytes(payload);
            try (final Input input = new Input(payload)) {
                final Map<String, Object> requestData = (Map<String, Object>) kryo.readClassAndObject(input);
                final RequestMessage.Builder builder = RequestMessage.build((String) requestData.get(SerTokens.TOKEN_OP))
                        .overrideRequestId((UUID) requestData.get(SerTokens.TOKEN_REQUEST))
                        .processor((String) requestData.get(SerTokens.TOKEN_PROCESSOR));
                final Map<String, Object> args = (Map<String, Object>) requestData.get(SerTokens.TOKEN_ARGS);
View Full Code Here


    @Override
    public Iterator<Vertex> readVertices(final InputStream inputStream, final Direction direction,
                                         final Function<DetachedVertex, Vertex> vertexMaker,
                                         final Function<DetachedEdge, Edge> edgeMaker) throws IOException {
        final Input input = new Input(inputStream);
        return new Iterator<Vertex>() {
            @Override
            public boolean hasNext() {
                return !input.eof();
            }

            @Override
            public Vertex next() {
                try {
View Full Code Here

        };
    }

    @Override
    public Edge readEdge(final InputStream inputStream, final Function<DetachedEdge, Edge> edgeMaker) throws IOException {
        final Input input = new Input(inputStream);
        this.headerReader.read(kryo, input);
        final Object o = kryo.readClassAndObject(input);
        return edgeMaker.apply((DetachedEdge) o);
    }
View Full Code Here

        return readVertex(inputStream, null, vertexMaker, null);
    }

    @Override
    public Vertex readVertex(final InputStream inputStream, final Direction direction, Function<DetachedVertex, Vertex> vertexMaker, final Function<DetachedEdge, Edge> edgeMaker) throws IOException {
        final Input input = new Input(inputStream);
        return readVertex(direction, vertexMaker, edgeMaker, input);
    }
View Full Code Here

    }

    @Override
    public void readGraph(final InputStream inputStream, final Graph graphToWriteTo) throws IOException {
        this.counter.set(0);
        final Input input = new Input(inputStream);
        this.headerReader.read(kryo, input);

        final BatchGraph graph;
        try {
            // will throw an exception if not constructed properly
            graph = BatchGraph.build(graphToWriteTo)
                    .vertexIdKey(vertexIdKey)
                    .edgeIdKey(edgeIdKey)
                    .bufferSize(batchSize).create();
        } catch (Exception ex) {
            throw new IOException("Could not instantiate BatchGraph wrapper", ex);
        }

        try (final Output output = new Output(new FileOutputStream(tempFile))) {
            final boolean supportedMemory = input.readBoolean();
            if (supportedMemory) {
                // if the graph that serialized the data supported sideEffects then the sideEffects needs to be read
                // to advance the reader forward.  if the graph being read into doesn't support the sideEffects
                // then we just setting the data to sideEffects.
                final Map<String, Object> memMap = (Map<String, Object>) kryo.readObject(input, HashMap.class);
                if (graphToWriteTo.features().graph().variables().supportsVariables()) {
                    final Graph.Variables variables = graphToWriteTo.variables();
                    memMap.forEach(variables::set);
                }
            }

            final boolean hasSomeVertices = input.readBoolean();
            if (hasSomeVertices) {
                while (!input.eof()) {
                    final List<Object> vertexArgs = new ArrayList<>();
                    final DetachedVertex current = (DetachedVertex) kryo.readClassAndObject(input);
                    appendToArgList(vertexArgs, T.id, current.id());
                    appendToArgList(vertexArgs, T.label, current.label());

                    final Vertex v = graph.addVertex(vertexArgs.toArray());
                    current.iterators().propertyIterator().forEachRemaining(p -> createVertexProperty(graphToWriteTo, v, p, false));
                    current.iterators().hiddenPropertyIterator().forEachRemaining(p -> createVertexProperty(graphToWriteTo, v, p, true));

                    // the gio file should have been written with a direction specified
                    final boolean hasDirectionSpecified = input.readBoolean();
                    final Direction directionInStream = kryo.readObject(input, Direction.class);
                    final Direction directionOfEdgeBatch = kryo.readObject(input, Direction.class);

                    // graph serialization requires that a direction be specified in the stream and that the
                    // direction of the edges be OUT
                    if (!hasDirectionSpecified || directionInStream != Direction.OUT || directionOfEdgeBatch != Direction.OUT)
                        throw new IllegalStateException(String.format("Stream must specify edge direction and that direction must be %s", Direction.OUT));

                    // if there are edges then read them to end and write to temp, otherwise read what should be
                    // the vertex terminator
                    if (!input.readBoolean())
                        kryo.readClassAndObject(input);
                    else
                        readToEndOfEdgesAndWriteToTemp(input, output);
                }
            }
        } catch (Exception ex) {
            throw new IOException(ex);
        }
        // done writing to temp

        // start reading in the edges now from the temp file
        try (final Input edgeInput = new Input(new FileInputStream(tempFile))) {
            readFromTempEdges(edgeInput, graph);
            graph.tx().commit();
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new IOException(ex);
View Full Code Here

    kryo.writeClassAndObject(output, new MeasurePointData("1111"));
    kryo.writeClassAndObject(output, new MeasurePointData("2222"));
    kryo.writeClassAndObject(output, new MeasurePointData("2222"));
    kryo.writeClassAndObject(output, new MeasurePointData("1111"));
   
    Input input = new Input(output.getBuffer());
    assertEquals("1111", ((MeasurePointData)kryo.readClassAndObject(input)).getMeasurePointId());
    assertEquals("1111", ((MeasurePointData)kryo.readClassAndObject(input)).getMeasurePointId());
    assertEquals("1111", ((MeasurePointData)kryo.readClassAndObject(input)).getMeasurePointId());
    assertEquals("2222", ((MeasurePointData)kryo.readClassAndObject(input)).getMeasurePointId());
    assertEquals("2222", ((MeasurePointData)kryo.readClassAndObject(input)).getMeasurePointId());
View Full Code Here

  }
 
  @Test
  public void test_read(){
    Kryo kryo = Mockito.mock(Kryo.class);
    Input input = Mockito.mock(Input.class);
 
    Mockito.when(input.readString()).thenReturn("111");
    Mockito.when(input.readInt()).thenReturn(-1);
    MeasurePointIdSerializer measurePointIdSerializer = new MeasurePointIdSerializer();
    assertEquals("111", measurePointIdSerializer.read(kryo, input, String.class));
   
    Mockito.when(input.readString()).thenReturn("?");
    Mockito.when(input.readInt()).thenReturn(0);
    assertEquals("111", measurePointIdSerializer.read(kryo, input, String.class));
   
    Mockito.when(input.readString()).thenReturn("?");
    Mockito.when(input.readInt()).thenReturn(0);
    assertEquals("111", measurePointIdSerializer.read(kryo, input, String.class));
   
    Mockito.when(input.readString()).thenReturn("222");
    Mockito.when(input.readInt()).thenReturn(-1);
    assertEquals("222", measurePointIdSerializer.read(kryo, input, String.class));
   
    Mockito.when(input.readString()).thenReturn("?");
    Mockito.when(input.readInt()).thenReturn(1);
    assertEquals("222", measurePointIdSerializer.read(kryo, input, String.class));
  }
View Full Code Here

    long latestTimestamp = b.getLong(MonitoringDataStorage.LATEST_POSITION);
    assertEquals(42, earliestTimestamp);
    assertEquals(43, latestTimestamp);
   
    Kryo kryo = new Kryo();
    Input input = new Input(new ByteBufferInputStream(b));
    input.setPosition(MonitoringDataStorage.FIRST_RECORD_POSITION);
    assertEquals("blabla1",((MonitoringDataDummy)kryo.readClassAndObject(input)).value);
    assertEquals("blabla2",((MonitoringDataDummy)kryo.readClassAndObject(input)).value);
    assertNull(kryo.readClassAndObject(input));
    b.putInt(MonitoringDataStorage.LIMIT_POSITION, b.position());
    b.position(0);
View Full Code Here

      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

    E bean = null;

    try {
      Class<?> c = Class.forName(classname);
      ByteArrayInputStream stream = new ByteArrayInputStream(getDatas());
      Input input = new Input(stream);
      bean = (E) k.readObjectOrNull(input, c);
      input.close(); // Also calls output.flush()
    } catch (ClassNotFoundException e) {
      Logger.getLogger(getClass()).error(
          "Classe non trouvé: " + classname, e);
    } catch (IOException e) {
      Logger.getLogger(getClass()).error("Erreur réseaux", e);
View Full Code Here

TOP

Related Classes of com.esotericsoftware.kryo.io.Input

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.