Package org.infinispan.protostream
Class ProtobufUtil
java.lang.Object
org.infinispan.protostream.ProtobufUtil
This is the entry point to the ProtoStream library. This class provides methods to write and read Java objects
to/from a Protobuf encoded data stream. Also provides conversion to and from canonical JSON.
- Since:
- 1.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <A> intstatic <A> intstatic <A> AfromByteArray(ImmutableSerializationContext ctx, byte[] bytes, int offset, int length, Class<A> clazz) static <A> AfromByteArray(ImmutableSerializationContext ctx, byte[] bytes, Class<A> clazz) static <A> AfromByteBuffer(ImmutableSerializationContext ctx, ByteBuffer byteBuffer, Class<A> clazz) static byte[]fromCanonicalJSON(ImmutableSerializationContext ctx, Reader reader) static <A> AfromWrappedByteArray(ImmutableSerializationContext ctx, byte[] bytes) Parses a top-level message that was wrapped according to the org.infinispan.protostream.WrappedMessage proto definition.static <A> AfromWrappedByteArray(ImmutableSerializationContext ctx, byte[] bytes, int offset, int length) static <A> AfromWrappedByteBuffer(ImmutableSerializationContext ctx, ByteBuffer byteBuffer) static <A> Astatic SerializationContextstatic SerializationContextnewSerializationContext(Configuration configuration) static <A> AreadFrom(ImmutableSerializationContext ctx, InputStream in, Class<A> clazz) private static <A> AreadFrom(TagReaderImpl in, Class<A> clazz) static byte[]static ByteBufferstatic StringtoCanonicalJSON(ImmutableSerializationContext ctx, byte[] bytes) Converts a Protobuf encoded message to its canonical JSON representation.static StringtoCanonicalJSON(ImmutableSerializationContext ctx, byte[] bytes, boolean prettyPrint) Converts a Protobuf encoded message to its canonical JSON representation.static byte[]static byte[]toWrappedByteArray(ImmutableSerializationContext ctx, Object t, int bufferSize) static ByteBufferstatic voidtoWrappedStream(ImmutableSerializationContext ctx, OutputStream out, Object t) static voidtoWrappedStream(ImmutableSerializationContext ctx, OutputStream out, Object t, int bufferSize) Deprecated.private static <A> voidwrite(ImmutableSerializationContext ctx, TagWriterImpl out, A t) static voidwriteTo(ImmutableSerializationContext ctx, OutputStream out, Object t)
-
Field Details
-
DEFAULT_STREAM_BUFFER_SIZE
public static final int DEFAULT_STREAM_BUFFER_SIZE- See Also:
-
DEFAULT_ARRAY_BUFFER_SIZE
public static final int DEFAULT_ARRAY_BUFFER_SIZE- See Also:
-
-
Constructor Details
-
ProtobufUtil
private ProtobufUtil()
-
-
Method Details
-
newSerializationContext
-
newSerializationContext
-
computeMessageSize
- Throws:
IOException
-
computeWrappedMessageSize
public static <A> int computeWrappedMessageSize(ImmutableSerializationContext ctx, A t) throws IOException - Throws:
IOException
-
write
private static <A> void write(ImmutableSerializationContext ctx, TagWriterImpl out, A t) throws IOException - Throws:
IOException
-
writeTo
public static void writeTo(ImmutableSerializationContext ctx, OutputStream out, Object t) throws IOException - Throws:
IOException
-
toByteArray
- Throws:
IOException
-
toByteBuffer
public static ByteBuffer toByteBuffer(ImmutableSerializationContext ctx, Object t) throws IOException - Throws:
IOException
-
readFrom
- Throws:
IOException
-
readFrom
public static <A> A readFrom(ImmutableSerializationContext ctx, InputStream in, Class<A> clazz) throws IOException - Throws:
IOException
-
fromByteArray
public static <A> A fromByteArray(ImmutableSerializationContext ctx, byte[] bytes, Class<A> clazz) throws IOException - Throws:
IOException
-
fromByteArray
public static <A> A fromByteArray(ImmutableSerializationContext ctx, byte[] bytes, int offset, int length, Class<A> clazz) throws IOException - Throws:
IOException
-
fromByteBuffer
public static <A> A fromByteBuffer(ImmutableSerializationContext ctx, ByteBuffer byteBuffer, Class<A> clazz) throws IOException - Throws:
IOException
-
fromWrappedByteArray
public static <A> A fromWrappedByteArray(ImmutableSerializationContext ctx, byte[] bytes) throws IOException Parses a top-level message that was wrapped according to the org.infinispan.protostream.WrappedMessage proto definition.- Parameters:
ctx- the serialization contextbytes- the array of bytes to parse- Returns:
- the unwrapped object
- Throws:
IOException- in case parsing fails
-
fromWrappedByteArray
public static <A> A fromWrappedByteArray(ImmutableSerializationContext ctx, byte[] bytes, int offset, int length) throws IOException - Throws:
IOException
-
fromWrappedByteBuffer
public static <A> A fromWrappedByteBuffer(ImmutableSerializationContext ctx, ByteBuffer byteBuffer) throws IOException - Throws:
IOException
-
fromWrappedStream
public static <A> A fromWrappedStream(ImmutableSerializationContext ctx, InputStream in) throws IOException - Throws:
IOException
-
toWrappedByteArray
public static byte[] toWrappedByteArray(ImmutableSerializationContext ctx, Object t) throws IOException - Throws:
IOException
-
toWrappedByteArray
public static byte[] toWrappedByteArray(ImmutableSerializationContext ctx, Object t, int bufferSize) throws IOException - Throws:
IOException
-
toWrappedByteBuffer
public static ByteBuffer toWrappedByteBuffer(ImmutableSerializationContext ctx, Object t) throws IOException - Throws:
IOException
-
toWrappedStream
public static void toWrappedStream(ImmutableSerializationContext ctx, OutputStream out, Object t) throws IOException - Throws:
IOException
-
toWrappedStream
@Deprecated public static void toWrappedStream(ImmutableSerializationContext ctx, OutputStream out, Object t, int bufferSize) throws IOException Deprecated.since 5.0.10 Please usetoWrappedStream(ImmutableSerializationContext, OutputStream, Object)with aBufferedOutputStreaminstead- Throws:
IOException
-
toCanonicalJSON
public static String toCanonicalJSON(ImmutableSerializationContext ctx, byte[] bytes) throws IOException Converts a Protobuf encoded message to its canonical JSON representation.- Parameters:
ctx- the serialization contextbytes- the Protobuf encoded message bytes to parse- Returns:
- the JSON string representation
- Throws:
IOException- if I/O operations fail
-
toCanonicalJSON
public static String toCanonicalJSON(ImmutableSerializationContext ctx, byte[] bytes, boolean prettyPrint) throws IOException Converts a Protobuf encoded message to its canonical JSON representation.- Parameters:
ctx- the serialization contextbytes- the Protobuf encoded message bytes to parseprettyPrint- indicates if the JSON output should use a 'pretty' human-readable format or a compact format- Returns:
- the JSON string representation
- Throws:
IOException- if I/O operations fail
-
fromCanonicalJSON
public static byte[] fromCanonicalJSON(ImmutableSerializationContext ctx, Reader reader) throws IOException - Throws:
IOException
-
toWrappedStream(ImmutableSerializationContext, OutputStream, Object)with aBufferedOutputStreaminstead