Enum Class StreamOutputHelper
- All Implemented Interfaces:
Serializable,Comparable<StreamOutputHelper>,Constable
StreamOutput, for cases where performance is not a concern.-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]static intputMultiByteVInt(byte[] buffer, int i, int offset) Put the integeriinto the givenbufferstarting at the givenoffset, formatted as perStreamOutput.writeVInt(int).static intputVInt(byte[] buffer, int i, int offset) Put the integeriinto the givenbufferstarting at the givenoffset, formatted as perStreamOutput.writeVInt(int).static StreamOutputHelperReturns the enum constant of this class with the specified name.static StreamOutputHelper[]values()Returns an array containing the constants of this enum class, in the order they are declared.static intwriteGenericString(String value, OutputStream outputStream) Write generic string using the default thread-local scratch buffer, as described inStreamOutput.writeGenericString(java.lang.String).static intwriteOptionalString(String str, OutputStream outputStream) Write possibly-null string using the default thread-local scratch buffer, as described inStreamOutput.writeOptionalString(java.lang.String).static intwriteString(String str, byte[] buffer, int prefixLength, OutputStream outputStream) Write string prefixed by some number of bytes (possibly zero) from the beginning of the givenbuffer.static intwriteString(String str, OutputStream outputStream) Write string using the default thread-local scratch buffer, as described inStreamOutput.writeString(java.lang.String).
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
getThreadLocalScratchBuffer
public static byte[] getThreadLocalScratchBuffer()- Returns:
- a thread-local
byte[]that can be used to collect some data which is then passed toStreamOutput.write(int).This is almost certainly more efficient than calling
StreamOutput.writeByte(byte)repeatedly, but accessing a thread-local is not super-cheap so it is typically less efficient than writing the bytes directly into the buffer underneath theStreamOutputif it has such a buffer.
-
writeString
Write string using the default thread-local scratch buffer, as described inStreamOutput.writeString(java.lang.String).This is almost certainly more efficient than calling
StreamOutput.writeByte(byte)repeatedly, but accessing a thread-local is not super-cheap so it is typically less efficient than writing the bytes directly into the buffer underneath theStreamOutputif it has such a buffer.- Parameters:
str- string to writeoutputStream- the stream to which to write the data after buffering.- Returns:
- number of bytes written.
- Throws:
IOException- on failure
-
writeString
public static int writeString(String str, byte[] buffer, int prefixLength, OutputStream outputStream) throws IOException Write string prefixed by some number of bytes (possibly zero) from the beginning of the givenbuffer. The givenbufferwill also be used when encoding the given string. This is almost certainly more efficient than callingStreamOutput.writeByte(byte)repeatedly, but less efficient than writing the bytes directly into the buffer underneath theStreamOutputif it has such a buffer.- Parameters:
str- string to writebuffer- buffer that may hold some bytes to writeprefixLength- how many bytes in {code buffer} to writeoutputStream- the stream to which to write the data after buffering.- Returns:
- number of bytes written.
- Throws:
IOException- on failure
-
writeOptionalString
public static int writeOptionalString(@Nullable String str, OutputStream outputStream) throws IOException Write possibly-null string using the default thread-local scratch buffer, as described inStreamOutput.writeOptionalString(java.lang.String).This is almost certainly more efficient than calling
StreamOutput.writeByte(byte)repeatedly, but accessing a thread-local is not super-cheap so it is typically less efficient than writing the bytes directly into the buffer underneath theStreamOutputif it has such a buffer.- Parameters:
str- string to writeoutputStream- the stream to which to write the data after buffering.- Returns:
- number of bytes written.
- Throws:
IOException- on failure
-
writeGenericString
Write generic string using the default thread-local scratch buffer, as described inStreamOutput.writeGenericString(java.lang.String).This is almost certainly more efficient than calling
StreamOutput.writeByte(byte)repeatedly, but accessing a thread-local is not super-cheap so it is typically less efficient than writing the bytes directly into the buffer underneath theStreamOutputif it has such a buffer.- Parameters:
value- string to writeoutputStream- the stream to which to write the data after buffering.- Returns:
- number of bytes written.
- Throws:
IOException- on failure
-
putVInt
public static int putVInt(byte[] buffer, int i, int offset) Put the integeriinto the givenbufferstarting at the givenoffset, formatted as perStreamOutput.writeVInt(int). Performs no bounds checks: callers must verify that there is enough space inbufferfirst.- Returns:
- updated offset (original offset plus number of bytes written)
-
putMultiByteVInt
public static int putMultiByteVInt(byte[] buffer, int i, int offset) Put the integeriinto the givenbufferstarting at the givenoffset, formatted as perStreamOutput.writeVInt(int). Performs no bounds checks: callers must verify that there is enough space inbufferfirst.- Returns:
- updated offset (original offset plus number of bytes written)
-