Package org.apache.james.mime4j.util
Class ContentUtil
- java.lang.Object
-
- org.apache.james.mime4j.util.ContentUtil
-
public class ContentUtil extends java.lang.ObjectUtility methods for converting textual content of a message.
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.ThreadLocal<java.lang.ref.SoftReference<ByteArrayOutputStreamRecycler>>_outputStreamRecyclerRefprotected static java.lang.ThreadLocal<java.lang.ref.SoftReference<BufferRecycler>>_recyclerRef(package private) static intDEFAULT_COPY_BUFFER_SIZE
-
Constructor Summary
Constructors Modifier Constructor Description privateContentUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]buffer(java.io.InputStream in)static java.lang.Stringbuffer(java.io.Reader in)static ByteArrayOutputStreamRecycler.WrapperbufferEfficient(java.io.InputStream in)static voidcopy(java.io.InputStream in, java.io.OutputStream out)Copies the contents of one stream to the other.static voidcopy(java.io.Reader in, java.io.Writer out)Copies the contents of one stream to the other.private static java.lang.Stringdecode(java.nio.charset.Charset charset, byte[] buffer, int offset, int length)static java.lang.Stringdecode(java.nio.charset.Charset charset, ByteSequence byteSequence)Decodes the specified sequence of bytes into a string using the specified charset.static java.lang.Stringdecode(java.nio.charset.Charset charset, ByteSequence byteSequence, int offset, int length)Decodes a sub-sequence of the specified sequence of bytes into a string using the specified charset.static java.lang.Stringdecode(ByteSequence byteSequence)Decodes the specified sequence of bytes into a string using the US-ASCII charset.static java.lang.Stringdecode(ByteSequence byteSequence, int offset, int length)Decodes a sub-sequence of the specified sequence of bytes into a string using the US-ASCII charset.static java.lang.Stringdecode(ByteSequence byteSequence, int offset, int length, java.nio.charset.Charset charset)Decodes a sub-sequence of the specified sequence of bytes into a string using the US-ASCII charset with falling back todecode(Charset, ByteSequence, int, int)on a first non US-ASCII character.static ByteSequenceencode(java.lang.CharSequence string)Encodes the specified string into an immutable sequence of bytes using the US-ASCII charset.static ByteSequenceencode(java.nio.charset.Charset charset, java.lang.CharSequence string)Encodes the specified string into an immutable sequence of bytes using the specified charset.static BufferRecyclergetBufferRecycler()static ByteArrayOutputStreamRecyclergetOutputStreamRecycler()static byte[]toAsciiByteArray(java.lang.String s)static java.lang.StringtoAsciiString(byte[] b)static java.lang.StringtoAsciiString(byte[] b, int off, int len)static java.lang.StringtoAsciiString(ByteArrayBuffer b)static byte[]toByteArray(java.lang.String s, java.nio.charset.Charset charset)static java.lang.StringtoString(byte[] b, int off, int len, java.nio.charset.Charset charset)static java.lang.StringtoString(byte[] b, java.nio.charset.Charset charset)static java.lang.StringtoString(ByteArrayBuffer b, java.nio.charset.Charset charset)
-
-
-
Field Detail
-
_recyclerRef
protected static final java.lang.ThreadLocal<java.lang.ref.SoftReference<BufferRecycler>> _recyclerRef
-
_outputStreamRecyclerRef
protected static final java.lang.ThreadLocal<java.lang.ref.SoftReference<ByteArrayOutputStreamRecycler>> _outputStreamRecyclerRef
-
DEFAULT_COPY_BUFFER_SIZE
static final int DEFAULT_COPY_BUFFER_SIZE
- See Also:
- Constant Field Values
-
-
Method Detail
-
getBufferRecycler
public static BufferRecycler getBufferRecycler()
-
getOutputStreamRecycler
public static ByteArrayOutputStreamRecycler getOutputStreamRecycler()
-
copy
public static void copy(java.io.InputStream in, java.io.OutputStream out) throws java.io.IOExceptionCopies the contents of one stream to the other.- Parameters:
in- not nullout- not null- Throws:
java.io.IOException
-
copy
public static void copy(java.io.Reader in, java.io.Writer out) throws java.io.IOExceptionCopies the contents of one stream to the other.- Parameters:
in- not nullout- not null- Throws:
java.io.IOException
-
buffer
public static byte[] buffer(java.io.InputStream in) throws java.io.IOException- Throws:
java.io.IOException
-
bufferEfficient
public static ByteArrayOutputStreamRecycler.Wrapper bufferEfficient(java.io.InputStream in) throws java.io.IOException
- Throws:
java.io.IOException
-
buffer
public static java.lang.String buffer(java.io.Reader in) throws java.io.IOException- Throws:
java.io.IOException
-
encode
public static ByteSequence encode(java.lang.CharSequence string)
Encodes the specified string into an immutable sequence of bytes using the US-ASCII charset.- Parameters:
string- string to encode.- Returns:
- encoded string as an immutable sequence of bytes.
-
encode
public static ByteSequence encode(java.nio.charset.Charset charset, java.lang.CharSequence string)
Encodes the specified string into an immutable sequence of bytes using the specified charset.- Parameters:
charset- Java charset to be used for the conversion.string- string to encode.- Returns:
- encoded string as an immutable sequence of bytes.
-
decode
public static java.lang.String decode(ByteSequence byteSequence)
Decodes the specified sequence of bytes into a string using the US-ASCII charset.- Parameters:
byteSequence- sequence of bytes to decode.- Returns:
- decoded string.
-
decode
public static java.lang.String decode(java.nio.charset.Charset charset, ByteSequence byteSequence)Decodes the specified sequence of bytes into a string using the specified charset.- Parameters:
charset- Java charset to be used for the conversion.byteSequence- sequence of bytes to decode.- Returns:
- decoded string.
-
decode
public static java.lang.String decode(ByteSequence byteSequence, int offset, int length)
Decodes a sub-sequence of the specified sequence of bytes into a string using the US-ASCII charset.- Parameters:
byteSequence- sequence of bytes to decode.offset- offset into the byte sequence.length- number of bytes.- Returns:
- decoded string.
-
decode
public static java.lang.String decode(ByteSequence byteSequence, int offset, int length, java.nio.charset.Charset charset)
Decodes a sub-sequence of the specified sequence of bytes into a string using the US-ASCII charset with falling back todecode(Charset, ByteSequence, int, int)on a first non US-ASCII character.- Parameters:
byteSequence- sequence of bytes to decode.offset- offset into the byte sequence.length- number of bytes.charset- fallback charset.- Returns:
- decoded string.
-
decode
public static java.lang.String decode(java.nio.charset.Charset charset, ByteSequence byteSequence, int offset, int length)Decodes a sub-sequence of the specified sequence of bytes into a string using the specified charset.- Parameters:
charset- Java charset to be used for the conversion.byteSequence- sequence of bytes to decode.offset- offset into the byte sequence.length- number of bytes.- Returns:
- decoded string.
-
decode
private static java.lang.String decode(java.nio.charset.Charset charset, byte[] buffer, int offset, int length)
-
toByteArray
public static byte[] toByteArray(java.lang.String s, java.nio.charset.Charset charset)
-
toAsciiByteArray
public static byte[] toAsciiByteArray(java.lang.String s)
-
toString
public static java.lang.String toString(byte[] b, java.nio.charset.Charset charset)
-
toAsciiString
public static java.lang.String toAsciiString(byte[] b)
-
toString
public static java.lang.String toString(byte[] b, int off, int len, java.nio.charset.Charset charset)
-
toAsciiString
public static java.lang.String toAsciiString(byte[] b, int off, int len)
-
toString
public static java.lang.String toString(ByteArrayBuffer b, java.nio.charset.Charset charset)
-
toAsciiString
public static java.lang.String toAsciiString(ByteArrayBuffer b)
-
-