Package co.cask.cdap.internal.io

Examples of co.cask.cdap.internal.io.ByteBufferInputStream


    SchemaHash schemaHash = new SchemaHash(buffer);
    Preconditions.checkArgument(schemaHash.equals(STREAM_EVENT_SCHEMA.getSchemaHash()),
                                "Schema from payload not matching StreamEvent schema.");

    Decoder decoder = new BinaryDecoder(new ByteBufferInputStream(buffer));

    try {
      StreamEventData data = StreamEventDataCodec.decode(decoder);

      // Read the timestamp
View Full Code Here


    public Builder withBody(final ByteBuffer body) {
      this.body = new InputSupplier<InputStream>() {
        @Override
        public InputStream getInput() throws IOException {
          return new ByteBufferInputStream(body.duplicate());
        }
      };
      return this;
    }
View Full Code Here

        ByteBuffer buffer = ByteBuffer.wrap(content);
        SchemaHash schemaHash = new SchemaHash(buffer);
        Preconditions.checkArgument(schemaHash.equals(StreamEventDataCodec.STREAM_DATA_SCHEMA.getSchemaHash()),
                                    "Schema from payload not matching with StreamEventData schema.");

        Decoder decoder = new BinaryDecoder(new ByteBufferInputStream(buffer));
        // In old schema, timestamp is not recorded.
        builder.add(new DefaultStreamEvent(StreamEventDataCodec.decode(decoder), 0));
      }
    }
    final List<StreamEvent> events = builder.build();
View Full Code Here

  }

  private <T> Function<ByteBuffer, T> createInputDatumDecoder(final TypeToken<T> dataType, final Schema schema,
                                                              final SchemaCache schemaCache) {
    final ReflectionDatumReader<T> datumReader = new ReflectionDatumReader<T>(schema, dataType);
    final ByteBufferInputStream byteBufferInput = new ByteBufferInputStream(null);
    final BinaryDecoder decoder = new BinaryDecoder(byteBufferInput);

    return new Function<ByteBuffer, T>() {
      @Nullable
      @Override
      public T apply(ByteBuffer input) {
        byteBufferInput.reset(input);
        try {
          final Schema sourceSchema = schemaCache.get(input);
          Preconditions.checkNotNull(sourceSchema, "Fail to find source schema.");
          return datumReader.read(decoder, sourceSchema);
        } catch (IOException e) {
View Full Code Here

  }

  @Override
  public void onReceived(Iterator<FetchedMessage> messages) {
    // Decode the metrics records.
    final ByteBufferInputStream is = new ByteBufferInputStream(null);
    List<MetricsRecord> records = ImmutableList.copyOf(
      Iterators.filter(Iterators.transform(messages, new Function<FetchedMessage, MetricsRecord>() {
      @Override
      public MetricsRecord apply(FetchedMessage input) {
        try {
          return recordReader.read(new BinaryDecoder(is.reset(input.getPayload())), recordSchema);
        } catch (IOException e) {
          LOG.warn("Failed to decode message to MetricsRecord. Skipped. {}", e.getMessage(), e);
          return null;
        }
      }
View Full Code Here

TOP

Related Classes of co.cask.cdap.internal.io.ByteBufferInputStream

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.