Package com.google.protobuf
Class CodedOutputStream.OutputStreamEncoder
java.lang.Object
com.google.protobuf.ByteOutput
com.google.protobuf.CodedOutputStream
com.google.protobuf.CodedOutputStream.AbstractBufferedEncoder
com.google.protobuf.CodedOutputStream.OutputStreamEncoder
- Enclosing class:
CodedOutputStream
private static final class CodedOutputStream.OutputStreamEncoder
extends CodedOutputStream.AbstractBufferedEncoder
An
CodedOutputStream
that decorates an OutputStream
. It performs internal
buffering to optimize writes to the OutputStream
.-
Nested Class Summary
Nested classes/interfaces inherited from class com.google.protobuf.CodedOutputStream
CodedOutputStream.OutOfSpaceException
-
Field Summary
FieldsFields inherited from class com.google.protobuf.CodedOutputStream.AbstractBufferedEncoder
buffer, limit, position, totalBytesWritten
Fields inherited from class com.google.protobuf.CodedOutputStream
DEFAULT_BUFFER_SIZE, LITTLE_ENDIAN_32_SIZE, wrapper
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
doFlush()
void
flush()
Flushes the stream and forces any buffered bytes to be written.private void
flushIfNotAvailable
(int requiredSize) void
write
(byte value) Writes a single byte.void
write
(byte[] value, int offset, int length) Writes a sequence of bytes.void
write
(ByteBuffer value) Writes a sequence of bytes.void
writeBool
(int fieldNumber, boolean value) Write abool
field, including tag, to the stream.void
writeByteArray
(int fieldNumber, byte[] value) Write abytes
field, including tag, to the stream.void
writeByteArray
(int fieldNumber, byte[] value, int offset, int length) Write abytes
field, including tag, to the stream.void
writeByteArrayNoTag
(byte[] value, int offset, int length) Write abytes
field to the stream.void
writeByteBuffer
(int fieldNumber, ByteBuffer value) Write abytes
field, including tag, to the stream.void
writeBytes
(int fieldNumber, ByteString value) Write abytes
field, including tag, to the stream.void
writeBytesNoTag
(ByteString value) Write abytes
field to the stream.void
writeFixed32
(int fieldNumber, int value) Write afixed32
field, including tag, to the stream.void
writeFixed32NoTag
(int value) Write afixed32
field to the stream.void
writeFixed64
(int fieldNumber, long value) Write afixed64
field, including tag, to the stream.void
writeFixed64NoTag
(long value) Write afixed64
field to the stream.void
writeInt32
(int fieldNumber, int value) Write anint32
field, including tag, to the stream.void
writeInt32NoTag
(int value) Write anint32
field to the stream.void
writeLazy
(byte[] value, int offset, int length) Writes a sequence of bytes.void
writeLazy
(ByteBuffer value) Writes a sequence of bytes.void
writeMessage
(int fieldNumber, MessageLite value) Write an embedded message field, including tag, to the stream.(package private) void
writeMessage
(int fieldNumber, MessageLite value, Schema schema) Write an embedded message field, including tag, to the stream.void
writeMessageNoTag
(MessageLite value) Write an embedded message field to the stream.(package private) void
writeMessageNoTag
(MessageLite value, Schema schema) Write an embedded message field to the stream.void
writeMessageSetExtension
(int fieldNumber, MessageLite value) Write a MessageSet extension field to the stream.void
writeRawBytes
(ByteBuffer value) Write a ByteBuffer.void
writeRawMessageSetExtension
(int fieldNumber, ByteString value) Write an unparsed MessageSet extension field to the stream.void
writeString
(int fieldNumber, String value) Write astring
field, including tag, to the stream.void
writeStringNoTag
(String value) Write astring
field to the stream.void
writeTag
(int fieldNumber, int wireType) Encode and write a tag.void
writeUInt32
(int fieldNumber, int value) Write auint32
field, including tag, to the stream.void
writeUInt32NoTag
(int value) Write auint32
field to the stream.void
writeUInt64
(int fieldNumber, long value) Write auint64
field, including tag, to the stream.void
writeUInt64NoTag
(long value) Write auint64
field to the stream.Methods inherited from class com.google.protobuf.CodedOutputStream.AbstractBufferedEncoder
buffer, bufferFixed32NoTag, bufferFixed64NoTag, bufferInt32NoTag, bufferTag, bufferUInt32NoTag, bufferUInt64NoTag, getTotalBytesWritten, spaceLeft
Methods inherited from class com.google.protobuf.CodedOutputStream
checkNoSpaceLeft, computeBoolSize, computeBoolSizeNoTag, computeByteArraySize, computeByteArraySizeNoTag, computeByteBufferSize, computeByteBufferSizeNoTag, computeBytesSize, computeBytesSizeNoTag, computeDoubleSize, computeDoubleSizeNoTag, computeEnumSize, computeEnumSizeNoTag, computeFixed32Size, computeFixed32SizeNoTag, computeFixed64Size, computeFixed64SizeNoTag, computeFloatSize, computeFloatSizeNoTag, computeGroupSize, computeGroupSize, computeGroupSizeNoTag, computeGroupSizeNoTag, computeInt32Size, computeInt32SizeNoTag, computeInt64Size, computeInt64SizeNoTag, computeLazyFieldMessageSetExtensionSize, computeLazyFieldSize, computeLazyFieldSizeNoTag, computeLengthDelimitedFieldSize, computeMessageSetExtensionSize, computeMessageSize, computeMessageSize, computeMessageSizeNoTag, computeMessageSizeNoTag, computePreferredBufferSize, computeRawMessageSetExtensionSize, computeRawVarint32Size, computeRawVarint64Size, computeSFixed32Size, computeSFixed32SizeNoTag, computeSFixed64Size, computeSFixed64SizeNoTag, computeSInt32Size, computeSInt32SizeNoTag, computeSInt64Size, computeSInt64SizeNoTag, computeStringSize, computeStringSizeNoTag, computeTagSize, computeUInt32Size, computeUInt32SizeNoTag, computeUInt64Size, computeUInt64SizeNoTag, encodeZigZag32, encodeZigZag64, inefficientWriteStringNoTag, isSerializationDeterministic, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, newSafeInstance, newUnsafeInstance, useDeterministicSerialization, writeBoolNoTag, writeByteArrayNoTag, writeDouble, writeDoubleNoTag, writeEnum, writeEnumNoTag, writeFloat, writeFloatNoTag, writeGroup, writeGroup, writeGroupNoTag, writeGroupNoTag, writeInt64, writeInt64NoTag, writeRawByte, writeRawByte, writeRawBytes, writeRawBytes, writeRawBytes, writeRawLittleEndian32, writeRawLittleEndian64, writeRawVarint32, writeRawVarint64, writeSFixed32, writeSFixed32NoTag, writeSFixed64, writeSFixed64NoTag, writeSInt32, writeSInt32NoTag, writeSInt64, writeSInt64NoTag
-
Field Details
-
out
-
-
Constructor Details
-
OutputStreamEncoder
OutputStreamEncoder(OutputStream out, int bufferSize)
-
-
Method Details
-
writeTag
Description copied from class:CodedOutputStream
Encode and write a tag.- Specified by:
writeTag
in classCodedOutputStream
- Throws:
IOException
-
writeInt32
Description copied from class:CodedOutputStream
Write anint32
field, including tag, to the stream.- Specified by:
writeInt32
in classCodedOutputStream
- Throws:
IOException
-
writeUInt32
Description copied from class:CodedOutputStream
Write auint32
field, including tag, to the stream.- Specified by:
writeUInt32
in classCodedOutputStream
- Throws:
IOException
-
writeFixed32
Description copied from class:CodedOutputStream
Write afixed32
field, including tag, to the stream.- Specified by:
writeFixed32
in classCodedOutputStream
- Throws:
IOException
-
writeUInt64
Description copied from class:CodedOutputStream
Write auint64
field, including tag, to the stream.- Specified by:
writeUInt64
in classCodedOutputStream
- Throws:
IOException
-
writeFixed64
Description copied from class:CodedOutputStream
Write afixed64
field, including tag, to the stream.- Specified by:
writeFixed64
in classCodedOutputStream
- Throws:
IOException
-
writeBool
Description copied from class:CodedOutputStream
Write abool
field, including tag, to the stream.- Specified by:
writeBool
in classCodedOutputStream
- Throws:
IOException
-
writeString
Description copied from class:CodedOutputStream
Write astring
field, including tag, to the stream.- Specified by:
writeString
in classCodedOutputStream
- Throws:
IOException
-
writeBytes
Description copied from class:CodedOutputStream
Write abytes
field, including tag, to the stream.- Specified by:
writeBytes
in classCodedOutputStream
- Throws:
IOException
-
writeByteArray
Description copied from class:CodedOutputStream
Write abytes
field, including tag, to the stream.- Specified by:
writeByteArray
in classCodedOutputStream
- Throws:
IOException
-
writeByteArray
public void writeByteArray(int fieldNumber, byte[] value, int offset, int length) throws IOException Description copied from class:CodedOutputStream
Write abytes
field, including tag, to the stream.- Specified by:
writeByteArray
in classCodedOutputStream
- Throws:
IOException
-
writeByteBuffer
Description copied from class:CodedOutputStream
Write abytes
field, including tag, to the stream. This method will write all content of the ByteBuffer regardless of the current position and limit (i.e., the number of bytes to be written is value.capacity(), not value.remaining()). Furthermore, this method doesn't alter the state of the passed-in ByteBuffer. Its position, limit, mark, etc. will remain unchanged. If you only want to write the remaining bytes of a ByteBuffer, you can callwriteByteBuffer(fieldNumber, byteBuffer.slice())
.- Specified by:
writeByteBuffer
in classCodedOutputStream
- Throws:
IOException
-
writeBytesNoTag
Description copied from class:CodedOutputStream
Write abytes
field to the stream.- Specified by:
writeBytesNoTag
in classCodedOutputStream
- Throws:
IOException
-
writeByteArrayNoTag
Description copied from class:CodedOutputStream
Write abytes
field to the stream. Visible for testing.- Specified by:
writeByteArrayNoTag
in classCodedOutputStream
- Throws:
IOException
-
writeRawBytes
Description copied from class:CodedOutputStream
Write a ByteBuffer. This method will write all content of the ByteBuffer regardless of the current position and limit (i.e., the number of bytes to be written is value.capacity(), not value.remaining()). Furthermore, this method doesn't alter the state of the passed-in ByteBuffer. Its position, limit, mark, etc. will remain unchanged. If you only want to write the remaining bytes of a ByteBuffer, you can callwriteRawBytes(byteBuffer.slice())
.- Specified by:
writeRawBytes
in classCodedOutputStream
- Throws:
IOException
-
writeMessage
Description copied from class:CodedOutputStream
Write an embedded message field, including tag, to the stream.- Specified by:
writeMessage
in classCodedOutputStream
- Throws:
IOException
-
writeMessage
Description copied from class:CodedOutputStream
Write an embedded message field, including tag, to the stream.- Specified by:
writeMessage
in classCodedOutputStream
- Throws:
IOException
-
writeMessageSetExtension
Description copied from class:CodedOutputStream
Write a MessageSet extension field to the stream. For historical reasons, the wire format differs from normal fields.- Specified by:
writeMessageSetExtension
in classCodedOutputStream
- Throws:
IOException
-
writeRawMessageSetExtension
Description copied from class:CodedOutputStream
Write an unparsed MessageSet extension field to the stream. For historical reasons, the wire format differs from normal fields.- Specified by:
writeRawMessageSetExtension
in classCodedOutputStream
- Throws:
IOException
-
writeMessageNoTag
Description copied from class:CodedOutputStream
Write an embedded message field to the stream.- Specified by:
writeMessageNoTag
in classCodedOutputStream
- Throws:
IOException
-
writeMessageNoTag
Description copied from class:CodedOutputStream
Write an embedded message field to the stream.- Specified by:
writeMessageNoTag
in classCodedOutputStream
- Throws:
IOException
-
write
Description copied from class:ByteOutput
Writes a single byte.- Specified by:
write
in classCodedOutputStream
- Parameters:
value
- the byte to be written- Throws:
IOException
- thrown if an error occurred while writing
-
writeInt32NoTag
Description copied from class:CodedOutputStream
Write anint32
field to the stream.- Specified by:
writeInt32NoTag
in classCodedOutputStream
- Throws:
IOException
-
writeUInt32NoTag
Description copied from class:CodedOutputStream
Write auint32
field to the stream.- Specified by:
writeUInt32NoTag
in classCodedOutputStream
- Throws:
IOException
-
writeFixed32NoTag
Description copied from class:CodedOutputStream
Write afixed32
field to the stream.- Specified by:
writeFixed32NoTag
in classCodedOutputStream
- Throws:
IOException
-
writeUInt64NoTag
Description copied from class:CodedOutputStream
Write auint64
field to the stream.- Specified by:
writeUInt64NoTag
in classCodedOutputStream
- Throws:
IOException
-
writeFixed64NoTag
Description copied from class:CodedOutputStream
Write afixed64
field to the stream.- Specified by:
writeFixed64NoTag
in classCodedOutputStream
- Throws:
IOException
-
writeStringNoTag
Description copied from class:CodedOutputStream
Write astring
field to the stream.- Specified by:
writeStringNoTag
in classCodedOutputStream
- Throws:
IOException
-
flush
Description copied from class:CodedOutputStream
Flushes the stream and forces any buffered bytes to be written. This does not flush the underlying OutputStream.- Specified by:
flush
in classCodedOutputStream
- Throws:
IOException
-
write
Description copied from class:ByteOutput
Writes a sequence of bytes. TheByteOutput
must copyvalue
if it will not be processed prior to the return of this method call, sincevalue
may be reused/altered by the caller.NOTE: This method MUST NOT modify the
value
. Doing so is a programming error and will lead to data corruption which will be difficult to debug.- Specified by:
write
in classCodedOutputStream
- Parameters:
value
- the bytes to be writtenoffset
- the offset of the start of the writable rangelength
- the number of bytes to write starting fromoffset
- Throws:
IOException
- thrown if an error occurred while writing
-
writeLazy
Description copied from class:ByteOutput
Writes a sequence of bytes. TheByteOutput
is free to retain a reference to the value beyond the scope of this method call (e.g. write later) since it is considered immutable and is guaranteed not to change by the caller.NOTE: This method MUST NOT modify the
value
. Doing so is a programming error and will lead to data corruption which will be difficult to debug.- Specified by:
writeLazy
in classCodedOutputStream
- Parameters:
value
- the bytes to be writtenoffset
- the offset of the start of the writable rangelength
- the number of bytes to write starting fromoffset
- Throws:
IOException
- thrown if an error occurred while writing
-
write
Description copied from class:ByteOutput
Writes a sequence of bytes. TheByteOutput
must copyvalue
if it will not be processed prior to the return of this method call, sincevalue
may be reused/altered by the caller.NOTE: This method MUST NOT modify the
value
. Doing so is a programming error and will lead to data corruption which will be difficult to debug.- Specified by:
write
in classCodedOutputStream
- Parameters:
value
- the bytes to be written. Upon returning from this call, theposition
of this buffer will be set to thelimit
- Throws:
IOException
- thrown if an error occurred while writing
-
writeLazy
Description copied from class:ByteOutput
Writes a sequence of bytes. TheByteOutput
is free to retain a reference to the value beyond the scope of this method call (e.g. write later) since it is considered immutable and is guaranteed not to change by the caller.NOTE: This method MUST NOT modify the
value
. Doing so is a programming error and will lead to data corruption which will be difficult to debug.- Specified by:
writeLazy
in classCodedOutputStream
- Parameters:
value
- the bytes to be written. Upon returning from this call, theposition
of this buffer will be set to thelimit
- Throws:
IOException
- thrown if an error occurred while writing
-
flushIfNotAvailable
- Throws:
IOException
-
doFlush
- Throws:
IOException
-