private synchronized PrintStream createStream(String header) {
        FileOutputStream newFileStream = null;
        CountingOutputStream newCountingStream = null;
        PrintStream newPrintStream = null;

        File targetLogFile = null;
        long realMaxFileSizeBytes = maxFileSizeBytes;

        // Store the value, and temporarily "disable" log rolling to avoid
        // re-trying to roll the log if the ThreadIdentityManager creates
        // log or trace records. This value is reset in the finally block
        maxFileSizeBytes = 0;

        Object token = ThreadIdentityManager.runAsServer();
        try {
            // Close the existing file
            currentPrintStream.flush();
            if (currentFileStream != null) {
                FileLogUtils.tryToClose(currentFileStream);
            }

            // Get the non-unique file (e.g. trace.log)
            targetLogFile = FileLogUtils.createNewFile(fileLogSet);

            if (targetLogFile != null) {
                try {
                    // create the new file stream -- never append
                    // When asking Erin about the above comment, she could not find a reason for why we would
                    // never use the append flag.  Testing across numerous platforms has shown that using the
                    // append flag does not appear to cause any problems with log creation and log rolling - a
                    // switch to using append = true is being made to address APAR PI57488
                    TextFileOutputStreamFactory fileStreamFactory = TrConfigurator.getFileOutputStreamFactory();
                    newFileStream = fileStreamFactory.createOutputStream(targetLogFile, true);
                    newCountingStream = new CountingOutputStream(newFileStream);
                    newPrintStream = new PrintStream(newCountingStream);
                } catch (IOException e) {
                    // should not happen: we created the new file in createNewFile
                }

                // If both the file and print streams were created successfully,
                // re-assign the active/current streams to point to the new
                // artifacts
                if (newFileStream != null && newCountingStream != null && newPrintStream != null) {

                    // re-assign the current file and print streams
                    setStreamStatus(StreamStatus.ACTIVE, newFileStream, newCountingStream, newPrintStream);
                } else {
                    // something didn't go right along the way...
                    // don't keep spinning trying to create files when you can't
                    setStreamStatus(StreamStatus.CLOSED, null, null, DummyOutputStream.psInstance);
                }
            } else {
                // something didn't go right along the way...
                // don't keep spinning trying to create files when you can't
                setStreamStatus(StreamStatus.CLOSED, null, null, DummyOutputStream.psInstance);
            }
        } finally {
            ThreadIdentityManager.reset(token);
            maxFileSizeBytes = realMaxFileSizeBytes;
            if (currentStatus == StreamStatus.ACTIVE && header != null) {
                currentPrintStream.println(header);
            }
        }

        return currentPrintStream;
    }
private synchronized PrintStream createStream ( String header ) { FileOutputStream newFileStream = null ; CountingOutputStream newCountingStream = null ; PrintStream newPrintStream = null ; File targetLogFile = null ; long realMaxFileSizeBytes = maxFileSizeBytes ; maxFileSizeBytes = 0 ; Object token = ThreadIdentityManager . runAsServer ( ) ; try { currentPrintStream . flush ( ) ; if ( currentFileStream != null ) { FileLogUtils . tryToClose ( currentFileStream ) ; } targetLogFile = FileLogUtils . createNewFile ( fileLogSet ) ; if ( targetLogFile != null ) { try { TextFileOutputStreamFactory fileStreamFactory = TrConfigurator . getFileOutputStreamFactory ( ) ; newFileStream = fileStreamFactory . createOutputStream ( targetLogFile , true ) ; newCountingStream = new CountingOutputStream ( newFileStream ) ; newPrintStream = new PrintStream ( newCountingStream ) ; } catch ( IOException e ) { } if ( newFileStream != null && newCountingStream != null && newPrintStream != null ) { setStreamStatus ( StreamStatus . ACTIVE , newFileStream , newCountingStream , newPrintStream ) ; } else { setStreamStatus ( StreamStatus . CLOSED , null , null , DummyOutputStream . psInstance ) ; } } else { setStreamStatus ( StreamStatus . CLOSED , null , null , DummyOutputStream . psInstance ) ; } } finally { ThreadIdentityManager . reset ( token ) ; maxFileSizeBytes = realMaxFileSizeBytes ; if ( currentStatus == StreamStatus . ACTIVE && header != null ) { currentPrintStream . println ( header ) ; } } return currentPrintStream ; }
@return a new print stream