Class OutputStreamBufferOutput
- java.lang.Object
-
- com.batch.android.msgpack.core.buffer.OutputStreamBufferOutput
-
- All Implemented Interfaces:
MessageBufferOutput,java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
public class OutputStreamBufferOutput extends java.lang.Object implements MessageBufferOutput
MessageBufferOutput adapter forOutputStream.
-
-
Constructor Summary
Constructors Constructor Description OutputStreamBufferOutput(java.io.OutputStream out)OutputStreamBufferOutput(java.io.OutputStream out, int bufferSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(byte[] buffer, int offset, int length)Writes an external payload data.voidclose()voidflush()MessageBuffernext(int minimumSize)Allocates the next buffer to write.java.io.OutputStreamreset(java.io.OutputStream out)Reset Stream.voidwrite(byte[] buffer, int offset, int length)Writes an external payload data.voidwriteBuffer(int length)Writes the previously allocated buffer.
-
-
-
Method Detail
-
reset
public java.io.OutputStream reset(java.io.OutputStream out) throws java.io.IOExceptionReset Stream. This method doesn't close the old stream.- Parameters:
out- new stream- Returns:
- the old stream
- Throws:
java.io.IOException
-
next
public MessageBuffer next(int minimumSize) throws java.io.IOException
Description copied from interface:MessageBufferOutputAllocates the next buffer to write.This method should return a MessageBuffer instance that has specified size of capacity at least.
When this method is called twice, the previously returned buffer is no longer used. This method may be called twice without call of
MessageBufferOutput.writeBuffer(int)in between. In this case, the buffer should be discarded without flushing it to the output.- Specified by:
nextin interfaceMessageBufferOutput- Parameters:
minimumSize- the mimium required buffer size to allocate- Returns:
- the MessageBuffer instance with at least minimumSize bytes of capacity
- Throws:
java.io.IOException
-
writeBuffer
public void writeBuffer(int length) throws java.io.IOExceptionDescription copied from interface:MessageBufferOutputWrites the previously allocated buffer.This method should write the buffer previously returned from
MessageBufferOutput.next(int)method until specified number of bytes. Once the buffer is written, the buffer is no longer used.This method is not always called for each
MessageBufferOutput.next(int)call. In this case, the buffer should be discarded without flushing it to the output when the nextMessageBufferOutput.next(int)is called.- Specified by:
writeBufferin interfaceMessageBufferOutput- Parameters:
length- the number of bytes to write- Throws:
java.io.IOException
-
write
public void write(byte[] buffer, int offset, int length) throws java.io.IOExceptionDescription copied from interface:MessageBufferOutputWrites an external payload data. This method should follow semantics of OutputStream.- Specified by:
writein interfaceMessageBufferOutput- Parameters:
buffer- the data to writeoffset- the start offset in the datalength- the number of bytes to write- Throws:
java.io.IOException
-
add
public void add(byte[] buffer, int offset, int length) throws java.io.IOExceptionDescription copied from interface:MessageBufferOutputWrites an external payload data.Unlike
MessageBufferOutput.write(byte[], int, int)method, the buffer is given - this MessageBufferOutput implementation gets ownership of the buffer and may modify contents of the buffer. Contents of this buffer won't be modified by the caller.- Specified by:
addin interfaceMessageBufferOutput- Parameters:
buffer- the data to addoffset- the start offset in the datalength- the number of bytes to add- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOException- Specified by:
flushin interfacejava.io.Flushable- Throws:
java.io.IOException
-
-