Class ContentUtil

java.lang.Object
org.apache.james.mime4j.util.ContentUtil

public class ContentUtil extends Object
Utility methods for converting textual content of a message.
  • Field Details

  • Constructor Details

    • ContentUtil

      private ContentUtil()
  • Method Details

    • getBufferRecycler

      public static BufferRecycler getBufferRecycler()
    • getOutputStreamRecycler

      public static ByteArrayOutputStreamRecycler getOutputStreamRecycler()
    • copy

      public static void copy(InputStream in, OutputStream out) throws IOException
      Copies the contents of one stream to the other.
      Parameters:
      in - not null
      out - not null
      Throws:
      IOException
    • copy

      public static void copy(Reader in, Writer out) throws IOException
      Copies the contents of one stream to the other.
      Parameters:
      in - not null
      out - not null
      Throws:
      IOException
    • buffer

      public static byte[] buffer(InputStream in) throws IOException
      Throws:
      IOException
    • bufferEfficient

      public static ByteArrayOutputStreamRecycler.Wrapper bufferEfficient(InputStream in) throws IOException
      Throws:
      IOException
    • buffer

      public static String buffer(Reader in) throws IOException
      Throws:
      IOException
    • encode

      public static ByteSequence encode(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(Charset charset, 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 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 String decode(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 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 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 to decode(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 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.
      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 String decode(Charset charset, byte[] buffer, int offset, int length)
    • toByteArray

      public static byte[] toByteArray(String s, Charset charset)
    • toAsciiByteArray

      public static byte[] toAsciiByteArray(String s)
    • toString

      public static String toString(byte[] b, Charset charset)
    • toAsciiString

      public static String toAsciiString(byte[] b)
    • toString

      public static String toString(byte[] b, int off, int len, Charset charset)
    • toAsciiString

      public static String toAsciiString(byte[] b, int off, int len)
    • toString

      public static String toString(ByteArrayBuffer b, Charset charset)
    • toAsciiString

      public static String toAsciiString(ByteArrayBuffer b)