use of com.amazonaws.services.schemaregistry.exception.AWSSchemaRegistryException in project flink by apache.
the class GlueSchemaRegistryInputStreamDeserializer method getSchemaAndDeserializedStream.
/**
* Get schema and remove extra Schema Registry information within input stream.
*
* @param in input stream
* @return schema of object within input stream
* @throws IOException Exception during decompression
*/
public Schema getSchemaAndDeserializedStream(InputStream in) throws IOException {
byte[] inputBytes = new byte[in.available()];
in.read(inputBytes);
in.reset();
MutableByteArrayInputStream mutableByteArrayInputStream = (MutableByteArrayInputStream) in;
String schemaDefinition = glueSchemaRegistryDeserializationFacade.getSchemaDefinition(inputBytes);
byte[] deserializedBytes = glueSchemaRegistryDeserializationFacade.getActualData(inputBytes);
mutableByteArrayInputStream.setBuffer(deserializedBytes);
Schema schema;
try {
Parser schemaParser = new Schema.Parser();
schema = schemaParser.parse(schemaDefinition);
} catch (SchemaParseException e) {
String message = "Error occurred while parsing schema, see inner exception for details.";
throw new AWSSchemaRegistryException(message, e);
}
return schema;
}
Aggregations