Package org.apache.james.mime4j.util
Class ContentUtil
java.lang.Object
org.apache.james.mime4j.util.ContentUtil
Utility methods for converting textual content of a message.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final ThreadLocal
<SoftReference<ByteArrayOutputStreamRecycler>> protected static final ThreadLocal
<SoftReference<BufferRecycler>> (package private) static final int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
buffer
(InputStream in) static String
static void
copy
(InputStream in, OutputStream out) Copies the contents of one stream to the other.static void
Copies the contents of one stream to the other.private static String
static String
decode
(Charset charset, ByteSequence byteSequence) Decodes the specified sequence of bytes into a string using the specified charset.static String
decode
(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 String
decode
(ByteSequence byteSequence) Decodes the specified sequence of bytes into a string using the US-ASCII charset.static 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.static String
decode
(ByteSequence byteSequence, int offset, int length, 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 ByteSequence
encode
(CharSequence string) Encodes the specified string into an immutable sequence of bytes using the US-ASCII charset.static ByteSequence
encode
(Charset charset, CharSequence string) Encodes the specified string into an immutable sequence of bytes using the specified charset.static BufferRecycler
static byte[]
static String
toAsciiString
(byte[] b) static String
toAsciiString
(byte[] b, int off, int len) static String
static byte[]
toByteArray
(String s, Charset charset) static String
static String
static String
toString
(ByteArrayBuffer b, Charset charset)
-
Field Details
-
_recyclerRef
-
_outputStreamRecyclerRef
protected static final ThreadLocal<SoftReference<ByteArrayOutputStreamRecycler>> _outputStreamRecyclerRef -
DEFAULT_COPY_BUFFER_SIZE
static final int DEFAULT_COPY_BUFFER_SIZE- See Also:
-
-
Constructor Details
-
ContentUtil
private ContentUtil()
-
-
Method Details
-
getBufferRecycler
-
getOutputStreamRecycler
-
copy
Copies the contents of one stream to the other.- Parameters:
in
- not nullout
- not null- Throws:
IOException
-
copy
Copies the contents of one stream to the other.- Parameters:
in
- not nullout
- not null- Throws:
IOException
-
buffer
- Throws:
IOException
-
bufferEfficient
public static ByteArrayOutputStreamRecycler.Wrapper bufferEfficient(InputStream in) throws IOException - Throws:
IOException
-
buffer
- Throws:
IOException
-
encode
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
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
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
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
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
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
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
-
toByteArray
-
toAsciiByteArray
-
toString
-
toAsciiString
-
toString
-
toAsciiString
-
toString
-
toAsciiString
-