com.openexchange.mail.utils
Class CharsetDetector

java.lang.Object
  extended by com.openexchange.mail.utils.CharsetDetector

public final class CharsetDetector
extends java.lang.Object

CharsetDetector - A charset detector based on jchardet library.

Author:
Thorben Betten

Method Summary
static boolean checkName(java.lang.String s)
          Checks that the given string is a legal charset name.
static java.lang.String detectCharset(java.io.ByteArrayInputStream in)
          Detects the charset of specified byte array input stream's data.
static java.lang.String detectCharset(java.io.InputStream in)
          Detects the charset of specified input stream's data.
static java.lang.String detectPartCharset(javax.mail.Part p)
          Detects the charset of specified part.
static boolean isValid(java.lang.String charset)
          Convenience method to check if given name is valid; meaning not null, a legal charset name and supported as indicated by Charset.isSupported(String).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isValid

public static boolean isValid(java.lang.String charset)
Convenience method to check if given name is valid; meaning not null, a legal charset name and supported as indicated by Charset.isSupported(String).

Parameters:
charset - The charset name whose validity shall be checked
Returns:
true if given name is valid; otherwise false

checkName

public static boolean checkName(java.lang.String s)
Checks that the given string is a legal charset name.

Parameters:
s - The charset name
Returns:
true if the given name is a legal charset name; otherwise false
Throws:
java.lang.NullPointerException - If given name is null

detectPartCharset

public static java.lang.String detectPartCharset(javax.mail.Part p)
                                          throws javax.mail.MessagingException
Detects the charset of specified part.

Parameters:
p - The part whose charset shall be detected
Returns:
The detected part's charset
Throws:
javax.mail.MessagingException - If an error occurs in part's getter methods

detectCharset

public static java.lang.String detectCharset(java.io.ByteArrayInputStream in)
Detects the charset of specified byte array input stream's data.

Note: Specified input stream is going to be closed in this method.

Parameters:
in - The byte array input stream to examine
Returns:
The detected charset or US-ASCII if no matching/supported charset could be found
Throws:
java.lang.NullPointerException - If input stream is null

detectCharset

public static java.lang.String detectCharset(java.io.InputStream in)
Detects the charset of specified input stream's data.

Note: Specified input stream is going to be closed in this method.

Parameters:
in - The input stream to examine
Returns:
The detected charset or US-ASCII if no matching/supported charset could be found
Throws:
java.lang.NullPointerException - If input stream is null