Class StandardConversions
- java.lang.Object
-
- org.infinispan.commons.dataconversion.StandardConversions
-
public final class StandardConversions extends Object
Utilities to convert between text/plain, octet-stream, java-objects and url-encoded contents.- Since:
- 9.2
-
-
Constructor Summary
Constructors Constructor Description StandardConversions()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static String
bytesToHex(byte[] bytes)
Deprecated.static byte[]
convertCharset(Object content, Charset fromCharset, Charset toCharset)
Convert text content.static byte[]
convertJavaToOctetStream(Object source, MediaType sourceMediaType, Marshaller marshaller)
Deprecated.Since 13.0, with no replacement.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 byte[]
convertJavaToText(Object source, MediaType sourceMediaType, MediaType destinationMediaType)
Deprecated.Since 13.0 without replacement.static Object
convertOctetStreamToJava(byte[] source, MediaType destination, Marshaller marshaller)
Deprecated.Since 13.0, without replacement.static byte[]
convertOctetStreamToText(byte[] source, MediaType destination)
Deprecated.Since 13.0, without replacment.static Object
convertOctetStreamToUrlEncoded(Object content, MediaType contentType)
Deprecated.Since 13.0 without replacement.static String
convertTextToObject(Object source, MediaType sourceType)
Converts text content to the Java representation (String).static byte[]
convertTextToOctetStream(Object source, MediaType sourceType)
Deprecated.Since 13.0, without replacement.static Object
convertTextToText(Object source, MediaType sourceType, MediaType destinationType)
Convert text content to a different encoding.static String
convertTextToUrlEncoded(Object source, MediaType sourceType)
Deprecated.Since 13.0, without replacement.static Object
convertUrlEncodedToObject(Object content)
Deprecated.since 13.0 without replacement.static Object
convertUrlEncodedToOctetStream(Object content)
Deprecated.Since 13.0 without replacement.static Object
convertUrlEncodedToText(Object content, MediaType destinationType)
Deprecated.Since 13.0 without replacement.static Object
decodeObjectContent(Object content, MediaType contentMediaType)
Deprecated.Since 13.0, without replacement.static byte[]
decodeOctetStream(Object input, MediaType octetStream)
Deprecated.Since 13.0, without replacement.static byte[]
hexToBytes(String hex)
Deprecated.UseBase16Codec.decode(String)
instead.static Object
urlDecode(Object content)
Deprecated.Since 13.0, without replacement.static String
urlEncode(Object content, MediaType mediaType)
Deprecated.Since 13.0 without replacement.
-
-
-
Method Detail
-
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.
-
convertTextToOctetStream
@Deprecated public static byte[] convertTextToOctetStream(Object source, MediaType sourceType)
Deprecated.Since 13.0, without replacement.Converts text content to binary.- Parameters:
source
- The source content.sourceType
- MediaType for the source content.- Returns:
- content converted as octet-stream represented as byte[].
- Throws:
EncodingException
- if the source cannot be interpreted as plain text.
-
convertTextToObject
public static String convertTextToObject(Object source, MediaType sourceType)
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.
-
convertTextToUrlEncoded
@Deprecated public static String convertTextToUrlEncoded(Object source, MediaType sourceType)
Deprecated.Since 13.0, without replacement.Convert text format to a URL safe format.- Parameters:
source
- the source text/plain content.sourceType
- the MediaType of the source content.- Returns:
- a String with the content URLEncoded.
- Throws:
EncodingException
- if the source format cannot be interpreted as plain/text.
-
convertOctetStreamToText
@Deprecated public static byte[] convertOctetStreamToText(byte[] source, MediaType destination)
Deprecated.Since 13.0, without replacment.Converts generic byte[] to text.- Parameters:
source
- byte[] to convert.destination
- MediaType of the desired text conversion.- Returns:
- byte[] content interpreted as text, in the encoding specified by the destination MediaType.
-
convertOctetStreamToJava
@Deprecated public static Object convertOctetStreamToJava(byte[] source, MediaType destination, Marshaller marshaller)
Deprecated.Since 13.0, without replacement.Converts an octet stream to a Java object- Parameters:
source
- The source to convertdestination
- The type of the converted object.- Returns:
- an instance of a java object compatible with the supplied destination type.
-
convertJavaToOctetStream
@Deprecated public static byte[] convertJavaToOctetStream(Object source, MediaType sourceMediaType, Marshaller marshaller) throws IOException, InterruptedException
Deprecated.Since 13.0, with no replacement.Converts a java object to a sequence of bytes applying standard java serialization.- 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.IOException
InterruptedException
-
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.IOException
InterruptedException
-
convertJavaToText
@Deprecated public static byte[] convertJavaToText(Object source, MediaType sourceMediaType, MediaType destinationMediaType)
Deprecated.Since 13.0 without replacement.Converts a java object to a text/plain representation.- Parameters:
source
- Object to convert.sourceMediaType
- The MediaType for the source object.destinationMediaType
- The required text/plain specification.- Returns:
- byte[] with the text/plain representation of the object with the requested charset.
-
decodeObjectContent
@Deprecated public static Object decodeObjectContent(Object content, MediaType contentMediaType)
Deprecated.Since 13.0, without replacement.Decode UTF-8 as a java object. For this conversion, the "type" parameter is used in the suppliedMediaType
. Currently supported types are primitives and String, plus a special "ByteArray" to describe a sequence of bytes.- Parameters:
content
- The content to decode.contentMediaType
- theMediaType
describing the content.- Returns:
- instance of Object according to the supplied MediaType "type" parameter, or if no type is present, the object itself.
- Throws:
EncodingException
- if the provided type is not supported.
-
convertCharset
public static byte[] convertCharset(Object content, Charset fromCharset, Charset toCharset)
Convert text content.- Parameters:
content
- Object to convert.fromCharset
- Charset of the provided content.toCharset
- Charset to convert to.- Returns:
- byte[] with the content in the desired charset.
-
decodeOctetStream
@Deprecated public static byte[] decodeOctetStream(Object input, MediaType octetStream)
Deprecated.Since 13.0, without replacement.Decode a octet-stream content that is not a byte[]. For this, it uses a special param called "encoding" in the "application/octet-stream" MediaType. The "encoding" param supports only the "hex" value that represents an octet-stream as a hexadecimal representation, for example "0xdeadbeef". In the absence of the "encoding" param, it will assume base64 encoding.- Parameters:
input
- Object representing the binary content.octetStream
- The MediaType describing the input.- Returns:
- a byte[] with the decoded content.
-
bytesToHex
@Deprecated public static String bytesToHex(byte[] bytes)
Deprecated.
-
hexToBytes
@Deprecated public static byte[] hexToBytes(String hex)
Deprecated.UseBase16Codec.decode(String)
instead.
-
convertUrlEncodedToObject
@Deprecated public static Object convertUrlEncodedToObject(Object content)
Deprecated.since 13.0 without replacement.Handle x-www-form-urlencoded as single values for now. Ideally it should generate a Map<String, String>
-
convertUrlEncodedToText
@Deprecated public static Object convertUrlEncodedToText(Object content, MediaType destinationType)
Deprecated.Since 13.0 without replacement.
-
convertUrlEncodedToOctetStream
@Deprecated public static Object convertUrlEncodedToOctetStream(Object content)
Deprecated.Since 13.0 without replacement.
-
urlEncode
@Deprecated public static String urlEncode(Object content, MediaType mediaType)
Deprecated.Since 13.0 without replacement.
-
urlDecode
@Deprecated public static Object urlDecode(Object content)
Deprecated.Since 13.0, without replacement.
-
convertOctetStreamToUrlEncoded
@Deprecated public static Object convertOctetStreamToUrlEncoded(Object content, MediaType contentType)
Deprecated.Since 13.0 without replacement.
-
-