org.glassfish.grizzly.http.server.io
Class NIOOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by org.glassfish.grizzly.http.server.io.NIOOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable, BinaryNIOOutputSink, NIOOutputSink

public class NIOOutputStream
extends java.io.OutputStream
implements BinaryNIOOutputSink

Stream implementation for writing binary content to an HTTP user-agent.

Since:
2.0

Constructor Summary
NIOOutputStream(OutputBuffer outputBuffer)
           
 
Method Summary
 boolean canWrite(int length)
          
 void close()
          
 void flush()
          
 boolean notifyCanWrite(WriteHandler handler, int length)
          Instructs the NIOOutputSink to invoke the provided WriteHandler when it is possible to write length bytes.
 void write(Buffer buffer)
          Writes the contents of the specified Buffer.
 void write(byte[] b)
          
 void write(byte[] b, int off, int len)
          
 void write(int b)
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NIOOutputStream

public NIOOutputStream(OutputBuffer outputBuffer)
Method Detail

write

public void write(int b)
           throws java.io.IOException

Specified by:
write in class java.io.OutputStream
Throws:
java.io.IOException

write

public void write(byte[] b)
           throws java.io.IOException

Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException

Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException

flush

public void flush()
           throws java.io.IOException

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

close

public void close()
           throws java.io.IOException

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

canWrite

public boolean canWrite(int length)

Specified by:
canWrite in interface NIOOutputSink
Parameters:
length - specifies the number of bytes that require writing
Returns:
true if a write to this NIOOutputSink will succeed, otherwise returns false.

notifyCanWrite

public boolean notifyCanWrite(WriteHandler handler,
                              int length)
Instructs the NIOOutputSink to invoke the provided WriteHandler when it is possible to write length bytes. Note that once the WriteHandler has been notified, it will not be considered for notification again at a later point in time.

Specified by:
notifyCanWrite in interface NIOOutputSink
Parameters:
handler - the WriteHandler that should be notified when it's possible to write length bytes.
length - the number of bytes that require writing.
Returns:
true if the specified handler has been accepted and will be notified as it becomes possible to write, otherwise returns false which means data is currently available to write without blocking or that there is no limit as to how much data can be pending to be written.

write

public void write(Buffer buffer)
           throws java.io.IOException
Writes the contents of the specified Buffer.

Specified by:
write in interface BinaryNIOOutputSink
Parameters:
buffer - the to write
Throws:
java.io.IOException


Copyright © 2011 Oracle Corpration. All Rights Reserved.