本文整理汇总了Java中org.apache.avro.generic.GenericContainer.getSchema方法的典型用法代码示例。如果您正苦于以下问题:Java GenericContainer.getSchema方法的具体用法?Java GenericContainer.getSchema怎么用?Java GenericContainer.getSchema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.avro.generic.GenericContainer
的用法示例。
在下文中一共展示了GenericContainer.getSchema方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decodeFromTransport
import org.apache.avro.generic.GenericContainer; //导入方法依赖的package包/类
/**
* Decode the message from the transport.
*
* @param input The FinancialForce Orizuru Avro Transport message from which to decode the message.
* @throws OrizuruConsumerException Exception thrown if decoding the message fails.
*/
public void decodeFromTransport(Transport input) throws OrizuruConsumerException {
try {
String messageSchemaName = input.getMessageSchemaName().toString();
Class<?> avroClass = Class.forName(messageSchemaName);
Constructor<?> constructor = avroClass.getConstructor();
GenericContainer container = (GenericContainer) constructor.newInstance();
this.schema = container.getSchema();
ByteBuffer messageBuffer = input.getMessageBuffer();
this.data = messageBuffer.array();
} catch (Exception ex) {
throw new DecodeMessageException(ex);
}
}
示例2: objectToByteBuffer
import org.apache.avro.generic.GenericContainer; //导入方法依赖的package包/类
@Override
public byte[] objectToByteBuffer(Object o) throws IOException{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
if (o instanceof GenericContainer) {
oos.write(RECORD);
GenericContainer container = (GenericContainer) o;
oos.writeObject((container.getSchema().getFullName()));
DatumWriter<GenericContainer> datumWriter = new GenericDatumWriter<>(container.getSchema());
BinaryEncoder encoder = EncoderFactory.get().directBinaryEncoder(baos, null);
datumWriter.write(container,encoder);
encoder.flush();
} else if (o instanceof Schema) {
oos.write(SCHEMA);
oos.writeObject(o.toString());
} else {
oos.write(OTHER);
oos.writeObject(o);
}
return baos.toByteArray();
}
示例3: serialize
import org.apache.avro.generic.GenericContainer; //导入方法依赖的package包/类
/**
* Serializes the record as an in-memory representation of a standard Avro file.
*
* <p>That is, the returned bytes include a standard Avro header that contains a magic byte, the
* record's Avro schema (and so on), followed by the byte representation of the record.
*
* <p>Implementation detail: This method uses Avro's {@code DataFileWriter}.
*
* @return Avro-encoded record (bytes) that includes the Avro schema
*/
public byte[] serialize(GenericContainer record) throws IOException {
if (record != null) {
DatumWriter<GenericContainer> datumWriter = new GenericDatumWriter<>(record.getSchema());
ByteArrayOutputStream out = new ByteArrayOutputStream();
DataFileWriter<GenericContainer> writer = new DataFileWriter<>(datumWriter);
writer.create(record.getSchema(), out);
writer.append(record);
writer.close();
out.close();
return out.toByteArray();
} else {
return null;
}
}
示例4: from
import org.apache.avro.generic.GenericContainer; //导入方法依赖的package包/类
@Override
public org.infinispan.query.dsl.QueryBuilder from(Class entityType) {
if (!GenericContainer.class.isAssignableFrom(entityType))
throw new CacheException();
try {
GenericContainer container = (GenericContainer) entityType.newInstance();
Schema schema = container.getSchema();
return new QueryBuilder(cache,this,schema);
} catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace();
}
throw new CacheException();
}
示例5: getSchema
import org.apache.avro.generic.GenericContainer; //导入方法依赖的package包/类
private Schema getSchema(GenericContainer datum, Schema lastSchema) {
Schema schema = datum.getSchema();
if (lastSchema != null && lastSchema != schema) {
throw new MorphlineRuntimeException("Schemas must be identical: " + schema + ", lastSchema: " + lastSchema);
}
return schema;
}
示例6: write
import org.apache.avro.generic.GenericContainer; //导入方法依赖的package包/类
public void write(Kryo kryo, Output output, GenericContainer record) {
String fingerPrint = this.getFingerprint(record.getSchema());
output.writeString(fingerPrint);
GenericDatumWriter<GenericContainer> writer = new GenericDatumWriter<>(record.getSchema());
BinaryEncoder encoder = EncoderFactory
.get()
.directBinaryEncoder(output, null);
try {
writer.write(record, encoder);
} catch (IOException e) {
throw new RuntimeException(e);
}
}