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
- Author:
- [email protected]
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
-
Method Summary
Modifier and TypeMethodDescriptionstatic <A> int
static <A> int
static <A> A
fromByteArray
(ImmutableSerializationContext ctx, byte[] bytes, int offset, int length, Class<A> clazz) static <A> A
fromByteArray
(ImmutableSerializationContext ctx, byte[] bytes, Class<A> clazz) static <A> A
fromByteBuffer
(ImmutableSerializationContext ctx, ByteBuffer byteBuffer, Class<A> clazz) static byte[]
fromCanonicalJSON
(ImmutableSerializationContext ctx, Reader reader) static <A> A
fromWrappedByteArray
(ImmutableSerializationContext ctx, byte[] bytes) Parses a top-level message that was wrapped according to the org.infinispan.protostream.WrappedMessage proto definition.static <A> A
fromWrappedByteArray
(ImmutableSerializationContext ctx, byte[] bytes, int offset, int length) static <A> A
fromWrappedByteBuffer
(ImmutableSerializationContext ctx, ByteBuffer byteBuffer) static <A> A
static SerializationContext
static SerializationContext
newSerializationContext
(Configuration configuration) static <A> A
readFrom
(ImmutableSerializationContext ctx, InputStream in, Class<A> clazz) static byte[]
static ByteBuffer
static String
toCanonicalJSON
(ImmutableSerializationContext ctx, byte[] bytes) Converts a Protobuf encoded message to its canonical JSON representation.static String
toCanonicalJSON
(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 ByteBuffer
static void
toWrappedStream
(ImmutableSerializationContext ctx, OutputStream out, Object t) static void
toWrappedStream
(ImmutableSerializationContext ctx, OutputStream out, Object t, int bufferSize) static void
writeTo
(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:
-
-
Method Details
-
newSerializationContext
-
newSerializationContext
-
computeMessageSize
- Throws:
IOException
-
computeWrappedMessageSize
public static <A> int computeWrappedMessageSize(ImmutableSerializationContext ctx, 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
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
public static void toWrappedStream(ImmutableSerializationContext ctx, OutputStream out, Object t, int bufferSize) throws IOException - 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
-