Package org.infinispan.protostream
Class ProtobufUtil
- java.lang.Object
-
- org.infinispan.protostream.ProtobufUtil
-
public final class ProtobufUtil extends Object
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
Fields Modifier and Type Field Description static int
DEFAULT_ARRAY_BUFFER_SIZE
static int
DEFAULT_STREAM_BUFFER_SIZE
-
Method Summary
-
-
-
Field Detail
-
DEFAULT_STREAM_BUFFER_SIZE
public static final int DEFAULT_STREAM_BUFFER_SIZE
- See Also:
- Constant Field Values
-
DEFAULT_ARRAY_BUFFER_SIZE
public static final int DEFAULT_ARRAY_BUFFER_SIZE
- See Also:
- Constant Field Values
-
-
Method Detail
-
newSerializationContext
public static SerializationContext newSerializationContext()
-
newSerializationContext
public static SerializationContext newSerializationContext(Configuration configuration)
-
computeMessageSize
public static <A> int computeMessageSize(ImmutableSerializationContext ctx, A t) throws IOException
- 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
public static byte[] toByteArray(ImmutableSerializationContext ctx, Object t) throws IOException
- 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
-
-