private Writer nextWriter() throws IOException {
        close();
        int maxAttempts = 1000;
        while (maxAttempts-- > 0) {
            String name = prefix + "-" + generation++;
            File f = new File(name);

            // make sure directory exists
            File dir = f.getParentFile();
            if (! dir.exists()) {
                dir.mkdirs();
            }

            // if compressed version exists we skip it
            if ((new File(name + ".gz").exists())
                    || (new File(name + ".bz2").exists())) {
                continue;
            }

            // if file does not exist we have a winner
            if (! f.exists()) {
                log.log(Level.FINE, () -> "nextWriter, new file: " + name);
                currentFile = f;
                bytesWritten = 0;
                return new FileWriter(f, true);
            }

            // just skip over directories for now
            if (! f.isFile()) {
                log.fine("nextWriter, " + name + " is a directory, skipping");
                continue;
            }

            // if the size is < resumeSizeLimit then we open it
            if (f.length() < resumeLimitSize) {
                log.fine("nextWriter, resuming " + name + ", length was " + f.length());
                currentFile = f;
                bytesWritten = f.length();
                return new FileWriter(f, true);
            } else {

                log.fine("nextWriter, not resuming " + name
                                 + " because it is bigger than "
                                 + resumeLimit
                                 + " percent of max");
            }
        }

        throw new RuntimeException("Unable to create next log file");
    }
This is called when we want to rotate the output file to
start writing the next file.  There are two scenarios when
we do this:
<UL>
<LI> initial case, when we have no file
<LI> when we have filled the file and want to rotate it
</UL>
logserver/src/main/java/com/yahoo/logserver/handlers/archive/LogWriter.java