org.apache.geronimo.mail.util
Class ASCIIUtil

java.lang.Object
  extended by org.apache.geronimo.mail.util.ASCIIUtil

public class ASCIIUtil
extends Object

Set of utility classes for handling common encoding-related manipulations.


Constructor Summary
ASCIIUtil()
           
 
Method Summary
static String getBinaryTransferEncoding(InputStream content)
          Determine if the transfer encoding looks like it might be valid ascii text, and thus transferable as 7bit code.
static String getTextTransferEncoding(InputStream content)
          Examine a stream of text and make a judgement on what encoding type should be used for the text.
static String getTextTransferEncoding(String content)
          Examine a stream of text and make a judgement on what encoding type should be used for the text.
static boolean isAscii(int ch)
          Test to see if a given character can be considered "valid" ASCII.
static boolean isAscii(String s)
          Test to see if this string contains only US-ASCII (i.e., 7-bit ASCII) charactes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ASCIIUtil

public ASCIIUtil()
Method Detail

isAscii

public static boolean isAscii(String s)
Test to see if this string contains only US-ASCII (i.e., 7-bit ASCII) charactes.

Parameters:
s - The test string.
Returns:
true if this is a valid 7-bit ASCII encoding, false if it contains any non-US ASCII characters.

isAscii

public static boolean isAscii(int ch)
Test to see if a given character can be considered "valid" ASCII. The excluded characters are the control characters less than 32, 8-bit characters greater than 127, EXCEPT the CR, LF and tab characters ARE considered value (all less than 32).

Parameters:
ch - The test character.
Returns:
true if this character meets the "ascii-ness" criteria, false otherwise.

getTextTransferEncoding

public static String getTextTransferEncoding(InputStream content)
                                      throws IOException
Examine a stream of text and make a judgement on what encoding type should be used for the text. Ideally, we want to use 7bit encoding to determine this, but we may need to use either quoted-printable or base64. The choice is made on the ratio of 7-bit characters to non-7bit.

Parameters:
content - An input stream for the content we're examining.
Throws:
IOException

getTextTransferEncoding

public static String getTextTransferEncoding(String content)
Examine a stream of text and make a judgement on what encoding type should be used for the text. Ideally, we want to use 7bit encoding to determine this, but we may need to use either quoted-printable or base64. The choice is made on the ratio of 7-bit characters to non-7bit.

Parameters:
content - A string for the content we're examining.

getBinaryTransferEncoding

public static String getBinaryTransferEncoding(InputStream content)
                                        throws IOException
Determine if the transfer encoding looks like it might be valid ascii text, and thus transferable as 7bit code. In order for this to be true, all characters must be valid 7-bit ASCII code AND all line breaks must be properly formed (JUST '\r\n' sequences). 7-bit transfers also typically have a line limit of 1000 bytes (998 + the CRLF), so any stretch of charactes longer than that will also force Base64 encoding.

Parameters:
content - An input stream for the content we're examining.
Throws:
IOException


Copyright © 2006 Apache Software Foundation. All Rights Reserved.