code: private void update(int len) throws IOException {
      if (file == null && (memory.getCount() + len > fileThreshold)) {
        File temp = File.createTempFile("FileBackedOutputStream", null);
        if (resetOnFinalize) {
          // Finalizers are not guaranteed to be called on system shutdown;
          // this is insurance.
          temp.deleteOnExit();
        }
        FileOutputStream transfer = new FileOutputStream(temp);
        transfer.write(memory.getBuffer(), 0, memory.getCount());
        transfer.flush();
  
        // We've successfully transferred the data; switch to writing to file
        out = transfer;
        file = temp;
        memory = null;
      }
    }
docs: Checks if writing {@code len} bytes would go over threshold, and switches to file buffering if
  so.