Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

org.objectweb.cjdbc.common.util.LoggingOutputStream Class Reference

List of all members.

Public Member Functions

 LoggingOutputStream (Category cat, Priority priority) throws IllegalArgumentException
void close ()
void write (final int b) throws IOException
void flush ()

Static Public Attributes

final int DEFAULT_BUFFER_LENGTH = 2048

Protected Attributes

boolean hasBeenClosed = false
byte[] buf
int count
Category category
Priority priority

Static Protected Attributes

final String LINE_SEPERATOR

Detailed Description

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.

Author:
Jim Moore

Nicolas Modrzyk

See also:
Category

Definition at line 45 of file LoggingOutputStream.java.


Constructor & Destructor Documentation

org.objectweb.cjdbc.common.util.LoggingOutputStream.LoggingOutputStream Category  cat,
Priority  priority
throws IllegalArgumentException
 

Creates the LoggingOutputStream to flush to the given Category.

Parameters:
cat the Category to write to
priority the Priority to use when writing to the Category
Exceptions:
IllegalArgumentException if cat == null or priority == null

Definition at line 92 of file LoggingOutputStream.java.

References org.objectweb.cjdbc.common.util.LoggingOutputStream.buf, org.objectweb.cjdbc.common.util.LoggingOutputStream.category, org.objectweb.cjdbc.common.util.LoggingOutputStream.count, and org.objectweb.cjdbc.common.util.LoggingOutputStream.priority.

00094   {
00095     if (cat == null)
00096     {
00097       throw new IllegalArgumentException("cat == null");
00098     }
00099     if (priority == null)
00100     {
00101       throw new IllegalArgumentException("priority == null");
00102     }
00103     this.priority = priority;
00104     category = cat;
00105     bufLength = DEFAULT_BUFFER_LENGTH;
00106     buf = new byte[DEFAULT_BUFFER_LENGTH];
00107     count = 0;
00108   }


Member Function Documentation

void org.objectweb.cjdbc.common.util.LoggingOutputStream.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.

Definition at line 116 of file LoggingOutputStream.java.

References org.objectweb.cjdbc.common.util.LoggingOutputStream.flush(), and org.objectweb.cjdbc.common.util.LoggingOutputStream.hasBeenClosed.

00117   {
00118     flush();
00119     hasBeenClosed = true;
00120   }

void org.objectweb.cjdbc.common.util.LoggingOutputStream.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.

Definition at line 164 of file LoggingOutputStream.java.

References org.objectweb.cjdbc.common.util.LoggingOutputStream.buf, org.objectweb.cjdbc.common.util.LoggingOutputStream.category, org.objectweb.cjdbc.common.util.LoggingOutputStream.count, and org.objectweb.cjdbc.common.util.LoggingOutputStream.priority.

Referenced by org.objectweb.cjdbc.common.util.LoggingOutputStream.close().

00165   {
00166     if (count == 0)
00167     {
00168       return;
00169     }
00170     // don't print out blank lines; flushing from PrintStream puts out these
00171     if (count == LINE_SEPERATOR.length())
00172     {
00173       if (((char) buf[0]) == LINE_SEPERATOR.charAt(0) && ((count == 1) || // <-
00174                                                                                                                                  // Unix
00175                                                                                                                                  // &
00176                                                                                                                                  // Mac,
00177                                                                                                                                  // ->
00178                                                                                                                                  // Windows
00179           ((count == 2) && ((char) buf[1]) == LINE_SEPERATOR.charAt(1))))
00180       {
00181         reset();
00182         return;
00183       }
00184     }
00185     final byte[] theBytes = new byte[count];
00186     System.arraycopy(buf, 0, theBytes, 0, count);
00187     
00188     // ADDED: We don't want blank lines at all
00189     String bytes  = new String(theBytes).trim();
00190     int line = -1;
00191     while((line = bytes.indexOf(LINE_SEPERATOR))!=-1)
00192     {
00193         bytes = bytes.substring(0, line) + bytes.substring(line+LINE_SEPERATOR.length());
00194     }
00195     // END ADDED 
00196     
00197     category.log(priority, bytes);
00198     reset();
00199   }

