private static void decodeBase256Segment(BitSource bits,StringBuilder result,Collection<byte[]> byteSegments) throws FormatException {
  int codewordPosition=1 + bits.getByteOffset();
  int d1=unrandomize255State(bits.readBits(8),codewordPosition++);
  int count;
  if (d1 == 0) {
    count=bits.available() / 8;
  }
 else   if (d1 < 250) {
    count=d1;
  }
 else {
    count=250 * (d1 - 249) + unrandomize255State(bits.readBits(8),codewordPosition++);
  }
  if (count < 0) {
    throw FormatException.getFormatInstance();
  }
  byte[] bytes=new byte[count];
  for (int i=0; i < count; i++) {
    if (bits.available() < 8) {
      throw FormatException.getFormatInstance();
    }
    bytes[i]=(byte)unrandomize255State(bits.readBits(8),codewordPosition++);
  }
  byteSegments.add(bytes);
  try {
    result.append(new String(bytes,"ISO8859_1"));
  }
 catch (  UnsupportedEncodingException uee) {
    throw new IllegalStateException("Platform does not support required encoding: " + uee);
  }
}

private static void decodeBase256Segment ( BitSource bits , StringBuilder result , Collection < byte [ ] > byteSegments ) throws FormatException { int codewordPosition = 1 + bits . getByteOffset ( ) ; int d1 = unrandomize255State ( bits . readBits ( 8 ) , codewordPosition ++ ) ; int count ; if ( d1 == 0 ) { count = bits . available ( ) / 8 ; } else if ( d1 < 250 ) { count = d1 ; } else { count = 250 * ( d1 - 249 ) + unrandomize255State ( bits . readBits ( 8 ) , codewordPosition ++ ) ; } if ( count < 0 ) { throw FormatException . getFormatInstance ( ) ; } byte [ ] bytes = new byte [ count ] ; for ( int i = 0 ; i < count ; i ++ ) { if ( bits . available ( ) < 8 ) { throw FormatException . getFormatInstance ( ) ; } bytes [ i ] = ( byte ) unrandomize255State ( bits . readBits ( 8 ) , codewordPosition ++ ) ; } byteSegments . add ( bytes ) ; try { result . append ( new String ( bytes , "ISO8859_1" ) ) ; } catch ( UnsupportedEncodingException uee ) { throw new IllegalStateException ( "Platform does not support required encoding: " + uee ) ; } }
see iso 16022 : 2006 , 5 . 2 . 9 and annex b , b . 2
