Package com.google.protobuf
Class ByteString.Output
- java.lang.Object
-
- java.io.OutputStream
-
- com.google.protobuf.ByteString.Output
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
- Enclosing class:
- ByteString
public static final class ByteString.Output extends java.io.OutputStream
-
-
Field Summary
Fields Modifier and Type Field Description private byte[]
buffer
private int
bufferPos
private static byte[]
EMPTY_BYTE_ARRAY
private java.util.ArrayList<ByteString>
flushedBuffers
private int
flushedBuffersTotalBytes
private int
initialCapacity
-
Constructor Summary
Constructors Constructor Description Output(int initialCapacity)
Creates a new ByteString output stream with the specified initial capacity.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private 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
flushLastBuffer()
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.ByteString
toByteString()
Creates a byte string.java.lang.String
toString()
void
write(byte[] b, int offset, int length)
void
write(int b)
void
writeTo(java.io.OutputStream out)
Writes the complete contents of this byte array output stream to the specified output stream argument.
-
-
-
Field Detail
-
EMPTY_BYTE_ARRAY
private static final byte[] EMPTY_BYTE_ARRAY
-
initialCapacity
private final int initialCapacity
-
flushedBuffers
private final java.util.ArrayList<ByteString> flushedBuffers
-
flushedBuffersTotalBytes
private int flushedBuffersTotalBytes
-
buffer
private byte[] buffer
-
bufferPos
private int bufferPos
-
-
Method Detail
-
write
public void write(int b)
- Specified by:
write
in classjava.io.OutputStream
-
write
public void write(byte[] b, int offset, int length)
- Overrides:
write
in classjava.io.OutputStream
-
toByteString
public ByteString toByteString()
Creates a byte string. Its size is the current size of this output stream and its output has been copied to it.- 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
public void writeTo(java.io.OutputStream out) throws java.io.IOException
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:
java.io.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
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
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.
-
-