Cob2AvroSpecificConverter extends
        AbstractCob2ObjectConverter < SpecificRecord > { public FromHostResult < SpecificRecord > convert(byte[] hostData, int start, int length) { FromHostResult < GenericRecord > result = converter.convert(hostData, start, length); if (result.getValue() == null) { return null; } this.specificRecord = (SpecificRecord) SpecificData.get().deepCopy( result.getValue().getSchema(), result.getValue()); return new FromHostResult < SpecificRecord >( result.getBytesProcessed(), specificRecord); } private  Cob2AvroSpecificConverter(Builder builder); FromHostResult < SpecificRecord > convert(byte[] hostData,
            int start, int length); boolean isValid(byte[] hostData); boolean isValid(byte[] hostData, int start, int length); SpecificRecord getSpecificRecord(); int getHostBytesLen();  }
@Test public void testConvertFlat01() { Cob2AvroSpecificConverter converter = new Cob2AvroSpecificConverter.Builder() .cobolComplexType(new legstar.test.avro.flat01.CobolFlat01Record()) .schema(getSchema("flat01")) .build(); FromHostResult < SpecificRecord > result = converter.convert( HexUtils.decodeHex("F0F0F1F0F4F3D5C1D4C5F0F0F0F0F4F3404040404040404040400215000F")); assertEquals(30, result.getBytesProcessed()); check(avro2Json(result.getValue()), "result.json"); }
@Test public void testConvertRdef01Strategy() { FromCobolChoiceStrategy customChoiceStrategy = new FromCobolChoiceStrategy() { public CobolType choose(String choiceFieldName, CobolChoiceType choiceType, Map < String, Object > variables, byte[] hostData, int start, int length) { int select = ((Number) variables.get("comSelect")) .intValue(); switch (select) { case 0: return choiceType.getAlternatives().get( "ComDetail1"); case 1: return choiceType.getAlternatives().get( "ComDetail2"); default: return null; } } public Set < String > getVariableNames() { Set < String > variables = new HashSet < String >(); variables.add("comSelect"); return variables; } }; Cob2AvroSpecificConverter converter = new Cob2AvroSpecificConverter.Builder() .cobolComplexType(new legstar.test.avro.rdef01.CobolRdef01Record()) .schema(getSchema("rdef01")) .customChoiceStrategy(customChoiceStrategy) .build(); FromHostResult < SpecificRecord > result = converter.convert( HexUtils.decodeHex("00010250000F40404040404000010260000F404040404040")); assertEquals(6, result.getBytesProcessed()); check(avro2Json(result.getValue()), "result.json"); }