public static final PrintWriter openPrintWriter()

in src/main/java/org/apache/datasketches/Files.java [757:783]


  public static final PrintWriter openPrintWriter(final String fileName) {
    File file = null;
    PrintWriter pw = null;
    if (fileName != null && !fileName.isEmpty()) {
      file = new File(fileName);
      if (file.isFile()) {
        file.delete(); //remove old file if it exists
      } else {
        try {
          file.createNewFile();
        } catch (final Exception e) {
          throw new RuntimeException("Cannot create file: " + fileName + LS + e);
        }
      }
      final BufferedWriter bw;
      try {
        final FileOutputStream fos = new FileOutputStream(file, true);
        final OutputStreamWriter osw = new OutputStreamWriter(fos, Charset.defaultCharset()); //LEAK?
        bw = new BufferedWriter(osw, 8192); //LEAK?
      } catch (final IOException e) {
        // never opened, so don't close it.
        throw new RuntimeException("Could not create: " + file.getPath() + LS + e);
      }
      pw = new PrintWriter(bw);
    }
    return pw;
  }