org.cdlib.xtf.servletBase
Class LatencyCutoffStream

Object
  extended by OutputStream
      extended by ServletOutputStream
          extended by LatencyCutoffStream
All Implemented Interfaces:
Closeable, Flushable

 class LatencyCutoffStream
extends ServletOutputStream

This class prints out latency information after a given number of bytes have been output.


Field Summary
private  boolean isReported
          Whether the message has been printed yet
private  int limit
          The limit on the number of bytes after which the message is printed
private  OutputStream realOut
          The output stream to receive the output
private  long reqStartTime
          The start of the request, for timing purposes
private  int total
          How many bytes have been output so far
private  String url
          The URL of the request being served
 
Constructor Summary
LatencyCutoffStream(OutputStream realOut, int limit, long reqStartTime, String url)
          Constructor.
 
Method Summary
 void close()
          Close the output stream
 void flush()
          Flush any pending data to the output stream
 boolean isReported()
          Tells whether the latency was reported yet
private  void reportLatency()
          Report the latency and set the flag saying it has been done.
 void write(byte[] b)
          Write an array of bytes to the output stream
 void write(byte[] b, int off, int len)
          Write a subset of bytes to the stream
 void write(int b)
          Write a single byte to the stream
 
Methods inherited from class ServletOutputStream
print, print, print, print, print, print, print, println, println, println, println, println, println, println, println
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

realOut

private OutputStream realOut
The output stream to receive the output


total

private int total
How many bytes have been output so far


limit

private int limit
The limit on the number of bytes after which the message is printed


url

private String url
The URL of the request being served


reqStartTime

private long reqStartTime
The start of the request, for timing purposes


isReported

private boolean isReported
Whether the message has been printed yet

Constructor Detail

LatencyCutoffStream

public LatencyCutoffStream(OutputStream realOut,
                           int limit,
                           long reqStartTime,
                           String url)
Constructor.

Parameters:
realOut - The output stream to receive the limited output
limit - How many characters to output the message after
url - The URL of the request being served
Method Detail

close

public void close()
           throws IOException
Close the output stream

Specified by:
close in interface Closeable
Overrides:
close in class OutputStream
Throws:
IOException

flush

public void flush()
           throws IOException
Flush any pending data to the output stream

Specified by:
flush in interface Flushable
Overrides:
flush in class OutputStream
Throws:
IOException

write

public void write(byte[] b)
           throws IOException
Write an array of bytes to the output stream

Overrides:
write in class OutputStream
Throws:
IOException

write

public void write(byte[] b,
                  int off,
                  int len)
           throws IOException
Write a subset of bytes to the stream

Overrides:
write in class OutputStream
Throws:
IOException

write

public void write(int b)
           throws IOException
Write a single byte to the stream

Specified by:
write in class OutputStream
Throws:
IOException

isReported

public boolean isReported()
Tells whether the latency was reported yet


reportLatency

private void reportLatency()
Report the latency and set the flag saying it has been done.