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 Stringstatic voidcopy(InputStream in, OutputStream out) Copies the contents of one stream to the other.static voidCopies the contents of one stream to the other.private static Stringstatic Stringdecode(Charset charset, ByteSequence byteSequence) Decodes the specified sequence of bytes into a string using the specified charset.static Stringdecode(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 Stringdecode(ByteSequence byteSequence) Decodes the specified sequence of bytes into a string using the US-ASCII charset.static 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 Stringdecode(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 ByteSequenceencode(CharSequence string) Encodes the specified string into an immutable sequence of bytes using the US-ASCII charset.static ByteSequenceencode(Charset charset, CharSequence string) Encodes the specified string into an immutable sequence of bytes using the specified charset.static BufferRecyclerstatic byte[]static StringtoAsciiString(byte[] b) static StringtoAsciiString(byte[] b, int off, int len) static Stringstatic byte[]toByteArray(String s, Charset charset) static Stringstatic Stringstatic StringtoString(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
-