Class StandardConversions
java.lang.Object
org.infinispan.commons.dataconversion.StandardConversions
Utilities to convert between text/plain, octet-stream, java-objects and url-encoded contents.
- Since:
- 9.2
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]convertCharset(Object content, Charset fromCharset, Charset toCharset) Convert text content.static byte[]convertJavaToProtoStream(Object source, MediaType sourceMediaType, org.infinispan.protostream.ImmutableSerializationContext ctx) Converts a java object to a sequence of bytes using a ProtoStreamImmutableSerializationContext.static StringconvertTextToObject(Object source, MediaType sourceType) Converts text content to the Java representation (String).static ObjectconvertTextToText(Object source, MediaType sourceType, MediaType destinationType) Convert text content to a different encoding.
-
Constructor Details
-
StandardConversions
public StandardConversions()
-
-
Method Details
-
convertTextToText
public static Object convertTextToText(Object source, MediaType sourceType, MediaType destinationType) Convert text content to a different encoding.- Parameters:
source- The source content.sourceType- MediaType for the source content.destinationType- the MediaType of the converted content.- Returns:
- content conforming to the destination MediaType.
-
convertTextToObject
Converts text content to the Java representation (String).- Parameters:
source- The source contentsourceType- the MediaType of the source content.- Returns:
- String representation of the text content.
- Throws:
EncodingException- if the source cannot be interpreted as plain text.
-
convertJavaToProtoStream
public static byte[] convertJavaToProtoStream(Object source, MediaType sourceMediaType, org.infinispan.protostream.ImmutableSerializationContext ctx) throws IOException, InterruptedException Converts a java object to a sequence of bytes using a ProtoStreamImmutableSerializationContext.- Parameters:
source- source the java object to convert.sourceMediaType- the MediaType matching application/x-application-object describing the source.- Returns:
- byte[] representation of the java object.
- Throws:
EncodingException- if the sourceMediaType is not a application/x-java-object or if the conversion is not supported.IOExceptionInterruptedException
-
convertCharset
-