Search in sources :

Example 1 with AWSSchemaRegistryException

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;
}
Also used : AWSSchemaRegistryException(com.amazonaws.services.schemaregistry.exception.AWSSchemaRegistryException) MutableByteArrayInputStream(org.apache.flink.formats.avro.utils.MutableByteArrayInputStream) SchemaParseException(org.apache.avro.SchemaParseException) Schema(org.apache.avro.Schema) Parser(org.apache.avro.Schema.Parser)

Aggregations

AWSSchemaRegistryException (com.amazonaws.services.schemaregistry.exception.AWSSchemaRegistryException)1 Schema (org.apache.avro.Schema)1 Parser (org.apache.avro.Schema.Parser)1 SchemaParseException (org.apache.avro.SchemaParseException)1 MutableByteArrayInputStream (org.apache.flink.formats.avro.utils.MutableByteArrayInputStream)1