code: 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;
              }
          }
      }
docs: Writes a string piece by piece to file
  
  @param text       to input
  @param tempFileIn input
  @throws IOException exception when writing