question: private static void decodeTextSegment ( BitSource bits , StringBuilder result ) throws FormatException { boolean upperShift = false ; int [ ] cValues = new int [ 3 ] ; int shift = 0 ; do { if ( bits . available ( ) == 8 ) { return ; } int firstByte = bits . readBits ( 8 ) ; if ( firstByte == 254 ) { return ; } parseTwoBytes ( firstByte , bits . readBits ( 8 ) , cValues ) ; for ( int i = 0 ; i < 3 ; i ++ ) { int cValue = cValues [ i ] ; switch ( shift ) { case 0 : if ( cValue < 3 ) { shift = cValue + 1 ; } else if ( cValue < TEXT_BASIC_SET_CHARS . length ) { char textChar = TEXT_BASIC_SET_CHARS [ cValue ] ; if ( upperShift ) { result . append ( ( char ) ( textChar + 128 ) ) ; upperShift = false ; } else { result . append ( textChar ) ; } } else { throw FormatException . getFormatInstance ( ) ; } break ; case 1 : if ( upperShift ) { result . append ( ( char ) ( cValue + 128 ) ) ; upperShift = false ; } else { result . append ( ( char ) cValue ) ; } shift = 0 ; break ; case 2 : if ( cValue < TEXT_SHIFT2_SET_CHARS . length ) { char textChar = TEXT_SHIFT2_SET_CHARS [ cValue ] ; if ( upperShift ) { result . append ( ( char ) ( textChar + 128 ) ) ; upperShift = false ; } else { result . append ( textChar ) ; } } else if ( cValue == 27 ) { result . append ( ( char ) 29 ) ; } else if ( cValue == 30 ) { upperShift = true ; } else { throw FormatException . getFormatInstance ( ) ; } shift = 0 ; break ; case 3 : if ( cValue < TEXT_SHIFT3_SET_CHARS . length ) { char textChar = TEXT_SHIFT3_SET_CHARS [ cValue ] ; if ( upperShift ) { result . append ( ( char ) ( textChar + 128 ) ) ; upperShift = false ; } else { result . append ( textChar ) ; } shift = 0 ; } else { throw FormatException . getFormatInstance ( ) ; } break ; default : throw FormatException . getFormatInstance ( ) ; } } } while ( bits . available ( ) > 0 ) ; }
target:  See ISO 16022:2006, 5.2.6 and Annex C, Table C.2