Class BufferPoolServerOutputStream<B>
- java.lang.Object
-
- java.io.OutputStream
-
- net.officefloor.server.stream.ServerOutputStream
-
- net.officefloor.server.stream.impl.BufferPoolServerOutputStream<B>
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
public class BufferPoolServerOutputStream<B> extends ServerOutputStream
- Author:
- Daniel Sagenschneider
-
-
Constructor Summary
Constructors Constructor Description BufferPoolServerOutputStream(StreamBufferPool<B> bufferPool)Instantiate.BufferPoolServerOutputStream(StreamBufferPool<B> bufferPool, CloseHandler closeHandler)Instantiate.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clears thisOutputStreamand releases theStreamBufferinstances.voidclose()voidflush()StreamBuffer<B>getBuffers()Obtains the headStreamBufferinstances used by thisServerOutputStream.longgetContentLength()Obtains the content length of output data.ServerWritergetServerWriter(java.nio.charset.Charset charset)Obtains theServerWriter.voidwrite(byte[] bytes, int off, int len)voidwrite(int b)voidwrite(java.nio.ByteBuffer buffer)Writes aByteBuffer.voidwrite(java.nio.channels.FileChannel file, long position, long count, FileCompleteCallback callback)Writes part of theFileChannelcontents.voidwrite(java.nio.channels.FileChannel file, FileCompleteCallback callback)Writes the entireFileChannelcontents.
-
-
-
Constructor Detail
-
BufferPoolServerOutputStream
public BufferPoolServerOutputStream(StreamBufferPool<B> bufferPool, CloseHandler closeHandler)
Instantiate.- Parameters:
bufferPool-StreamBufferPool.closeHandler-CloseHandler.
-
BufferPoolServerOutputStream
public BufferPoolServerOutputStream(StreamBufferPool<B> bufferPool)
Instantiate.- Parameters:
bufferPool-StreamBufferPool.
-
-
Method Detail
-
getServerWriter
public ServerWriter getServerWriter(java.nio.charset.Charset charset) throws java.io.IOException
Obtains theServerWriter.- Parameters:
charset-Charsetfor writing outStringdata.- Returns:
ServerWriter.- Throws:
java.io.IOException- ShouldServerOutputStreambe closed.
-
getContentLength
public long getContentLength()
Obtains the content length of output data.- Returns:
- Content length of output data.
-
getBuffers
public StreamBuffer<B> getBuffers()
Obtains the headStreamBufferinstances used by thisServerOutputStream.- Returns:
StreamBufferinstances used by thisServerOutputStream.
-
clear
public void clear() throws java.io.IOExceptionClears thisOutputStreamand releases theStreamBufferinstances.- Throws:
java.io.IOException- If failure in clearingOutputStream.
-
write
public void write(java.nio.ByteBuffer buffer) throws java.io.IOExceptionDescription copied from class:ServerOutputStreamWrites a
ByteBuffer.This is to enable efficient I/O of writing content (typically cached).
- Specified by:
writein classServerOutputStream- Parameters:
buffer-ByteBufferthat should never change its content.- Throws:
java.io.IOException- If fails to write theByteBuffer.
-
write
public void write(java.nio.channels.FileChannel file, long position, long count, FileCompleteCallback callback) throws java.io.IOExceptionDescription copied from class:ServerOutputStreamWrites part of the
FileChannelcontents.This is to enable efficient I/O (ie DMA) of writing
FileChannelcontent.To write the entire
FileChannelcontents, invokewrite(file, 0, -1).Note that the underlying implementation will need to support
FileChannelefficiencies.- Specified by:
writein classServerOutputStream- Parameters:
file-FileChannel.position- Position within theFileChannelto start writing content. Must be non-negative number.count- Count of bytes to write from theFileChannel. A negative value (typically-1) indicates to write the remainingFileChannelcontent from position.callback- OptionalFileCompleteCallback. May benull.- Throws:
java.io.IOException- If fails to write theFileChannelcontent.
-
write
public void write(java.nio.channels.FileChannel file, FileCompleteCallback callback) throws java.io.IOExceptionDescription copied from class:ServerOutputStreamWrites the entire
FileChannelcontents.This is a convenience method for
write(file, 0, -1).- Specified by:
writein classServerOutputStream- Parameters:
file-FileChannel.callback- OptionalFileCompleteCallback. May benull.- Throws:
java.io.IOException- If fails to write theFileChannelcontent.
-
write
public void write(int b) throws java.io.IOException- Specified by:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
write
public void write(byte[] bytes, int off, int len) throws java.io.IOException- Overrides:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOException- Specified by:
flushin interfacejava.io.Flushable- Overrides:
flushin classjava.io.OutputStream- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.OutputStream- Throws:
java.io.IOException
-
-