void org.objectweb.cjdbc.common.util.LoggingOutputStream.write final int  b  )  throws 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.

Parameters:
b the byte to write
Exceptions:
IOException if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.

Definition at line 132 of file LoggingOutputStream.java.

References org.objectweb.cjdbc.common.util.LoggingOutputStream.buf, and org.objectweb.cjdbc.common.util.LoggingOutputStream.count.

00133   {
00134     if (hasBeenClosed)
00135     {
00136       throw new IOException("The stream has been closed.");
00137     }
00138     // don't log nulls
00139     if (b == 0)
00140     {
00141       return;
00142     }
00143     // would this be writing past the buffer?
00144     if (count == bufLength)
00145     {
00146       // grow the buffer
00147       final int newBufLength = bufLength + DEFAULT_BUFFER_LENGTH;
00148       final byte[] newBuf = new byte[newBufLength];
00149       System.arraycopy(buf, 0, newBuf, 0, bufLength);
00150       buf = newBuf;
00151       bufLength = newBufLength;
00152     }
00153     buf[count] = (byte) b;
00154     count++;
00155   }


Member Data Documentation

byte [] org.objectweb.cjdbc.common.util.LoggingOutputStream.buf [protected]
 

The internal buffer where data is stored.

Definition at line 56 of file LoggingOutputStream.java.

Referenced by org.objectweb.cjdbc.common.util.LoggingOutputStream.flush(), org.objectweb.cjdbc.common.util.LoggingOutputStream.LoggingOutputStream(), and org.objectweb.cjdbc.common.util.LoggingOutputStream.write().

Category org.objectweb.cjdbc.common.util.LoggingOutputStream.category [protected]
 

The category to write to.

Definition at line 74 of file LoggingOutputStream.java.

Referenced by org.objectweb.cjdbc.common.util.LoggingOutputStream.flush(), and org.objectweb.cjdbc.common.util.LoggingOutputStream.LoggingOutputStream().

int org.objectweb.cjdbc.common.util.LoggingOutputStream.count [protected]
 

The number of valid bytes in the buffer. This value is always in the range 0 through buf.length; elements buf[0] through buf[count-1] contain valid byte data.

Definition at line 62 of file LoggingOutputStream.java.

Referenced by org.objectweb.cjdbc.common.util.LoggingOutputStream.flush(), org.objectweb.cjdbc.common.util.LoggingOutputStream.LoggingOutputStream(), and org.objectweb.cjdbc.common.util.LoggingOutputStream.write().

final int org.objectweb.cjdbc.common.util.LoggingOutputStream.DEFAULT_BUFFER_LENGTH = 2048 [static]
 

The default number of bytes in the buffer. =2048

Definition at line 70 of file LoggingOutputStream.java.

boolean org.objectweb.cjdbc.common.util.LoggingOutputStream.hasBeenClosed = false [protected]
 

Used to maintain the contract of close().

Definition at line 52 of file LoggingOutputStream.java.

Referenced by org.objectweb.cjdbc.common.util.LoggingOutputStream.close().

final String org.objectweb.cjdbc.common.util.LoggingOutputStream.LINE_SEPERATOR [static, protected]
 

Initial value:

 System
                                                          .getProperty("line.separator")

Definition at line 47 of file LoggingOutputStream.java.

Priority org.objectweb.cjdbc.common.util.LoggingOutputStream.priority [protected]
 

The priority to use when writing to the Category.

Definition at line 78 of file LoggingOutputStream.java.

Referenced by org.objectweb.cjdbc.common.util.LoggingOutputStream.flush(), and org.objectweb.cjdbc.common.util.LoggingOutputStream.LoggingOutputStream().


The documentation for this class was generated from the following file:
Generated on Mon Apr 11 22:02:14 2005 for C-JDBC by  doxygen 1.3.9.1