private static void writeChunkBytes ( String text , File tempFileIn ) throws IOException { try ( FileOutputStream writer = new FileOutputStream ( tempFileIn ) ) { int chunk = text . length ( ) ; if ( text . length ( ) > STRING_MAX_SIZE ) { chunk = text . length ( ) / STRING_MAX_SIZE ; } int startString = 0 ; while ( startString < text . length ( ) ) { int endString = startString + chunk ; if ( endString > text . length ( ) ) { endString = text . length ( ) ; } byte [ ] bytes = text . substring ( startString , endString ) . getBytes ( StandardCharsets . UTF_8 ) ; writer . write ( bytes ) ; startString = endString ; } } }
Writes a string piece by piece to file