Package hec.io

Class HecSwappingOutputStream

java.lang.Object
java.io.OutputStream
hec.io.HecSwappingOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class HecSwappingOutputStream extends OutputStream
static class to print data to a file and to stdout swapping logfiles when they reach a user specified maximum size. The user also specifies how many log files to swap between. Properties can be set through the following properties: logfile.name - String. name of the log file. Default is /tmp/jre.out logfile.count - int. number of logfiles to swap between. Default is 2 logfile.size - int. size logfile will grow to before swapping. Default is 51200 bytes logfile.print - boolean. whether to echo System.out messages to stdout. Default is false.
  • Field Details

    • _logFileNames

      protected String[] _logFileNames
    • _logFileName2

      protected String _logFileName2
    • _logFileSize

      protected long _logFileSize
    • _currentLogFileName

      protected int _currentLogFileName
  • Method Details

    • getOutputStream

      public static HecSwappingOutputStream getOutputStream(String name, int numLogs, int logSize, boolean toConsole) throws IOException
      return the current HecSwappingOutputStream, if one hasn't been created then create it with the specified arguments.
      Parameters:
      name - - name of logfile.
      numLogs - - number of logfile to maintain.
      logSize - - max size of log file before swapping to next logfile. 0 means no swapping
      Throws:
      IOException
    • getOutputStream

      public static HecSwappingOutputStream getOutputStream() throws IOException
      return the current HecSwappingOutputStream, if one hasn't been created then create it with the System properties or defaults if the system properties are not set.
      Throws:
      IOException
    • getLogFileName

      public String getLogFileName()
      get the name of the log file current being written to
    • close

      public void close() throws IOException
      Closes this file output stream and releases any system resources associated with this stream.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class OutputStream
      Throws:
      IOException
    • write

      public void write(byte[] b) throws IOException
      Writes b.length bytes from the specified byte array to this file output stream.
      Overrides:
      write in class OutputStream
      Throws:
      IOException
    • write

      public void write(byte[] b, int off, int len) throws IOException
      Writes len bytes from the specified byte array starting at offset off to this file output stream.
      Overrides:
      write in class OutputStream
      Throws:
      IOException
    • write

      public void write(int b) throws IOException
      Writes the specified byte to this file output stream.
      Specified by:
      write in class OutputStream
      Throws:
      IOException