Java Code Examples for org.apache.avro.io.BinaryDecoder#isEnd()

The following examples show how to use org.apache.avro.io.BinaryDecoder#isEnd() . 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: GenericSchemaDecoder.java    From DBus with Apache License 2.0 6 votes vote down vote up
/**
 * unwrap the osource generic schema
 *
 * @param input data
 * @return List<GenericData>
 * @throws Exception
 */
public List<GenericData> unwrap(byte[] input) throws Exception {
    BinaryDecoder decoder = getBinaryDecoder(input);
    List<GenericData> list = new LinkedList<>();
    while (!decoder.isEnd()) {
        try {
            GenericRecord record = datumReader.read(null, decoder);
            GenericData schemaBean = new GenericData();
            Utf8 utf8 = (Utf8) record.get(GenericData.TABLE_NAME);
            schemaBean.setTableName(utf8.toString());
            schemaBean.setSchemaHash((Integer) record.get(GenericData.SCHEMA_HASH));
            ByteBuffer buffer = (ByteBuffer) record.get(GenericData.PAYLOAD);
            schemaBean.setPayload(buffer.array());
            list.add(schemaBean);
        } catch (Exception e) {
            throw e;
        }
    }
    logger.trace("message count:" + list.size());
    return list;
}
 
Example 2
Source File: GenericSchemaDecoder.java    From DBus with Apache License 2.0 6 votes vote down vote up
/**
 * unwrap the osource generic schema
 *
 * @param input data
 * @return List<GenericData>
 * @throws Exception
 */
public List<GenericData> unwrap(byte[] input) throws Exception {
    BinaryDecoder decoder = getBinaryDecoder(input);
    List<GenericData> list = new LinkedList<>();
    while (!decoder.isEnd()) {
        try {
            GenericRecord record = datumReader.read(null, decoder);
            GenericData schemaBean = new GenericData();
            Utf8 utf8 = (Utf8) record.get(GenericData.TABLE_NAME);
            schemaBean.setTableName(utf8.toString());
            schemaBean.setSchemaId((Integer) record.get(GenericData.SCHEMA_ID));
            Utf8 offset = (Utf8) record.get(GenericData.OFFSET);
            schemaBean.setOffset(offset.toString());
            ByteBuffer buffer = (ByteBuffer) record.get(GenericData.PAYLOAD);
            schemaBean.setPayload(buffer.array());
            list.add(schemaBean);
        } catch (Exception e) {
            throw e;
        }
    }
    logger.trace("message count:" + list.size());
    return list;
}
 
Example 3
Source File: SecurityTokensReader.java    From reef with Apache License 2.0 6 votes vote down vote up
/**
 * Read tokens from a file and add them to the user's credentials.
 * @param ugi user's credentials to add tokens to.
 * @throws IOException if there are errors in reading the tokens' file.
 */
void addTokensFromFile(final UserGroupInformation ugi) throws IOException {
  LOG.log(Level.FINE, "Reading security tokens from file: {0}", this.securityTokensFile);

  try (FileInputStream stream = new FileInputStream(securityTokensFile)) {
    final BinaryDecoder decoder = decoderFactory.binaryDecoder(stream, null);

    while (!decoder.isEnd()) {
      final SecurityToken token = tokenDatumReader.read(null, decoder);

      final Token<TokenIdentifier> yarnToken = new Token<>(
          token.getKey().array(),
          token.getPassword().array(),
          new Text(token.getKind().toString()),
          new Text(token.getService().toString()));

      LOG.log(Level.FINE, "addToken for {0}", yarnToken.getKind());

      ugi.addToken(yarnToken);
    }
  }
}
 
Example 4
Source File: AvroGenericDeserializer.java    From avro-util with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Iterable<V> deserializeObjects(BinaryDecoder decoder) throws Exception {

    List<V> objects = new ArrayList();
    try {
      while (!decoder.isEnd()) {
        objects.add(datumReader.read(null, decoder));
      }
    } catch (Exception e) {
      throw new RuntimeException("Could not deserialize bytes back into Avro objects", e);
    }

    return objects;
  }
 
Example 5
Source File: GenericSchemaDecoder.java    From DBus with Apache License 2.0 5 votes vote down vote up
/**
 * 解析被generic schema封装的实际数据
 *
 * @param schema  schema对象
 * @param payload 实际数据
 * @return List<GenericRecord>
 * @throws Exception
 */
public List<GenericRecord> decode(Schema schema, byte[] payload) throws Exception {
    logger.trace("Schema:" + schema.toString() + " schema payload:" + new String(payload, "utf-8"));
    List<GenericRecord> list = new LinkedList<>();
    DatumReader<GenericRecord> reader = new GenericDatumReader<>(schema);
    BinaryDecoder decoder = getBinaryDecoder(payload);
    while (!decoder.isEnd()) {
        list.add(reader.read(null, decoder));
    }
    return list;
}
 
Example 6
Source File: GenericSchemaDecoder.java    From DBus with Apache License 2.0 5 votes vote down vote up
/**
 * 解析被generic schema封装的实际数据
 *
 * @param schema  schema对象
 * @param payload 实际数据
 * @return List<GenericRecord>
 * @throws Exception
 */
public List<GenericRecord> decode(Schema schema, byte[] payload, int start, int len) throws Exception {
    logger.trace("Schema:" + schema.toString() + " schema payload:" + new String(payload, "utf-8"));
    List<GenericRecord> list = new LinkedList<>();
    DatumReader<GenericRecord> reader = new GenericDatumReader<>(schema);
    BinaryDecoder decoder = DecoderFactory.get().binaryDecoder(payload, start, len, null);
    while (!decoder.isEnd()) {
        list.add(reader.read(null, decoder));
    }
    return list;
}