Package com.google.protobuf
Class ByteString.Output
java.lang.Object
java.io.OutputStream
com.google.protobuf.ByteString.Output
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
- Enclosing class:
ByteString
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate byte[]
private int
private static final byte[]
private final ArrayList
<ByteString> private int
private final int
-
Constructor Summary
ConstructorsConstructorDescriptionOutput
(int initialCapacity) Creates a new ByteString output stream with the specified initial capacity. -
Method Summary
Modifier and TypeMethodDescriptionprivate byte[]
copyArray
(byte[] buffer, int length) Implement java.util.Arrays.copyOf() for jdk 1.5.private void
flushFullBuffer
(int minSize) Internal function used by writers.private void
Internal function used bytoByteString()
.void
reset()
Resets this stream, so that all currently accumulated output in the output stream is discarded.int
size()
Returns the current size of the output stream.Creates a byte string with the size and contents of this output stream.toString()
void
write
(byte[] b, int offset, int length) void
write
(int b) void
writeTo
(OutputStream out) Writes the complete contents of this byte array output stream to the specified output stream argument.Methods inherited from class java.io.OutputStream
close, flush, nullOutputStream, write
-
Field Details
-
EMPTY_BYTE_ARRAY
private static final byte[] EMPTY_BYTE_ARRAY -
initialCapacity
private final int initialCapacity -
flushedBuffers
-
flushedBuffersTotalBytes
private int flushedBuffersTotalBytes -
buffer
private byte[] buffer -
bufferPos
private int bufferPos
-
-
Constructor Details
-
Output
Output(int initialCapacity) Creates a new ByteString output stream with the specified initial capacity.- Parameters:
initialCapacity
- the initial capacity of the output stream.
-
-
Method Details
-
write
public void write(int b) - Specified by:
write
in classOutputStream
-
write
public void write(byte[] b, int offset, int length) - Overrides:
write
in classOutputStream
-
toByteString
Creates a byte string with the size and contents of this output stream. This does not create a new copy of the underlying bytes. If the stream size grows dynamically, the runtime is O(log n) in respect to the number of bytes written to theByteString.Output
. If the stream size stays within the initial capacity, the runtime is O(1).- Returns:
- the current contents of this output stream, as a byte string.
-
copyArray
private byte[] copyArray(byte[] buffer, int length) Implement java.util.Arrays.copyOf() for jdk 1.5. -
writeTo
Writes the complete contents of this byte array output stream to the specified output stream argument.- Parameters:
out
- the output stream to which to write the data.- Throws:
IOException
- if an I/O error occurs.
-
size
public int size()Returns the current size of the output stream.- Returns:
- the current size of the output stream
-
reset
public void reset()Resets this stream, so that all currently accumulated output in the output stream is discarded. The output stream can be used again, reusing the already allocated buffer space. -
toString
-
flushFullBuffer
private void flushFullBuffer(int minSize) Internal function used by writers. The current buffer is full, and the writer needs a new buffer whose size is at least the specified minimum size. -
flushLastBuffer
private void flushLastBuffer()Internal function used bytoByteString()
. The current buffer may or may not be full, but it needs to be flushed.
-