@Override
 public void writeAFP(OutputStream os, AFPParserConfiguration config) throws IOException {
   os.write(UtilBinaryDecoding.shortToByteArray(startingCopyNumber, 2));
   os.write(UtilBinaryDecoding.shortToByteArray(endingCopyNumber, 2));
   os.write(reserved4);
   os.write(mediumModificationControlIdentifier);
 }
 @Override
 public void decodeAFP(byte[] sfData, int offset, int length, AFPParserConfiguration config)
     throws AFPParserException {
   checkDataLength(sfData, offset, length, 6);
   startingCopyNumber = UtilBinaryDecoding.parseShort(sfData, offset, 2);
   endingCopyNumber = UtilBinaryDecoding.parseShort(sfData, offset + 2, 2);
   reserved4 = sfData[4];
   mediumModificationControlIdentifier = sfData[5];
 }
  @Override
  public void decodeAFP(byte[] sfData, int offset, int length, AFPParserConfiguration config)
      throws AFPParserException {
    checkDataLength(sfData, offset, length, 13);

    defaultGraphicCharacterGlobalID = new String(sfData, 0, 8, cpIBM500);
    defaultCharacterUseFlags = DefaultCharacterUseFlag.valueOf(sfData[8] & 0xFF);
    cpiRepeatingGroupLength = CPIRepeatingGroupLength.valueOf(sfData[9] & 0xFF);
    spaceCharacterSectionNumber = UtilBinaryDecoding.parseShort(sfData, offset + 10, 1);
    spaceCharacterCodePoint = UtilBinaryDecoding.parseShort(sfData, offset + 11, 1);
    codePageUseFlags = CodePageUseFlag.valueOf(sfData[12] & 0xFF);
    if (cpiRepeatingGroupLength == CPIRepeatingGroupLength.SingleByteCodePageUnicodeScalarValues
        || cpiRepeatingGroupLength
            == CPIRepeatingGroupLength.DoubleByteCodePageUnicodeScalarValues) {
      unicodeScalarValue = UtilBinaryDecoding.parseLong(sfData, 13, 4);
    }
  }
  @Override
  public void writeAFP(OutputStream os, AFPParserConfiguration config) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    baos.write(
        UtilCharacterEncoding.stringToByteArray(
            defaultGraphicCharacterGlobalID, cpIBM500, 8, Constants.EBCDIC_ID_FILLER));
    baos.write(DefaultCharacterUseFlag.toByte(defaultCharacterUseFlags));
    baos.write(cpiRepeatingGroupLength.val);
    baos.write(UtilBinaryDecoding.shortToByteArray(spaceCharacterSectionNumber, 1));
    baos.write(UtilBinaryDecoding.shortToByteArray(spaceCharacterCodePoint, 1));
    baos.write(CodePageUseFlag.toByte(codePageUseFlags));
    if (cpiRepeatingGroupLength == CPIRepeatingGroupLength.SingleByteCodePageUnicodeScalarValues
        || cpiRepeatingGroupLength
            == CPIRepeatingGroupLength.DoubleByteCodePageUnicodeScalarValues) {
      baos.write(UtilBinaryDecoding.longToByteArray(unicodeScalarValue, 4));
    }

    writeFullStructuredField(os, baos.toByteArray());
  }