fr.cnes.sitools.logging
Class LoggingOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by fr.cnes.sitools.logging.LoggingOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class LoggingOutputStream
extends java.io.OutputStream

An OutputStream that flushes out to a Category.

Note that no data is written out to the Category until the stream is flushed or closed.

Example:

 // make sure everything sent to System.err is logged
 System.setErr(new PrintStream(new LoggingOutputStream(Category.getRoot(), Priority.WARN), true));
 
 // make sure everything sent to System.out is also logged
 System.setOut(new PrintStream(new LoggingOutputStream(Category.getRoot(), Priority.INFO), true));
 

Author:
Jim Moore
See Also:
source code

Field Summary
static int DEFAULT_BUFFER_LENGTH
          The default number of bytes in the buffer. =2048
 
Constructor Summary
LoggingOutputStream(java.util.logging.Logger logger, java.util.logging.Level level)
          Creates the LoggingOutputStream to flush to the given Category.
 
Method Summary
 void close()
          Closes this output stream and releases any system resources associated with this stream.
 void flush()
          Flushes this output stream and forces any buffered output bytes to be written out.
 void write(int b)
          Writes the specified byte to this output stream.
 
Methods inherited from class java.io.OutputStream
write, write
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_BUFFER_LENGTH

public static final int DEFAULT_BUFFER_LENGTH
The default number of bytes in the buffer. =2048

See Also:
Constant Field Values
Constructor Detail

LoggingOutputStream

public LoggingOutputStream(java.util.logging.Logger logger,
                           java.util.logging.Level level)
                    throws java.lang.IllegalArgumentException
Creates the LoggingOutputStream to flush to the given Category.

Parameters:
logger - the Category to write to
level - the Priority to use when writing to the Category
Throws:
java.lang.IllegalArgumentException - if cat == null or priority == null
Method Detail

close

public void close()
Closes this output stream and releases any system resources associated with this stream. The general contract of close is that it closes the output stream. A closed stream cannot perform output operations and cannot be reopened.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.OutputStream

write

public void write(int b)
           throws java.io.IOException
Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

Specified by:
write in class java.io.OutputStream
Parameters:
b - the byte to write
Throws:
java.io.IOException - if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.

flush

public void flush()
Flushes this output stream and forces any buffered output bytes to be written out. The general contract of flush is that calling it is an indication that, if any bytes previously written have been buffered by the implementation of the output stream, such bytes should immediately be written to their intended destination.

Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream


Copyright © 2010-2013 CNES. All Rights Reserved.