public void writeFragmentedUTF ( String str ) throws IOException { if ( str . length ( ) <= MAX_LENGTH ) { writeLastUTFFragment ( str ) ; } else { writeUTFFragment ( str . substring ( 0 , MAX_LENGTH ) ) ; writeFragmentedUTF ( str . substring ( MAX_LENGTH ) ) ; } }
The UTF - 8 encoding uses sequences of 1 2 or 3 bytes per character . With he maximal length of the fragment we want to ensure that there are no overflow of 65536 byte sized buffer