private static int byteCompaction(int mode,int[] codewords,Charset encoding,int codeIndex,StringBuilder result){
  ByteArrayOutputStream decodedBytes=new ByteArrayOutputStream();
  if (mode == BYTE_COMPACTION_MODE_LATCH) {
    int count=0;
    long value=0;
    int[] byteCompactedCodewords=new int[6];
    boolean end=false;
    int nextCode=codewords[codeIndex++];
    while ((codeIndex < codewords[0]) && !end) {
      byteCompactedCodewords[count++]=nextCode;
      value=900 * value + nextCode;
      nextCode=codewords[codeIndex++];
      if (nextCode == TEXT_COMPACTION_MODE_LATCH || nextCode == BYTE_COMPACTION_MODE_LATCH || nextCode == NUMERIC_COMPACTION_MODE_LATCH || nextCode == BYTE_COMPACTION_MODE_LATCH_6 || nextCode == BEGIN_MACRO_PDF417_CONTROL_BLOCK || nextCode == BEGIN_MACRO_PDF417_OPTIONAL_FIELD || nextCode == MACRO_PDF417_TERMINATOR) {
        codeIndex--;
        end=true;
      }
 else {
        if ((count % 5 == 0) && (count > 0)) {
          for (int j=0; j < 6; ++j) {
            decodedBytes.write((byte)(value >> (8 * (5 - j))));
          }
          value=0;
          count=0;
        }
      }
    }
    if (codeIndex == codewords[0] && nextCode < TEXT_COMPACTION_MODE_LATCH) {
      byteCompactedCodewords[count++]=nextCode;
    }
    for (int i=0; i < count; i++) {
      decodedBytes.write((byte)byteCompactedCodewords[i]);
    }
  }
 else   if (mode == BYTE_COMPACTION_MODE_LATCH_6) {
    int count=0;
    long value=0;
    boolean end=false;
    while (codeIndex < codewords[0] && !end) {
      int code=codewords[codeIndex++];
      if (code < TEXT_COMPACTION_MODE_LATCH) {
        count++;
        value=900 * value + code;
      }
 else {
        if (code == TEXT_COMPACTION_MODE_LATCH || code == BYTE_COMPACTION_MODE_LATCH || code == NUMERIC_COMPACTION_MODE_LATCH || code == BYTE_COMPACTION_MODE_LATCH_6 || code == BEGIN_MACRO_PDF417_CONTROL_BLOCK || code == BEGIN_MACRO_PDF417_OPTIONAL_FIELD || code == MACRO_PDF417_TERMINATOR) {
          codeIndex--;
          end=true;
        }
      }
      if ((count % 5 == 0) && (count > 0)) {
        for (int j=0; j < 6; ++j) {
          decodedBytes.write((byte)(value >> (8 * (5 - j))));
        }
        value=0;
        count=0;
      }
    }
  }
  result.append(new String(decodedBytes.toByteArray(),encoding));
  return codeIndex;
}

private static int byteCompaction ( int mode , int [ ] codewords , Charset encoding , int codeIndex , StringBuilder result ) { ByteArrayOutputStream decodedBytes = new ByteArrayOutputStream ( ) ; if ( mode == BYTE_COMPACTION_MODE_LATCH ) { int count = 0 ; long value = 0 ; int [ ] byteCompactedCodewords = new int [ 6 ] ; boolean end = false ; int nextCode = codewords [ codeIndex ++ ] ; while ( ( codeIndex < codewords [ 0 ] ) && ! end ) { byteCompactedCodewords [ count ++ ] = nextCode ; value = 900 * value + nextCode ; nextCode = codewords [ codeIndex ++ ] ; if ( nextCode == TEXT_COMPACTION_MODE_LATCH || nextCode == BYTE_COMPACTION_MODE_LATCH || nextCode == NUMERIC_COMPACTION_MODE_LATCH || nextCode == BYTE_COMPACTION_MODE_LATCH_6 || nextCode == BEGIN_MACRO_PDF417_CONTROL_BLOCK || nextCode == BEGIN_MACRO_PDF417_OPTIONAL_FIELD || nextCode == MACRO_PDF417_TERMINATOR ) { codeIndex -- ; end = true ; } else { if ( ( count % 5 == 0 ) && ( count > 0 ) ) { for ( int j = 0 ; j < 6 ; ++ j ) { decodedBytes . write ( ( byte ) ( value > > ( 8 * ( 5 - j ) ) ) ) ; } value = 0 ; count = 0 ; } } } if ( codeIndex == codewords [ 0 ] && nextCode < TEXT_COMPACTION_MODE_LATCH ) { byteCompactedCodewords [ count ++ ] = nextCode ; } for ( int i = 0 ; i < count ; i ++ ) { decodedBytes . write ( ( byte ) byteCompactedCodewords [ i ] ) ; } } else if ( mode == BYTE_COMPACTION_MODE_LATCH_6 ) { int count = 0 ; long value = 0 ; boolean end = false ; while ( codeIndex < codewords [ 0 ] && ! end ) { int code = codewords [ codeIndex ++ ] ; if ( code < TEXT_COMPACTION_MODE_LATCH ) { count ++ ; value = 900 * value + code ; } else { if ( code == TEXT_COMPACTION_MODE_LATCH || code == BYTE_COMPACTION_MODE_LATCH || code == NUMERIC_COMPACTION_MODE_LATCH || code == BYTE_COMPACTION_MODE_LATCH_6 || code == BEGIN_MACRO_PDF417_CONTROL_BLOCK || code == BEGIN_MACRO_PDF417_OPTIONAL_FIELD || code == MACRO_PDF417_TERMINATOR ) { codeIndex -- ; end = true ; } } if ( ( count % 5 == 0 ) && ( count > 0 ) ) { for ( int j = 0 ; j < 6 ; ++ j ) { decodedBytes . write ( ( byte ) ( value > > ( 8 * ( 5 - j ) ) ) ) ; } value = 0 ; count = 0 ; } } } result . append ( new String ( decodedBytes . toByteArray ( ) , encoding ) ) ; return codeIndex ; }
byte compaction mode ( see 5 . 4 . 3 ) permits all 256 possible 8 - bit byte values to be encoded . this includes all ascii characters value 0 to 127 inclusive and provides for international character set support .
