commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject cvs commit: jakarta-commons/codec/src/java/org/apache/commons/codec/net StringEncodings.java URLCodec.java QuotedPrintableCodec.java
Date Mon, 29 Mar 2004 07:59:00 GMT
ggregory    2004/03/28 23:59:00

  Modified:    codec/src/java/org/apache/commons/codec/net URLCodec.java
                        QuotedPrintableCodec.java
  Added:       codec/src/java/org/apache/commons/codec/net
                        StringEncodings.java
  Log:
  - Refactor String encoding names for reuse. 
  - Javadoc
  - Format.
  
  Revision  Changes    Path
  1.19      +23 -28    jakarta-commons/codec/src/java/org/apache/commons/codec/net/URLCodec.java
  
  Index: URLCodec.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/codec/src/java/org/apache/commons/codec/net/URLCodec.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- URLCodec.java	21 Mar 2004 01:58:40 -0000	1.18
  +++ URLCodec.java	29 Mar 2004 07:59:00 -0000	1.19
  @@ -47,17 +47,12 @@
    * @since 1.2
    * @version $Id$
    */
  -public class URLCodec 
  -        implements BinaryEncoder, BinaryDecoder, 
  -                   StringEncoder, StringDecoder 
  -{
  -    
  -    private final static String US_ASCII = "US-ASCII";
  +public class URLCodec implements BinaryEncoder, BinaryDecoder, StringEncoder, StringDecoder
{
       
       /**
        * The default charset used for string decoding and encoding.
        */
  -    protected String charset = "UTF-8";
  +    protected String charset = StringEncodings.UTF8;
       
       protected static byte ESCAPE_CHAR = '%';
       /**
  @@ -110,12 +105,12 @@
        * characters. Unsafe characters are escaped.
        *
        * @param urlsafe bitset of characters deemed URL safe
  -     * @param pArray array of bytes to convert to URL safe characters
  +     * @param bytes array of bytes to convert to URL safe characters
        * @return array of bytes containing URL safe characters
        */
  -    public static final byte[] encodeUrl(BitSet urlsafe, byte[] pArray) 
  +    public static final byte[] encodeUrl(BitSet urlsafe, byte[] bytes) 
       {
  -        if (pArray == null) {
  +        if (bytes == null) {
               return null;
           }
           if (urlsafe == null) {
  @@ -123,8 +118,8 @@
           }
           
           ByteArrayOutputStream buffer = new ByteArrayOutputStream(); 
  -        for (int i = 0; i < pArray.length; i++) {
  -            int b = pArray[i];
  +        for (int i = 0; i < bytes.length; i++) {
  +            int b = bytes[i];
               if (b < 0) {
                   b = 256 + b;
               }
  @@ -152,25 +147,25 @@
        * original bytes. Escaped characters are converted back to their 
        * original representation.
        *
  -     * @param pArray array of URL safe characters
  +     * @param bytes array of URL safe characters
        * @return array of original bytes 
        * @throws DecoderException Thrown if URL decoding is unsuccessful
        */
  -    public static final byte[] decodeUrl(byte[] pArray) 
  +    public static final byte[] decodeUrl(byte[] bytes) 
            throws DecoderException
       {
  -        if (pArray == null) {
  +        if (bytes == null) {
               return null;
           }
           ByteArrayOutputStream buffer = new ByteArrayOutputStream(); 
  -        for (int i = 0; i < pArray.length; i++) {
  -            int b = pArray[i];
  +        for (int i = 0; i < bytes.length; i++) {
  +            int b = bytes[i];
               if (b == '+') {
                   buffer.write(' ');
               } else if (b == '%') {
                   try {
  -                    int u = Character.digit((char)pArray[++i], 16);
  -                    int l = Character.digit((char)pArray[++i], 16);
  +                    int u = Character.digit((char)bytes[++i], 16);
  +                    int l = Character.digit((char)bytes[++i], 16);
                       if (u == -1 || l == -1) {
                           throw new DecoderException("Invalid URL encoding");
                       }
  @@ -190,11 +185,11 @@
        * Encodes an array of bytes into an array of URL safe 7-bit 
        * characters. Unsafe characters are escaped.
        *
  -     * @param pArray array of bytes to convert to URL safe characters
  +     * @param bytes array of bytes to convert to URL safe characters
        * @return array of bytes containing URL safe characters
        */
  -    public byte[] encode(byte[] pArray) {
  -        return encodeUrl(WWW_FORM_URL, pArray);
  +    public byte[] encode(byte[] bytes) {
  +        return encodeUrl(WWW_FORM_URL, bytes);
       }
   
   
  @@ -203,12 +198,12 @@
        * original bytes. Escaped characters are converted back to their 
        * original representation.
        *
  -     * @param pArray array of URL safe characters
  +     * @param bytes array of URL safe characters
        * @return array of original bytes 
        * @throws DecoderException Thrown if URL decoding is unsuccessful
        */
  -    public byte[] decode(byte[] pArray) throws DecoderException {
  -        return decodeUrl(pArray);
  +    public byte[] decode(byte[] bytes) throws DecoderException {
  +        return decodeUrl(bytes);
       }
   
   
  @@ -228,7 +223,7 @@
           if (pString == null) {
               return null;
           }
  -        return new String(encode(pString.getBytes(charset)), US_ASCII);
  +        return new String(encode(pString.getBytes(charset)), StringEncodings.US_ASCII);
       }
   
   
  @@ -272,7 +267,7 @@
           if (pString == null) {
               return null;
           }
  -        return new String(decode(pString.getBytes(US_ASCII)), charset);
  +        return new String(decode(pString.getBytes(StringEncodings.US_ASCII)), charset);
       }
   
   
  
  
  
  1.6       +176 -197  jakarta-commons/codec/src/java/org/apache/commons/codec/net/QuotedPrintableCodec.java
  
  Index: QuotedPrintableCodec.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/codec/src/java/org/apache/commons/codec/net/QuotedPrintableCodec.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- QuotedPrintableCodec.java	29 Mar 2004 01:32:07 -0000	1.5
  +++ QuotedPrintableCodec.java	29 Mar 2004 07:59:00 -0000	1.6
  @@ -1,25 +1,21 @@
   /*
  - * Copyright 2004 The Apache Software Foundation.
  + * Copyright 2001-2004 The Apache Software Foundation.
    * 
  - * Licensed under the Apache License, Version 2.0 (the "License");
  - * you may not use this file except in compliance with the License.
  - * You may obtain a copy of the License at
  + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
file except in compliance with
  + * the License. You may obtain a copy of the License at
    * 
  - *      http://www.apache.org/licenses/LICENSE-2.0
  + * http://www.apache.org/licenses/LICENSE-2.0
    * 
  - * Unless required by applicable law or agreed to in writing, software
  - * distributed under the License is distributed on an "AS IS" BASIS,
  - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  - * See the License for the specific language governing permissions and
  - * limitations under the License.
  - */ 
  + * Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on
  + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the
  + * specific language governing permissions and limitations under the License.
  + */
   
   package org.apache.commons.codec.net;
   
   import java.io.ByteArrayOutputStream;
   import java.io.UnsupportedEncodingException;
   import java.util.BitSet;
  -
   import org.apache.commons.codec.BinaryDecoder;
   import org.apache.commons.codec.BinaryEncoder;
   import org.apache.commons.codec.DecoderException;
  @@ -29,65 +25,50 @@
   
   /**
    * <p>
  - * Codec for the Quoted-Printable section of RFC 1521 MIME (Multipurpose Internet Mail
Extensions) Part One 
  - * Mechanisms for Specifying and Describing the Format of Internet Message Bodies.
  + * Codec for the Quoted-Printable section of <a href="http://www.ietf.org/rfc/rfc1521.txt">RFC
1521 </a>.
    * </p>
    * <p>
  - * The Quoted-Printable encoding is intended to represent data that
  - * largely consists of octets that correspond to printable characters in
  - * the ASCII character set.  It encodes the data in such a way that the
  - * resulting octets are unlikely to be modified by mail transport.  If
  - * the data being encoded are mostly ASCII text, the encoded form of the
  - * data remains largely recognizable by humans.  A body which is
  - * entirely ASCII may also be encoded in Quoted-Printable to ensure the
  - * integrity of the data should the message pass through a character-
  - * translating, and/or line-wrapping gateway.
  + * The Quoted-Printable encoding is intended to represent data that largely consists of
octets that correspond to
  + * printable characters in the ASCII character set. It encodes the data in such a way that
the resulting octets are
  + * unlikely to be modified by mail transport. If the data being encoded are mostly ASCII
text, the encoded form of the
  + * data remains largely recognizable by humans. A body which is entirely ASCII may also
be encoded in Quoted-Printable
  + * to ensure the integrity of the data should the message pass through a character- translating,
and/or line-wrapping
  + * gateway.
    * </p>
  - *  
  + * 
    * <p>
    * Note:
    * </p>
    * <p>
  - * Rules #3, #4, and #5 of the quoted-printable spec are not implemented yet 
  - * because the complete quoted-printable spec does not lend itself well
  - * into the byte[] oriented codec framework. Complete the codec once the
  - * steamable codec framework is ready. The motivation behind providing the codec in
  - * a partial form is that it can already come in handy for those applications that
  - * do not require quoted-printable line formatting (rules #3, #4, #5), for instance
  - * Q codec.
  + * Rules #3, #4, and #5 of the quoted-printable spec are not implemented yet because the
complete quoted-printable spec
  + * does not lend itself well into the byte[] oriented codec framework. Complete the codec
once the steamable codec
  + * framework is ready. The motivation behind providing the codec in a partial form is that
it can already come in handy
  + * for those applications that do not require quoted-printable line formatting (rules #3,
#4, #5), for instance Q codec.
    * </p>
    * 
  - * @see <a href="http://www.ietf.org/rfc/rfc1521.txt">
  - * RFC 1521 MIME (Multipurpose Internet Mail Extensions) Part One: Mechanisms for Specifying

  - * and Describing the Format of Internet Message Bodies</a>
  + * @see <a href="http://www.ietf.org/rfc/rfc1521.txt"> RFC 1521 MIME (Multipurpose
Internet Mail Extensions) Part One:
  + *          Mechanisms for Specifying and Describing the Format of Internet Message Bodies
</a>
    * 
    * @author Apache Software Foundation
    * @since 1.3
    * @version $Id$
    */
  -public class QuotedPrintableCodec 
  -        implements BinaryEncoder, BinaryDecoder, 
  -                   StringEncoder, StringDecoder 
  -{
  -    
  -    private final static String US_ASCII = "US-ASCII";
  -    
  +public class QuotedPrintableCodec implements BinaryEncoder, BinaryDecoder, StringEncoder,
StringDecoder {
       /**
        * The default charset used for string decoding and encoding.
        */
  -    protected String charset = "UTF-8";
  -    
  +    private String charset = StringEncodings.UTF8;
  +
       /**
        * BitSet of printable characters as defined in RFC 1521.
        */
  -    protected static final BitSet PRINTABLE_CHARS = new BitSet(256);
  -    
  -    protected static byte ESCAPE_CHAR = '=';
  -    protected static byte TAB = 9;
  -    protected static byte CR = 13;
  -    protected static byte LF = 10;
  -    protected static byte SPACE = 32;
  -    
  +    private static final BitSet PRINTABLE_CHARS = new BitSet(256);
  +
  +    private static byte ESCAPE_CHAR = '=';
  +
  +    private static byte TAB = 9;
  +
  +    private static byte SPACE = 32;
       // Static initializer for printable chars collection
       static {
           // alpha characters
  @@ -101,7 +82,6 @@
           PRINTABLE_CHARS.set(SPACE);
       }
   
  -
       /**
        * Default constructor.
        */
  @@ -112,7 +92,8 @@
       /**
        * Constructor which allows for the selection of a default charset
        * 
  -     * @param charset the default string charset to use.
  +     * @param charset
  +     *                  the default string charset to use.
        */
       public QuotedPrintableCodec(String charset) {
           super();
  @@ -122,43 +103,43 @@
       /**
        * Encodes byte into its quoted-printable representation.
        * 
  -     * @param b byte to encode
  -     * @param buffer the buffer to write to 
  +     * @param b
  +     *                  byte to encode
  +     * @param buffer
  +     *                  the buffer to write to
        */
  -    private static final void encodeQuotedPrintable(int b, ByteArrayOutputStream buffer)
  -    {
  +    private static final void encodeQuotedPrintable(int b, ByteArrayOutputStream buffer)
{
           buffer.write(ESCAPE_CHAR);
  -        char hex1 = Character.toUpperCase(
  -          Character.forDigit((b >> 4) & 0xF, 16));
  -        char hex2 = Character.toUpperCase(
  -          Character.forDigit(b & 0xF, 16));
  +        char hex1 = Character.toUpperCase(Character.forDigit((b >> 4) & 0xF,
16));
  +        char hex2 = Character.toUpperCase(Character.forDigit(b & 0xF, 16));
           buffer.write(hex1);
           buffer.write(hex2);
       }
   
       /**
  -     * Encodes an array of bytes into an array of quoted-printable 7-bit 
  -     * characters. Unsafe characters are escaped.
  +     * Encodes an array of bytes into an array of quoted-printable 7-bit characters. Unsafe
characters are escaped.
        * 
  -     * <p>This function implements a subset of quoted-printable encoding 
  -     * specification (rule #1 and rule #2) as defined in RFC 1521 and is 
  -     * suitable for encoding binary data and unformatted text.
  +     * <p>
  +     * This function implements a subset of quoted-printable encoding specification (rule
#1 and rule #2) as defined in
  +     * RFC 1521 and is suitable for encoding binary data and unformatted text.
        * </p>
  -     *
  -     * @param printable bitset of characters deemed quoted-printable
  -     * @param pArray array of bytes to be encoded
  +     * 
  +     * @param printable
  +     *                  bitset of characters deemed quoted-printable
  +     * @param bytes
  +     *                  array of bytes to be encoded
        * @return array of bytes containing quoted-printable data
        */
  -    public static final byte[] encodeQuotedPrintable(BitSet printable, byte[] pArray) {
  -        if (pArray == null) {
  +    public static final byte[] encodeQuotedPrintable(BitSet printable, byte[] bytes) {
  +        if (bytes == null) {
               return null;
           }
           if (printable == null) {
               printable = PRINTABLE_CHARS;
           }
           ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  -        for (int i = 0; i < pArray.length; i++) {
  -            int b = pArray[i];
  +        for (int i = 0; i < bytes.length; i++) {
  +            int b = bytes[i];
               if (b < 0) {
                   b = 256 + b;
               }
  @@ -171,95 +152,95 @@
           return buffer.toByteArray();
       }
   
  -
       /**
  -     * Decodes an array quoted-printable characters into an array of 
  -     * original bytes. Escaped characters are converted back to their 
  -     * original representation.
  -     *
  -     * <p>This function implements a subset of quoted-printable encoding 
  -     * specification (rule #1 and rule #2) as defined in RFC 1521.
  +     * Decodes an array quoted-printable characters into an array of original bytes. Escaped
characters are converted
  +     * back to their original representation.
  +     * 
  +     * <p>
  +     * This function implements a subset of quoted-printable encoding specification (rule
#1 and rule #2) as defined in
  +     * RFC 1521.
        * </p>
        * 
  -     * @param pArray array of quoted-printable characters
  -     * @return array of original bytes 
  -     * @throws DecoderException Thrown if quoted-printable decoding is unsuccessful
  -     */
  -    public static final byte[] decodeQuotedPrintable(byte[] pArray) 
  -         throws DecoderException
  -    {
  -        if (pArray == null) {
  +     * @param bytes
  +     *                  array of quoted-printable characters
  +     * @return array of original bytes
  +     * @throws DecoderException
  +     *                  Thrown if quoted-printable decoding is unsuccessful
  +     */
  +    public static final byte[] decodeQuotedPrintable(byte[] bytes) throws DecoderException
{
  +        if (bytes == null) {
               return null;
           }
  -        ByteArrayOutputStream buffer = new ByteArrayOutputStream(); 
  -        for (int i = 0; i < pArray.length; i++) {
  -            int b = pArray[i];
  +        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  +        for (int i = 0; i < bytes.length; i++) {
  +            int b = bytes[i];
               if (b == ESCAPE_CHAR) {
                   try {
  -                    int u = Character.digit((char)pArray[++i], 16);
  -                    int l = Character.digit((char)pArray[++i], 16);
  +                    int u = Character.digit((char) bytes[++i], 16);
  +                    int l = Character.digit((char) bytes[++i], 16);
                       if (u == -1 || l == -1) {
                           throw new DecoderException("Invalid quoted-printable encoding");
                       }
  -                    buffer.write((char)((u << 4) + l));
  -                } catch(ArrayIndexOutOfBoundsException e) {
  +                    buffer.write((char) ((u << 4) + l));
  +                } catch (ArrayIndexOutOfBoundsException e) {
                       throw new DecoderException("Invalid quoted-printable encoding");
                   }
               } else {
                   buffer.write(b);
               }
           }
  -        return buffer.toByteArray(); 
  +        return buffer.toByteArray();
       }
   
  -
       /**
  -     * Encodes an array of bytes into an array of quoted-printable 7-bit 
  -     * characters. Unsafe characters are escaped.
  +     * Encodes an array of bytes into an array of quoted-printable 7-bit characters. Unsafe
characters are escaped.
        * 
  -     * <p>This function implements a subset of quoted-printable encoding 
  -     * specification (rule #1 and rule #2) as defined in RFC 1521 and is 
  -     * suitable for encoding binary data and unformatted text.
  +     * <p>
  +     * This function implements a subset of quoted-printable encoding specification (rule
#1 and rule #2) as defined in
  +     * RFC 1521 and is suitable for encoding binary data and unformatted text.
        * </p>
  -     *
  -     * @param pArray array of bytes to be encoded
  +     * 
  +     * @param bytes
  +     *                  array of bytes to be encoded
        * @return array of bytes containing quoted-printable data
        */
  -    public byte[] encode(byte[] pArray) {
  -        return encodeQuotedPrintable(PRINTABLE_CHARS, pArray);
  +    public byte[] encode(byte[] bytes) {
  +        return encodeQuotedPrintable(PRINTABLE_CHARS, bytes);
       }
   
  -
       /**
  -     * Decodes an array of quoted-printable characters into an array of 
  -     * original bytes. Escaped characters are converted back to their 
  -     * original representation.
  -     *
  -     * <p>This function implements a subset of quoted-printable encoding 
  -     * specification (rule #1 and rule #2) as defined in RFC 1521.
  +     * Decodes an array of quoted-printable characters into an array of original bytes.
Escaped characters are converted
  +     * back to their original representation.
  +     * 
  +     * <p>
  +     * This function implements a subset of quoted-printable encoding specification (rule
#1 and rule #2) as defined in
  +     * RFC 1521.
        * </p>
        * 
  -     * @param pArray array of quoted-printable characters
  -     * @return array of original bytes 
  -     * @throws DecoderException Thrown if quoted-printable decoding is unsuccessful
  +     * @param bytes
  +     *                  array of quoted-printable characters
  +     * @return array of original bytes
  +     * @throws DecoderException
  +     *                  Thrown if quoted-printable decoding is unsuccessful
        */
  -    public byte[] decode(byte[] pArray) throws DecoderException {
  -        return decodeQuotedPrintable(pArray);
  +    public byte[] decode(byte[] bytes) throws DecoderException {
  +        return decodeQuotedPrintable(bytes);
       }
   
       /**
  -     * Encodes a string into its quoted-printable form using the default
  -     * string charset. Unsafe characters are escaped.
  +     * Encodes a string into its quoted-printable form using the default string charset.
Unsafe characters are escaped.
        * 
  -     * <p>This function implements a subset of quoted-printable encoding 
  -     * specification (rule #1 and rule #2) as defined in RFC 1521 and is 
  -     * suitable for encoding binary data.
  +     * <p>
  +     * This function implements a subset of quoted-printable encoding specification (rule
#1 and rule #2) as defined in
  +     * RFC 1521 and is suitable for encoding binary data.
        * </p>
  -     *
  -     * @param pString string to convert to quoted-printable form
  +     * 
  +     * @param pString
  +     *                  string to convert to quoted-printable form
        * @return quoted-printable string
        * 
  -     * @throws EncoderException Thrown if quoted-printable encoding is unsuccessful
  +     * @throws EncoderException
  +     *                  Thrown if quoted-printable encoding is unsuccessful
        * 
        * @see #getDefaultCharset()
        */
  @@ -269,44 +250,43 @@
           }
           try {
               return encode(pString, getDefaultCharset());
  -        } catch(UnsupportedEncodingException e) {
  +        } catch (UnsupportedEncodingException e) {
               throw new EncoderException(e.getMessage());
           }
       }
   
       /**
  -     * Decodes a quoted-printable string into its original form using the 
  -     * specified string charset. Escaped characters are converted back 
  -     * to their original representation.
  -     *
  -     * @param pString quoted-printable string to convert into its original form
  -     * @param charset the original string charset
  -     * @return original string 
  -     * @throws DecoderException Thrown if quoted-printable decoding is 
  -     *                          unsuccessful
  -     * @throws UnsupportedEncodingException Thrown if charset is not
  -     *                                      supported 
  -     */
  -    public String decode(String pString, String charset) 
  -        throws DecoderException, UnsupportedEncodingException 
  -    {
  +     * Decodes a quoted-printable string into its original form using the specified string
charset. Escaped characters
  +     * are converted back to their original representation.
  +     * 
  +     * @param pString
  +     *                  quoted-printable string to convert into its original form
  +     * @param charset
  +     *                  the original string charset
  +     * @return original string
  +     * @throws DecoderException
  +     *                  Thrown if quoted-printable decoding is unsuccessful
  +     * @throws UnsupportedEncodingException
  +     *                  Thrown if charset is not supported
  +     */
  +    public String decode(String pString, String charset) throws DecoderException, UnsupportedEncodingException
{
           if (pString == null) {
               return null;
           }
  -        return new String(decode(pString.getBytes(US_ASCII)), charset);
  +        return new String(decode(pString.getBytes(StringEncodings.US_ASCII)), charset);
       }
   
       /**
  -     * Decodes a quoted-printable string into its original form using the 
  -     * default string charset. Escaped characters are converted back 
  -     * to their original representation.
  -     *
  -     * @param pString quoted-printable string to convert into its original form
  -     * @return original string 
  -     * @throws DecoderException Thrown if quoted-printable decoding is 
  -     *                          unsuccessful
  -     * @throws UnsupportedEncodingException Thrown if charset is not
  -     *                                      supported
  +     * Decodes a quoted-printable string into its original form using the default string
charset. Escaped characters are
  +     * converted back to their original representation.
  +     * 
  +     * @param pString
  +     *                  quoted-printable string to convert into its original form
  +     * @return original string
  +     * @throws DecoderException
  +     *                  Thrown if quoted-printable decoding is unsuccessful
  +     * @throws UnsupportedEncodingException
  +     *                  Thrown if charset is not supported
        * @see #getDefaultCharset()
        */
       public String decode(String pString) throws DecoderException {
  @@ -315,62 +295,63 @@
           }
           try {
               return decode(pString, getDefaultCharset());
  -        } catch(UnsupportedEncodingException e) {
  +        } catch (UnsupportedEncodingException e) {
               throw new DecoderException(e.getMessage());
           }
       }
   
       /**
  -     * Encodes an object into its quoted-printable safe form. Unsafe 
  -     * characters are escaped.
  -     *
  -     * @param pObject string to convert to a quoted-printable form
  +     * Encodes an object into its quoted-printable safe form. Unsafe characters are escaped.
  +     * 
  +     * @param pObject
  +     *                  string to convert to a quoted-printable form
        * @return quoted-printable object
  -     * @throws EncoderException Thrown if quoted-printable encoding is not 
  -     *                          applicable to objects of this type or
  -     *                          if encoding is unsuccessful
  +     * @throws EncoderException
  +     *                  Thrown if quoted-printable encoding is not applicable to objects
of this type or if encoding is
  +     *                  unsuccessful
        */
       public Object encode(Object pObject) throws EncoderException {
           if (pObject == null) {
               return null;
           } else if (pObject instanceof byte[]) {
  -            return encode((byte[])pObject);
  +            return encode((byte[]) pObject);
           } else if (pObject instanceof String) {
  -            return encode((String)pObject);
  +            return encode((String) pObject);
           } else {
  -            throw new EncoderException("Objects of type " +
  -                pObject.getClass().getName() + " cannot be quoted-printable encoded");

  -              
  +            throw new EncoderException("Objects of type "
  +                + pObject.getClass().getName()
  +                + " cannot be quoted-printable encoded");
           }
       }
   
       /**
  -     * Decodes a quoted-printable object into its original form. Escaped 
  -     * characters are converted back to their original representation.
  -     *
  -     * @param pObject quoted-printable object to convert into its original form
  -     * @return original object 
  -     * @throws DecoderException Thrown if quoted-printable decoding is not 
  -     *                          applicable to objects of this type
  -     *                          if decoding is unsuccessful
  +     * Decodes a quoted-printable object into its original form. Escaped characters are
converted back to their original
  +     * representation.
  +     * 
  +     * @param pObject
  +     *                  quoted-printable object to convert into its original form
  +     * @return original object
  +     * @throws DecoderException
  +     *                  Thrown if quoted-printable decoding is not applicable to objects
of this type if decoding is
  +     *                  unsuccessful
        */
       public Object decode(Object pObject) throws DecoderException {
           if (pObject == null) {
               return null;
           } else if (pObject instanceof byte[]) {
  -            return decode((byte[])pObject);
  +            return decode((byte[]) pObject);
           } else if (pObject instanceof String) {
  -            return decode((String)pObject);
  +            return decode((String) pObject);
           } else {
  -            throw new DecoderException("Objects of type " +
  -                pObject.getClass().getName() + " cannot be quoted-printable decoded");

  -              
  +            throw new DecoderException("Objects of type "
  +                + pObject.getClass().getName()
  +                + " cannot be quoted-printable decoded");
           }
       }
   
       /**
        * Returns the default charset used for string decoding and encoding.
  -     *
  +     * 
        * @return the default string charset.
        */
       public String getDefaultCharset() {
  @@ -378,28 +359,26 @@
       }
   
       /**
  -     * Encodes a string into its quoted-printable form using the specified
  -     * charset. Unsafe characters are escaped.
  +     * Encodes a string into its quoted-printable form using the specified charset. Unsafe
characters are escaped.
        * 
  -     * <p>This function implements a subset of quoted-printable encoding 
  -     * specification (rule #1 and rule #2) as defined in RFC 1521 and is 
  -     * suitable for encoding binary data and unformatted text.
  +     * <p>
  +     * This function implements a subset of quoted-printable encoding specification (rule
#1 and rule #2) as defined in
  +     * RFC 1521 and is suitable for encoding binary data and unformatted text.
        * </p>
  -     *
  -     * @param pString string to convert to quoted-printable form
  -     * @param charset the charset for pString
  +     * 
  +     * @param pString
  +     *                  string to convert to quoted-printable form
  +     * @param charset
  +     *                  the charset for pString
        * @return quoted-printable string
        * 
  -     * @throws UnsupportedEncodingException Thrown if the charset is not
  -     *                                      supported 
  +     * @throws UnsupportedEncodingException
  +     *                  Thrown if the charset is not supported
        */
  -    public String encode(String pString, String charset) 
  -        throws UnsupportedEncodingException  
  -    {
  +    public String encode(String pString, String charset) throws UnsupportedEncodingException
{
           if (pString == null) {
               return null;
           }
  -        return new String(encode(pString.getBytes(charset)), US_ASCII);
  +        return new String(encode(pString.getBytes(charset)), StringEncodings.US_ASCII);
       }
  -
  -}
  +}
  \ No newline at end of file
  
  
  
  1.1                  jakarta-commons/codec/src/java/org/apache/commons/codec/net/StringEncodings.java
  
  Index: StringEncodings.java
  ===================================================================
  /*
   * Copyright 2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
file except in compliance with
   * the License. You may obtain a copy of the License at
   * 
   * http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on
   * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the
   * specific language governing permissions and limitations under the License.
   */
  
  package org.apache.commons.codec.net;
  
  /**
   * String encodings used in this package.
   * 
   * @author Apache Software Foundation
   * @since 1.3
   * @version $Id: StringEncodings.java,v 1.1 2004/03/29 07:59:00 ggregory Exp $
   */
  interface StringEncodings {
      /**
       * <p>
       * Seven-bit ASCII, also known as ISO646-US, also known as the Basic Latin block of
the Unicode character set.
       * </p>
       * <p>
       * Every implementation of the Java platform is required to support this character encoding.
       * </p>
       * 
       * @see <a href="http://java.sun.com/j2se/1.3/docs/api/java/lang/package-summary.html#charenc">JRE
character
       *          encoding names</a>
       */
      String US_ASCII = "US-ASCII";
  
      /**
       * <p>
       * Eight-bit Unicode Transformation Format.
       * </p>
       * <p>
       * Every implementation of the Java platform is required to support this character encoding.
       * </p>
       * 
       * @see <a href="http://java.sun.com/j2se/1.3/docs/api/java/lang/package-summary.html#charenc">JRE
character
       *          encoding names</a>
       */
      String UTF8 = "UTF-8";
  }
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message