use of com.hortonworks.registries.schemaregistry.serdes.avro.exceptions.AvroRetryableException in project registry by hortonworks.
the class AvroSnapshotDeserializer method retrieveProtocolId.
protected byte retrieveProtocolId(InputStream inputStream) throws SerDesException {
// first byte is protocol version/id.
// protocol format:
// 1 byte : protocol version
byte protocolId;
try {
protocolId = (byte) inputStream.read();
} catch (IOException e) {
throw new AvroRetryableException(e);
}
if (protocolId == -1) {
throw new AvroException("End of stream reached while trying to read protocol id");
}
checkProtocolHandlerExists(protocolId);
return protocolId;
}
use of com.hortonworks.registries.schemaregistry.serdes.avro.exceptions.AvroRetryableException in project registry by hortonworks.
the class ConfluentProtocolHandler method handleSchemaVersionDeserialization.
@Override
public SchemaIdVersion handleSchemaVersionDeserialization(InputStream inputStream) {
ByteBuffer byteBuffer = ByteBuffer.allocate(4);
try {
inputStream.read(byteBuffer.array());
} catch (IOException e) {
throw new AvroRetryableException(e);
}
int schemaVersionId = byteBuffer.getInt();
return new SchemaIdVersion((long) schemaVersionId);
}
use of com.hortonworks.registries.schemaregistry.serdes.avro.exceptions.AvroRetryableException in project registry by hortonworks.
the class SchemaMetadataIdProtocolHandler method handleSchemaVersionDeserialization.
@Override
public SchemaIdVersion handleSchemaVersionDeserialization(InputStream inputStream) {
// 8 bytes : schema metadata Id
// 4 bytes : schema version
ByteBuffer byteBuffer = ByteBuffer.allocate(12);
try {
inputStream.read(byteBuffer.array());
} catch (IOException e) {
throw new AvroRetryableException(e);
}
long schemaMetadataId = byteBuffer.getLong();
int schemaVersion = byteBuffer.getInt();
return new SchemaIdVersion(schemaMetadataId, schemaVersion);
}
use of com.hortonworks.registries.schemaregistry.serdes.avro.exceptions.AvroRetryableException in project registry by hortonworks.
the class SchemaVersionIdAsLongProtocolHandler method doHandleSchemaVersionSerialization.
@Override
public void doHandleSchemaVersionSerialization(OutputStream outputStream, SchemaIdVersion schemaIdVersion) throws SerDesException {
try {
Long versionId = schemaIdVersion.getSchemaVersionId();
outputStream.write(ByteBuffer.allocate(8).putLong(versionId).array());
} catch (IOException e) {
throw new AvroRetryableException(e);
}
}
use of com.hortonworks.registries.schemaregistry.serdes.avro.exceptions.AvroRetryableException in project registry by hortonworks.
the class DefaultAvroSerDesHandler method handlePayloadSerialization.
@Override
public void handlePayloadSerialization(OutputStream outputStream, Object input) {
try {
Schema schema = AvroUtils.computeSchema(input);
Schema.Type schemaType = schema.getType();
if (Schema.Type.BYTES.equals(schemaType)) {
// incase of byte arrays, no need to go through avro as there is not much to optimize and avro is expecting
// the payload to be ByteBuffer instead of a byte array
outputStream.write((byte[]) input);
} else if (Schema.Type.STRING.equals(schemaType)) {
// get UTF-8 bytes and directly send those over instead of using avro.
outputStream.write(input.toString().getBytes("UTF-8"));
} else {
BinaryEncoder encoder = EncoderFactory.get().binaryEncoder(outputStream, null);
DatumWriter<Object> writer;
boolean isSpecificRecord = input instanceof SpecificRecord;
if (isSpecificRecord) {
writer = new SpecificDatumWriter<>(schema);
} else {
writer = new GenericDatumWriter<>(schema);
}
writer.write(input, encoder);
encoder.flush();
}
} catch (IOException e) {
throw new AvroRetryableException(e);
} catch (RuntimeException e) {
throw new AvroException(e);
}
}
Aggregations