public static void writeUTF ( @ NotNull final OutputStream stream , @ NotNull final String str ) throws IOException { try ( DataOutputStream dataStream = new DataOutputStream ( stream ) ) { int len = str . length ( ) ; if ( len < SINGLE_UTF_CHUNK_SIZE ) { dataStream . writeUTF ( str ) ; } else { int startIndex = 0 ; int endIndex ; do { endIndex = startIndex + SINGLE_UTF_CHUNK_SIZE ; if ( endIndex > len ) { endIndex = len ; } dataStream . writeUTF ( str . substring ( startIndex , endIndex ) ) ; startIndex += SINGLE_UTF_CHUNK_SIZE ; } while ( endIndex < len ) ; } } }
Writes long strings to output stream as several chunks .