private Schema retrieveSchemaFromBytes(byte[] data) {
    ByteArrayInputStream bais = new ByteArrayInputStream(data);
    DatumReader<GenericRecord> reader = new GenericDatumReader<GenericRecord>();

    Schema schema = null;

    try {
      // dfs is AutoCloseable
      @SuppressWarnings("resource")
      DataFileStream<GenericRecord> dfs = new DataFileStream<GenericRecord>(bais, reader);
      schema = dfs.getSchema();
    } catch (IOException ioe) {
      throw new AvroObjectInspectorException("An error occurred retrieving schema from bytes", ioe);
    }

    return schema;
  }
Retrieve schema from the given bytes

@return the retrieved {@link Schema schema}
serde/src/java/org/apache/hadoop/hive/serde2/avro/AvroLazyObjectInspector.java