### Question:
GenericData { public int compare(Object o1, Object o2, Schema s) { return compare(o1, o2, s, false); } GenericData();  GenericData(ClassLoader classLoader); static void setStringType(Schema s, StringType stringType); static GenericData get(); ClassLoader getClassLoader(); Collection<Conversion<?>> getConversions(); void addLogicalTypeConversion(Conversion<?> conversion); @SuppressWarnings("unchecked") Conversion<T> getConversionByClass(Class<T> datumClass); @SuppressWarnings("unchecked") Conversion<T> getConversionByClass(Class<T> datumClass, LogicalType logicalType); @SuppressWarnings("unchecked") Conversion<Object> getConversionFor(LogicalType logicalType); GenericData setFastReaderEnabled(boolean flag); boolean isFastReaderEnabled(); FastReaderBuilder getFastReaderBuilder(); DatumReader createDatumReader(Schema schema); DatumReader createDatumReader(Schema writer, Schema reader); DatumWriter createDatumWriter(Schema schema); boolean validate(Schema schema, Object datum); String toString(Object datum); Schema induce(Object datum); void setField(Object record, String name, int position, Object value); Object getField(Object record, String name, int position); int resolveUnion(Schema union, Object datum); int hashCode(Object o, Schema s); int compare(Object o1, Object o2, Schema s); @SuppressWarnings({ "unchecked" }) Object getDefaultValue(Field field); @SuppressWarnings({ "rawtypes", "unchecked" }) T deepCopy(Schema schema, T value); Object createFixed(Object old, Schema schema); Object createFixed(Object old, byte[] bytes, Schema schema); Object createEnum(String symbol, Schema schema); Object newRecord(Object old, Schema schema); Object createString(Object value); Object newArray(Object old, int size, Schema schema); Object newMap(Object old, int size); InstanceSupplier getNewRecordSupplier(Schema schema); static final String STRING_PROP; static final String FAST_READER_PROP; }### Answer:
@Test public void testCompare() { Field integerField = new Field("test", Schema.create(Type.INT), null, null); List<Field> fields = new ArrayList<>(); fields.add(integerField); Schema record = Schema.createRecord("test", null, null, false); record.setFields(fields); ByteArrayOutputStream b1 = new ByteArrayOutputStream(5); ByteArrayOutputStream b2 = new ByteArrayOutputStream(5); BinaryEncoder b1Enc = EncoderFactory.get().binaryEncoder(b1, null); BinaryEncoder b2Enc = EncoderFactory.get().binaryEncoder(b2, null); Record testDatum1 = new Record(record); testDatum1.put(0, 1); Record testDatum2 = new Record(record); testDatum2.put(0, 2); GenericDatumWriter<Record> gWriter = new GenericDatumWriter<>(record); Integer start1 = 0, start2 = 0; try { gWriter.write(testDatum1, b1Enc); b1Enc.flush(); start1 = b1.size(); gWriter.write(testDatum1, b1Enc); b1Enc.flush(); b1.close(); gWriter.write(testDatum2, b2Enc); b2Enc.flush(); start2 = b2.size(); gWriter.write(testDatum2, b2Enc); b2Enc.flush(); b2.close(); assertEquals(-1, BinaryData.compare(b1.toByteArray(), start1, b2.toByteArray(), start2, record)); } catch (IOException e) { fail("IOException while writing records to output stream."); } }