oglueck     2003/01/16 02:53:09

  Modified:    httpclient/src/examples PostXML.java
               httpclient/src/java/org/apache/commons/httpclient
                        Authenticator.java ChunkedInputStream.java
                        ChunkedOutputStream.java HttpConnection.java
                        HttpMethodBase.java NTLM.java
                        RequestOutputStream.java WireLogInputStream.java
               httpclient/src/java/org/apache/commons/httpclient/methods
                        PostMethod.java PutMethod.java
               httpclient/src/java/org/apache/commons/httpclient/methods/multipart
                        FilePart.java Part.java StringPart.java
               httpclient/src/java/org/apache/commons/httpclient/util
                        Base64.java URIUtil.java
               httpclient/src/test/org/apache/commons/httpclient
                        SimpleHttpConnection.java TestAuthenticator.java
                        TestBase64.java TestStreams.java
                        TestWebappMethods.java TestWebappRedirect.java
  Added:       httpclient/src/java/org/apache/commons/httpclient
                        HttpConstants.java
  Log:
  fixed undefined encodings all over httpclient
  makes httpclient code platform independent
  
  Contributed by: Oleg Kalnichevski
  Reviewed by: Ortwin Glück
  
  Revision  Changes    Path
  1.5       +4 -8      jakarta-commons/httpclient/src/examples/PostXML.java
  
  Index: PostXML.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/examples/PostXML.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PostXML.java      17 Dec 2002 01:28:32 -0000      1.4
  +++ PostXML.java      16 Jan 2003 10:53:07 -0000      1.5
  @@ -130,11 +130,7 @@
                
                System.out.println("iResultCode = " + iResultCode);
   
  -             byte[] yaResponse = post.getResponseBody();
  -             
  -             System.out.println("Server response:");
  -             
  -             System.out.println( new String(yaResponse) );
  +             System.out.println("Server response:" + post.getResponseBodyAsString() 
);
   
           post.releaseConnection();
        }
  
  
  
  1.36      +16 -20    
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/Authenticator.java
  
  Index: Authenticator.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/Authenticator.java,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- Authenticator.java        3 Dec 2002 15:20:31 -0000       1.35
  +++ Authenticator.java        16 Jan 2003 10:53:08 -0000      1.36
  @@ -206,9 +206,9 @@
   
           // Calculating digest according to rfc 2617
           String a2 = method + ":" + uri;
  -        String md5a2 = encode(md5Helper.digest(a2.getBytes()));
  +        String md5a2 = encode(md5Helper.digest(HttpConstants.getBytes(a2)));
           String digestValue = uname + ":" + realm + ":" + pwd;
  -        String md5a1 = encode(md5Helper.digest(digestValue.getBytes()));
  +        String md5a1 = 
encode(md5Helper.digest(HttpConstants.getBytes(digestValue)));
           String serverDigestValue;
   
           if (qop == null) {
  @@ -219,7 +219,7 @@
           }
   
           String serverDigest =
  -            encode(md5Helper.digest(serverDigestValue.getBytes()));
  +            encode(md5Helper.digest(HttpConstants.getBytes(serverDigestValue)));
   
           return serverDigest;
       }
  @@ -285,7 +285,7 @@
           String authString = credentials.getUserName() + ":" +
               credentials.getPassword();
   
  -        return "Basic " + new String(Base64.encode(authString.getBytes()));
  +        return "Basic " + 
HttpConstants.getString(Base64.encode(HttpConstants.getBytes(authString)));
       }
   
   
  @@ -387,18 +387,14 @@
               throw new HttpException("No credentials available for NTLM "
                   + "authentication.");
           } else {
  -            try {
  -                NTLM ntlm = new NTLM();
  -                String response = "NTLM " + ntlm.getResponseFor(challenge,
  -                        credentials.getUserName(), credentials.getPassword(),
  -                        credentials.getHost(), credentials.getDomain());
  -                if (log.isDebugEnabled()) {
  -                    log.debug("Replying to challenge with: " + response);
  -                }
  -                return new Header(responseHeader, response);
  -            } catch (java.io.UnsupportedEncodingException e) {
  -                throw new HttpException("NTLM requires ASCII support.");
  +            NTLM ntlm = new NTLM();
  +            String response = "NTLM " + ntlm.getResponseFor(challenge,
  +                    credentials.getUserName(), credentials.getPassword(),
  +                    credentials.getHost(), credentials.getDomain());
  +            if (log.isDebugEnabled()) {
  +                log.debug("Replying to challenge with: " + response);
               }
  +            return new Header(responseHeader, response);
           }
       }
   
  @@ -756,7 +752,7 @@
           }
   
           cnonce = Long.toString(System.currentTimeMillis());
  -        cnonce = encode(md5Helper.digest(cnonce.getBytes()));
  +        cnonce = encode(md5Helper.digest(HttpConstants.getBytes(cnonce)));
   
           return cnonce;
       }
  
  
  
  1.8       +4 -5      
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ChunkedInputStream.java
  
  Index: ChunkedInputStream.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ChunkedInputStream.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ChunkedInputStream.java   9 Dec 2002 09:16:16 -0000       1.7
  +++ ChunkedInputStream.java   16 Jan 2003 10:53:08 -0000      1.8
  @@ -89,7 +89,6 @@
       private int chunkSize, pos;
       private boolean eof = false;
       private boolean closed = false;
  -    private static final String HTTP_ENC = "US-ASCII";
       private HttpMethod method;
   
       /**
  @@ -235,7 +234,7 @@
           }
   
           //parse data
  -        String dataString = new String(baos.toByteArray(), HTTP_ENC);
  +        String dataString = HttpConstants.getString(baos.toByteArray());
           int separator = dataString.indexOf(';');
           dataString = (separator > 0)
               ? dataString.substring(0, separator).trim()
  
  
  
  1.3       +3 -3      
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ChunkedOutputStream.java
  
  Index: ChunkedOutputStream.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ChunkedOutputStream.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ChunkedOutputStream.java  16 Dec 2002 15:19:37 -0000      1.2
  +++ ChunkedOutputStream.java  16 Jan 2003 10:53:08 -0000      1.3
  @@ -144,7 +144,7 @@
           if (s == null) {
               s = "null";
           }
  -        write(s.getBytes());
  +        write(HttpConstants.getBytes(s));
       }
   
       /**
  @@ -206,7 +206,7 @@
           if (closed){
               throw new IllegalStateException("Output stream already closed"); 
           }
  -        byte chunkHeader[] = (Integer.toHexString(len) + "\r\n").getBytes();
  +        byte chunkHeader[] = HttpConstants.getBytes(Integer.toHexString(len) + 
"\r\n");
           stream.write(chunkHeader, 0, chunkHeader.length);
           stream.write(b, off, len);
           stream.write(ENDCHUNK, 0, ENDCHUNK.length);
  
  
  
  1.30      +9 -9      
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java
  
  Index: HttpConnection.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- HttpConnection.java       13 Jan 2003 15:51:13 -0000      1.29
  +++ HttpConnection.java       16 Jan 2003 10:53:08 -0000      1.30
  @@ -663,7 +663,7 @@
   
           assertOpen();
           if(wireLog.isDebugEnabled() && (data.length > 0)) {
  -            String data_str =  new String(data);
  +            String data_str =  HttpConstants.getContentString(data);
               wireLog.debug(">> \"" + data_str.trim() + "\" [\\r\\n]" );
           }
           try{
  @@ -702,6 +702,7 @@
           }
       }
   
  +
       /**
        * Write the specified String (as bytes) to my output stream.
        *
  @@ -714,7 +715,7 @@
       public void print(String data)
       throws IOException, IllegalStateException, HttpRecoverableException {
           log.trace("enter HttpConnection.print(String)");
  -        write(data.getBytes());
  +        write(HttpConstants.getBytes(data));
       }
   
       /**
  @@ -730,7 +731,7 @@
       public void printLine(String data)
       throws IOException, IllegalStateException, HttpRecoverableException {
           log.trace("enter HttpConnection.printLine(String)");
  -        writeLine(data.getBytes());
  +        writeLine(HttpConstants.getBytes(data));
       }
   
       /**
  @@ -958,7 +959,7 @@
       /** the protocol being used */
       private Protocol _protocol;
       /** <tt>"\r\n"</tt>, as bytes. */
  -    private static final byte[] CRLF = "\r\n".getBytes();
  +    private static final byte[] CRLF = HttpConstants.getBytes("\r\n");
       /** SO_TIMEOUT value */
       private int _so_timeout = 0;
       /** Whether or not the _socket is a secure one. Note the difference to _ssl */
  @@ -969,5 +970,4 @@
       private int connect_timeout = 0;
       /** the connection manager that created this connection or null */
       private HttpConnectionManager httpConnectionManager;
  -
   }
  
  
  
  1.95      +12 -25    
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java
  
  Index: HttpMethodBase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
  retrieving revision 1.94
  retrieving revision 1.95
  diff -u -r1.94 -r1.95
  --- HttpMethodBase.java       14 Jan 2003 10:16:55 -0000      1.94
  +++ HttpMethodBase.java       16 Jan 2003 10:53:08 -0000      1.95
  @@ -65,7 +65,6 @@
   import java.io.ByteArrayOutputStream;
   import java.io.IOException;
   import java.io.InputStream;
  -import java.io.UnsupportedEncodingException;
   import java.net.MalformedURLException;
   import java.net.URL;
   import java.util.HashMap;
  @@ -159,6 +158,7 @@
    * @author Ortwin Glück
    * @author Eric Johnson
    * @author Michael Becke
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Oleg Kalnichevski</a>
    */
   public abstract class HttpMethodBase implements HttpMethod {
       //~ Static variables/initializers ··········································
  @@ -252,10 +252,6 @@
   
       private boolean doneWithConnection = false;
   
  -    /** Default content encoding chatset */
  -    protected static final String DEFAULT_CHARSET = "ISO-8859-1";
  -
  -
       //~ Constructors ···························································
   
       // ----------------------------------------------------------- Constructors
  @@ -677,22 +673,13 @@
        * @return my response body, if any, as a {@link String}. Otherwise return
        *         <tt>null</tt>.
        */
  -    public String getResponseBodyAsString() {
  -        if (!responseAvailable()) {
  +    public String getResponseBodyAsString()
  +    {
  +        if (!responseAvailable()) 
  +        {
               return null;
           }
  -        String body;
  -        try {
  -            body = new String(getResponseBody(), getResponseCharSet());
  -        }
  -        catch(UnsupportedEncodingException e) {
  -            if (log.isWarnEnabled()) {
  -                log.warn("Unsupported request body charset: " + e.getMessage());
  -            }
  -            body = new String(getResponseBody());
  -        }
  -
  -        return body;
  +        return HttpConstants.getContentString(getResponseBody(), 
getResponseCharSet());
       }
   
   
  @@ -2392,9 +2379,9 @@
           }
           if (charset == null) {
               if (log.isDebugEnabled()) {
  -                log.debug("Default charset used: " + DEFAULT_CHARSET);
  +                log.debug("Default charset used: " + 
HttpConstants.DEFAULT_CONTENT_CHARSET);
               }
  -            charset = DEFAULT_CHARSET;
  +            charset = HttpConstants.DEFAULT_CONTENT_CHARSET;
           }
           return charset;
       }
  
  
  
  1.8       +39 -25    
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/NTLM.java
  
  Index: NTLM.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/NTLM.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- NTLM.java 4 Jan 2003 17:38:51 -0000       1.7
  +++ NTLM.java 16 Jan 2003 10:53:08 -0000      1.8
  @@ -99,6 +99,8 @@
   
       /** Log object for this class. */
       private static final Log log = LogFactory.getLog(NTLM.class);
  +     /** Character encoding */
  +     public static final String DEFAULT_CHARSET = "ASCII";
   
       //Initialize the security provider
       static {
  @@ -132,13 +134,10 @@
        * @param username the username to authenticate with.
        * @param password the password to authenticate with.
        * @param domain the NT domain to authenticate in.
  -     *
  -     * @throws UnsupportedEncodingException if ASCII encoding is not
  -     * supported by the JVM.
        */
       public final String getResponseFor(String message,
               String username, String password, String host, String domain)
  -            throws UnsupportedEncodingException, HttpException {
  +            throws HttpException {
           String response = null;
           if (message == null || message.trim().equals("")) {
               response = getType1Message(host, domain);
  @@ -238,7 +237,7 @@
        * Returns the response that has been generated after shrinking the
        * array if required and base64 encodes the response.
        */
  -    private String getResponse() throws UnsupportedEncodingException {
  +    private String getResponse() {
           byte[] resp;
           if (currResponse.length > pos) {
               byte[] tmp = new byte[pos];
  @@ -249,22 +248,21 @@
           } else {
               resp = currResponse;
           }
  -        return new String(Base64.encode(resp), "ASCII");
  +        return HttpConstants.getString(Base64.encode(resp));
       }
       
  -    private String getType1Message(String host, String domain)
  -    throws UnsupportedEncodingException {
  +    private String getType1Message(String host, String domain) {
           host = host.toUpperCase();
           domain = domain.toUpperCase();
  -        byte[] hostBytes = host.getBytes("ASCII");
  -        byte[] domainBytes = domain.getBytes("ASCII");
  +        byte[] hostBytes = getBytes(host);
  +        byte[] domainBytes = getBytes(domain);
   
           int finalLength = 32 + hostBytes.length + domainBytes.length;
           prepareResponse(finalLength);
           byte[] msg = new byte[finalLength];
           
           // The initial id string.
  -        byte[] protocol = "NTLMSSP".getBytes("ASCII");
  +        byte[] protocol = getBytes("NTLMSSP");
           addBytes(protocol);
           addByte((byte)0);
   
  @@ -329,10 +327,9 @@
        * @return an array of 8 bytes that the server sent to be used when
        * hashing the password.
        */
  -    private byte[] parseType2Message(String sMsg)
  -    throws UnsupportedEncodingException {
  +    private byte[] parseType2Message(String sMsg) {
           // Decode the message first.
  -        byte[] msg = Base64.decode(sMsg.getBytes("ASCII"));
  +        byte[] msg = Base64.decode(getBytes(sMsg));
           byte[] nonce = new byte[8];
           // The nonce is the 8 bytes starting from the byte in position 24.
           for (int i = 0; i < 8; i++) {
  @@ -347,23 +344,23 @@
        */
       private String getType3Message(String user, String password,
               String host, String domain, byte[] nonce)
  -    throws UnsupportedEncodingException, HttpException {
  +    throws HttpException {
   
           int nt_resp_len = 0;
           int lm_resp_len = 24;
           domain = domain.toUpperCase();
           host = host.toUpperCase();
           user = user.toUpperCase();
  -        byte[] domainBytes = domain.getBytes("ASCII");
  -        byte[] hostBytes = host.getBytes("ASCII");
  -        byte[] userBytes = user.getBytes("ASCII");
  +        byte[] domainBytes = getBytes(domain);
  +        byte[] hostBytes = getBytes(host);
  +        byte[] userBytes = getBytes(user);
           int domainLen = domainBytes.length;
           int hostLen = hostBytes.length;
           int userLen = userBytes.length;
           int finalLength = 64 + nt_resp_len + lm_resp_len + domainLen +
               userLen + hostLen;
           prepareResponse(finalLength);
  -        byte[] ntlmssp = "NTLMSSP".getBytes("ASCII");
  +        byte[] ntlmssp = getBytes("NTLMSSP");
           addBytes(ntlmssp);
           addByte((byte)0);
           addByte((byte)3);
  @@ -443,8 +440,8 @@
        * @param nonce the nonce sent by the server.
        */
       private byte[] hashPassword(String password, byte[] nonce)
  -        throws UnsupportedEncodingException, HttpException {
  -        byte[] passw = password.toUpperCase().getBytes("ASCII");
  +        throws HttpException {
  +        byte[] passw = getBytes(password.toUpperCase());
           byte[] lm_pw1 = new byte[7];
           byte[] lm_pw2 = new byte[7];
   
  @@ -553,5 +550,22 @@
           val[0] = (byte)Integer.parseInt(low, 16);
           val[1] = (byte)Integer.parseInt(high, 16);
           return val;
  +    }
  +    
  +    
  +    private static byte[] getBytes(final String s)
  +    {
  +             if (s == null)
  +             {
  +                     throw new IllegalArgumentException("Parameter may not be 
null");
  +             }
  +     try
  +     {
  +             return s.getBytes(DEFAULT_CHARSET);
  +     }
  +     catch(UnsupportedEncodingException unexpected_eexception) 
  +     {
  +             throw new RuntimeException("NTLM requires ASCII support"); 
  +     }
       }
   }
  
  
  
  1.15      +5 -5      
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/RequestOutputStream.java
  
  Index: RequestOutputStream.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/RequestOutputStream.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- RequestOutputStream.java  5 Aug 2002 14:46:05 -0000       1.14
  +++ RequestOutputStream.java  16 Jan 2003 10:53:08 -0000      1.15
  @@ -250,7 +250,7 @@
           log.trace("enter RequestOutputStream.write(byte[], int, int)");
   
           if (useChunking) {
  -            byte chunkHeader[] = (Integer.toHexString(len) + "\r\n").getBytes();
  +            byte chunkHeader[] = HttpConstants.getBytes(Integer.toHexString(len) + 
"\r\n");
               stream.write(chunkHeader, 0, chunkHeader.length);
               stream.write(b, off, len);
               stream.write(ENDCHUNK, 0, ENDCHUNK.length);
  
  
  
  1.4       +4 -4      
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/WireLogInputStream.java
  
  Index: WireLogInputStream.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/WireLogInputStream.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- WireLogInputStream.java   19 Sep 2002 11:45:26 -0000      1.3
  +++ WireLogInputStream.java   16 Jan 2003 10:53:08 -0000      1.4
  @@ -95,7 +95,7 @@
   
       public int read(byte[] b) throws java.io.IOException {
           int l = super.read(b);
  -        wireLog.debug("<< "+ new String(b));
  +        wireLog.debug("<< "+ HttpConstants.getString(b));
           return l;
       }
   }
  
  
  
  1.1                  
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConstants.java
  
  Index: HttpConstants.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConstants.java,v
 1.1 2003/01/16 10:53:08 oglueck Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/16 10:53:08 $
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "HttpClient", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  package org.apache.commons.httpclient;
  
  
  import java.io.UnsupportedEncodingException;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  
  /**
   * DOCUMENT ME!
   *
   * @author Oleg Kalnichevski
   */
  public class HttpConstants {
  
      /** Character set used to encode HTTP protocol elements */
      public static final String HTTP_ELEMENT_CHARSET = "US-ASCII";
  
      /** Default content encoding chatset */
      protected static final String DEFAULT_CONTENT_CHARSET = "ISO-8859-1";
  
      /** Log object for this class. */
      private static final Log log = LogFactory.getLog(HttpConstants.class);
  
      /**
       * Converts the specified string to a byte array of HTTP element characters.
       * This method is to be used when encoding content of HTTP elements (such as 
request headers)
       *
       * @param data the string to be encoded
       */
      public static byte[] getBytes(final String data) {
  
          if (data == null) {
              throw new IllegalArgumentException("Parameter may not be null");
          }
  
          try {
              return data.getBytes(HTTP_ELEMENT_CHARSET);
          } catch (UnsupportedEncodingException e) {
  
              if (log.isWarnEnabled()) {
                  log.warn("Unsupported encoding: " + HTTP_ELEMENT_CHARSET + ". System 
default encoding used");
              }
  
              return data.getBytes();
          }
      }
  
      /**
       * Converts the byte array of HTTP element characters to a string
       * This method is to be used when decoding content of HTTP elements (such as 
response headers)
       *
       * @param data the byte array to be encoded
       */
      public static String getString(final byte[] data) {
  
          if (data == null) {
              throw new IllegalArgumentException("Parameter may not be null");
          }
  
          try {
              return new String(data, HTTP_ELEMENT_CHARSET);
          } catch (UnsupportedEncodingException e) {
  
              if (log.isWarnEnabled()) {
                  log.warn("Unsupported encoding: " + HTTP_ELEMENT_CHARSET + ". System 
default encoding used");
              }
  
              return new String(data);
          }
      }
  
      /**
       * Converts the specified string to a byte array of HTTP content charachetrs
       * This method is to be used when encoding content of HTTP request/response
       * If the specified charset is not supported, default HTTP content encoding
       * (ISO-8859-1) is applied
       *
       * @param data the string to be encoded
       * @param charset the desired character encoding
       */
      public static byte[] getContentBytes(final String data, String charset) {
  
          if (data == null) {
              throw new IllegalArgumentException("Parameter may not be null");
          }
  
          if ((charset == null) || (charset.equals(""))) {
              charset = DEFAULT_CONTENT_CHARSET;
          }
  
          try {
              return data.getBytes(charset);
          } catch (UnsupportedEncodingException e) {
  
              if (log.isWarnEnabled()) {
                  log.warn("Unsupported encoding: " + charset + ". HTTP default 
encoding used");
              }
  
              try {
                  return data.getBytes(DEFAULT_CONTENT_CHARSET);
              } catch (UnsupportedEncodingException e2) {
  
                  if (log.isWarnEnabled()) {
                      log.warn("Unsupported encoding: " + DEFAULT_CONTENT_CHARSET + ". 
System encoding used");
                  }
  
                  return data.getBytes();
              }
          }
      }
  
      /**
       * Converts the byte array of HTTP content characters to a string
       * This method is to be used when decoding content of HTTP request/response
       * If the specified charset is not supported, default HTTP content encoding
       * (ISO-8859-1) is applied
       *
       * @param data the byte array to be encoded
       * @param charset the desired character encoding
       */
      public static String getContentString(final byte[] data, String charset) {
  
          if (data == null) {
              throw new IllegalArgumentException("Parameter may not be null");
          }
  
          if ((charset == null) || (charset.equals(""))) {
              charset = DEFAULT_CONTENT_CHARSET;
          }
  
          try {
              return new String(data, charset);
          } catch (UnsupportedEncodingException e) {
  
              if (log.isWarnEnabled()) {
                  log.warn("Unsupported encoding: " + DEFAULT_CONTENT_CHARSET + ". 
Default HTTP encoding used");
              }
  
              try {
                  return new String(data, DEFAULT_CONTENT_CHARSET);
              } catch (UnsupportedEncodingException e2) {
  
                  if (log.isWarnEnabled()) {
                      log.warn("Unsupported encoding: " + DEFAULT_CONTENT_CHARSET + ". 
System encoding used");
                  }
  
                  return new String(data);
              }
          }
      }
  
      /**
       * Converts the specified string to a byte array of HTTP content charachetrs
       * using default HTTP content encoding (ISO-8859-1)
       * This method is to be used when encoding content of HTTP request/response
       *
       * @param data the string to be encoded
       */
      public static byte[] getContentBytes(final String data) {
          return getContentBytes(data, null);
      }
  
      /**
       * Converts the byte array of HTTP content characters to a string using default
       * HTTP content encoding (ISO-8859-1)
       * This method is to be used when decoding content of HTTP request/response
       *
       * @param data the byte array to be encoded
       */
      public static String getContentString(final byte[] data) {
          return getContentString(data, null);
      }
  
      /**
       * Converts the specified string to byte array of ASCII characters.
       *
       * @param data the string to be encoded
       */
      public static byte[] getAsciiBytes(final String data) {
  
          if (data == null) {
              throw new IllegalArgumentException("Parameter may not be null");
          }
  
          try {
              return data.getBytes("US-ASCII");
          } catch (UnsupportedEncodingException e) {
              throw new RuntimeException(e);
          }
      }
  
      /**
       * Converts the byte array of ASCII characters to a string
       * This method is to be used when decoding content of HTTP elements (such as 
response headers)
       *
       * @param data the byte array to be encoded
       */
      public static String getAsciiString(final byte[] data) {
  
          if (data == null) {
              throw new IllegalArgumentException("Parameter may not be null");
          }
  
          try {
              return new String(data, HTTP_ELEMENT_CHARSET);
          } catch (UnsupportedEncodingException e) {
              throw new RuntimeException(e);
          }
      }
  }
  
  
  1.32      +29 -19    
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PostMethod.java
  
  Index: PostMethod.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PostMethod.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- PostMethod.java   19 Dec 2002 10:23:37 -0000      1.31
  +++ PostMethod.java   16 Jan 2003 10:53:08 -0000      1.32
  @@ -64,13 +64,13 @@
   import java.io.ByteArrayInputStream;
   import java.io.ByteArrayOutputStream;
   import java.io.IOException;
  -import java.io.UnsupportedEncodingException;
   import java.io.InputStream;
   import java.io.OutputStream;
   import java.util.Iterator;
   import java.util.List;
   import java.util.Vector;
   
  +import org.apache.commons.httpclient.HttpConstants;
   import org.apache.commons.httpclient.Header;
   import org.apache.commons.httpclient.HttpConnection;
   import org.apache.commons.httpclient.HttpException;
  @@ -351,16 +351,8 @@
               return;
           }
   
  -        byte[] tmp = null;
  -        try {
  -            tmp = body.getBytes(getRequestCharSet());
  -        } catch(UnsupportedEncodingException e) {
  -            if (log.isWarnEnabled()) {
  -                log.warn("Unsupported request body charset: " + e.getMessage());
  -            }
  -            tmp = body.getBytes();
  -        }
  -        this.requestBody = new ByteArrayInputStream(tmp);
  +        this.requestBody = new ByteArrayInputStream(
  +          HttpConstants.getContentBytes(body, getRequestCharSet()));
       }
   
       /**
  @@ -385,7 +377,7 @@
                   "Request parameters have already been added.");
           }
   
  -        requestBody = body;
  +        this.requestBody = body;
       }
   
       /**
  @@ -765,7 +757,6 @@
           return true;
       }
   
  -    // ------------------------------------------------------------Class Methods
   
       /**
        * Encode the list of parameters into a query stream.
  @@ -776,8 +767,28 @@
        *
        * @since 1.0
        */
  -    static InputStream generateRequestBody(List params) {
  +    protected InputStream generateRequestBody(List params) {
           log.trace("enter PostMethod.generateRequestBody(List)");
  +             String body = generateRequestBodyAsString(params);
  +
  +        return new ByteArrayInputStream(
  +          HttpConstants.getContentBytes(body, getRequestCharSet()));
  +    }
  +
  +
  +    // ------------------------------------------------------------Class Methods
  +
  +    /**
  +     * Encode the list of parameters into a query string.
  +     *
  +     * @param params the list of query name and value
  +     *
  +     * @return the query string
  +     *
  +     * @since 2.0
  +     */
  +    protected static String generateRequestBodyAsString(List params) {
  +        log.trace("enter PostMethod.generateRequestBodyAsString(List)");
   
           Iterator it = params.iterator();
           StringBuffer buff = new StringBuffer();
  @@ -805,8 +816,7 @@
                   buff.append("&");
               }
           }
  -
  -        return new ByteArrayInputStream(buff.toString().getBytes());
  +        return buff.toString();
       }
   
       /**
  
  
  
  1.18      +5 -4      
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PutMethod.java
  
  Index: PutMethod.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PutMethod.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- PutMethod.java    19 Dec 2002 10:23:38 -0000      1.17
  +++ PutMethod.java    16 Jan 2003 10:53:08 -0000      1.18
  @@ -62,6 +62,7 @@
   
   package org.apache.commons.httpclient.methods;
   
  +import org.apache.commons.httpclient.HttpConstants;
   import org.apache.commons.httpclient.HttpConnection;
   import org.apache.commons.httpclient.HttpException;
   import org.apache.commons.httpclient.HttpMethodBase;
  @@ -186,7 +187,7 @@
        */
       public void setRequestBody(String bodydata) {
           checkNotUsed();
  -        setRequestBody(bodydata.getBytes());
  +        setRequestBody(HttpConstants.getContentBytes(bodydata, 
getRequestCharSet()));
       }
   
       /**
  
  
  
  1.7       +7 -9      
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/multipart/FilePart.java
  
  Index: FilePart.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/multipart/FilePart.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- FilePart.java     17 Nov 2002 03:11:27 -0000      1.6
  +++ FilePart.java     16 Jan 2003 10:53:09 -0000      1.7
  @@ -67,9 +67,7 @@
   import java.io.IOException;
   import java.io.InputStream;
   import java.io.OutputStream;
  -import java.security.InvalidParameterException;
  -import org.apache.commons.logging.Log;
  -import org.apache.commons.logging.LogFactory;
  +import org.apache.commons.httpclient.HttpConstants;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  @@ -138,7 +136,7 @@
       ) {
   
           if ( partSource.getLength() < 0 ) {
  -            throw new InvalidParameterException( "fileLength must be >= 0." );   
  +            throw new IllegalArgumentException( "fileLength must be >= 0." );   
           }
   
           this.name = name;
  @@ -158,7 +156,7 @@
       throws IOException {
           log.trace("enter sendFilename(OutputStream out)");
           String filename = "; filename=\"" + source.getFileName() + "\"";
  -        out.write(filename.getBytes());
  +        out.write(HttpConstants.getBytes(filename));
       }
   
       
  @@ -166,7 +164,7 @@
       throws IOException {
           log.trace("enter sendContentType(OutputStream out)");
           out.write(CRLF_bytes);
  -        out.write("Content-Type: application/octet-stream".getBytes());
  +        out.write(HttpConstants.getBytes("Content-Type: application/octet-stream"));
       }    
   
       public String getName() { 
  
  
  
  1.4       +8 -7      
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/multipart/Part.java
  
  Index: Part.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/multipart/Part.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Part.java 5 Nov 2002 17:50:22 -0000       1.3
  +++ Part.java 16 Jan 2003 10:53:09 -0000      1.4
  @@ -65,6 +65,7 @@
   import java.io.OutputStream;
   import java.io.ByteArrayOutputStream;
   import java.io.IOException;
  +import org.apache.commons.httpclient.HttpConstants;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  @@ -83,11 +84,11 @@
       private static final Log log = LogFactory.getLog(Part.class);
   
       static String boundary = "----------------314159265358979323846";
  -    static byte[] boundary_bytes = boundary.getBytes();
  +    static byte[] boundary_bytes = HttpConstants.getBytes(boundary);
       static String CRLF = "\r\n";
  -    static byte[] CRLF_bytes = CRLF.getBytes();
  +    static byte[] CRLF_bytes = HttpConstants.getBytes(CRLF);
       static String extra = "--";
  -    static byte[] extra_bytes = extra.getBytes();
  +    static byte[] extra_bytes = HttpConstants.getBytes(extra);
       
       public static String getBoundary() {
           return boundary;
  @@ -136,7 +137,7 @@
           String content_dispos = "Content-Disposition: form-data; name=\"" 
               + getName() + "\"";
       
  -        out.write(content_dispos.getBytes());
  +        out.write(HttpConstants.getBytes(content_dispos));
       }
       
       protected int lengthOfHeader()
  
  
  
  1.2       +6 -5      
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/multipart/StringPart.java
  
  Index: StringPart.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/multipart/StringPart.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StringPart.java   1 Oct 2002 19:13:41 -0000       1.1
  +++ StringPart.java   16 Jan 2003 10:53:09 -0000      1.2
  @@ -64,6 +64,7 @@
   
   import java.io.OutputStream;
   import java.io.IOException;
  +import org.apache.commons.httpclient.HttpConstants;
   
   /**
    * Simple string parameter for a multipart post
  @@ -93,11 +94,11 @@
       
       protected void sendData(OutputStream out) 
       throws IOException {
  -        out.write(value.getBytes());    
  +        out.write(HttpConstants.getBytes(value));    
       }
       
       protected long lengthOfData() 
       throws IOException {
  -        return value.getBytes().length;
  +        return HttpConstants.getBytes(value).length;
       }
   }
  
  
  
  1.2       +7 -5      
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/util/Base64.java
  
  Index: Base64.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/util/Base64.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Base64.java       3 Dec 2002 15:20:32 -0000       1.1
  +++ Base64.java       16 Jan 2003 10:53:09 -0000      1.2
  @@ -62,6 +62,8 @@
   
   package org.apache.commons.httpclient.util;
   
  +import org.apache.commons.httpclient.HttpConstants;
  +
   /**
    * <p>Base64 encoder and decoder.</p>
    * <p>
  @@ -133,7 +135,7 @@
        }
        
       public static boolean isBase64(String isValidString) {
  -        return isArrayByteBase64(isValidString.getBytes());
  +        return isArrayByteBase64(HttpConstants.getAsciiBytes(isValidString));
       }
   
   
  
  
  
  1.13      +5 -4      
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/util/URIUtil.java
  
  Index: URIUtil.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/util/URIUtil.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- URIUtil.java      18 Dec 2002 02:49:47 -0000      1.12
  +++ URIUtil.java      16 Jan 2003 10:53:09 -0000      1.13
  @@ -599,6 +599,7 @@
        * @return the document character encoded string
        * @exception URIException
        */
  +
       public static String toUsingCharset(String target, String fromCharset,
               String toCharset) throws URIException {
   
  
  
  
  1.5       +4 -4      
jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/SimpleHttpConnection.java
  
  Index: SimpleHttpConnection.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/SimpleHttpConnection.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SimpleHttpConnection.java 31 Oct 2002 07:45:35 -0000      1.4
  +++ SimpleHttpConnection.java 16 Jan 2003 10:53:09 -0000      1.5
  @@ -136,7 +136,7 @@
               headerReader = new BufferedReader(
                       new StringReader((String)headers.elementAt(hits)));
               bodyInputStream = new ByteArrayInputStream(
  -                    ((String)bodies.elementAt(hits)).getBytes());
  +              HttpConstants.getContentBytes((String)bodies.elementAt(hits)));
               bodyOutputStream = new ByteArrayOutputStream();
               hits++;
           } catch (ArrayIndexOutOfBoundsException aiofbe) {
  
  
  
  1.20      +10 -10    
jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestAuthenticator.java
  
  Index: TestAuthenticator.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestAuthenticator.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- TestAuthenticator.java    17 Dec 2002 02:26:57 -0000      1.19
  +++ TestAuthenticator.java    16 Jan 2003 10:53:09 -0000      1.20
  @@ -190,7 +190,7 @@
           HttpMethod method = new SimpleHttpMethod(new 
Header("WwW-AuThEnTiCaTe","bAsIc ReAlM=\"realm1\""));
           assertTrue(Authenticator.authenticate(method,state));
           assertTrue(null != method.getRequestHeader("Authorization"));
  -        String expected = "Basic " + new 
String(Base64.encode("username:password".getBytes()));
  +        String expected = "Basic " + 
HttpConstants.getString(Base64.encode(HttpConstants.getBytes("username:password")));
           assertEquals(expected,method.getRequestHeader("Authorization").getValue());
       }
   
  @@ -201,7 +201,7 @@
           HttpMethod method = new SimpleHttpMethod(new 
Header("WWW-Authenticate","Basic realm=\"realm1\""));
           assertTrue(Authenticator.authenticate(method,state));
           assertTrue(null != method.getRequestHeader("Authorization"));
  -        String expected = "Basic " + new 
String(Base64.encode("username:password".getBytes()));
  +        String expected = "Basic " + 
HttpConstants.getString(Base64.encode(HttpConstants.getBytes("username:password")));
           assertEquals(expected,method.getRequestHeader("Authorization").getValue());
       }
   
  @@ -211,7 +211,7 @@
           HttpMethod method = new SimpleHttpMethod(new 
Header("WWW-Authenticate","Basic realm=\"realm\""));
           assertTrue(Authenticator.authenticate(method,state));
           assertTrue(null != method.getRequestHeader("Authorization"));
  -        String expected = "Basic " + new 
String(Base64.encode("username:password".getBytes()));
  +        String expected = "Basic " + 
HttpConstants.getString(Base64.encode(HttpConstants.getBytes("username:password")));
           assertEquals(expected,method.getRequestHeader("Authorization").getValue());
       }
   
  @@ -224,14 +224,14 @@
               HttpMethod method = new SimpleHttpMethod(new 
Header("WWW-Authenticate","Basic realm=\"realm1\""));
               assertTrue(Authenticator.authenticate(method,state));
               assertTrue(null != method.getRequestHeader("Authorization"));
  -            String expected = "Basic " + new 
String(Base64.encode("username:password".getBytes()));
  +            String expected = "Basic " + 
HttpConstants.getString(Base64.encode(HttpConstants.getBytes("username:password")));
               
assertEquals(expected,method.getRequestHeader("Authorization").getValue());
           }
           {
               HttpMethod method = new SimpleHttpMethod(new 
Header("WWW-Authenticate","Basic realm=\"realm2\""));
               assertTrue(Authenticator.authenticate(method,state));
               assertTrue(null != method.getRequestHeader("Authorization"));
  -            String expected = "Basic " + new 
String(Base64.encode("uname2:password2".getBytes()));
  +            String expected = "Basic " + 
HttpConstants.getString(Base64.encode(HttpConstants.getBytes("uname2:password2")));
               
assertEquals(expected,method.getRequestHeader("Authorization").getValue());
           }
       }
  @@ -262,7 +262,7 @@
           System.getProperties().setProperty(Authenticator.PREEMPTIVE_PROPERTY, 
"true");
           assertTrue(Authenticator.authenticate(method,state));
           assertTrue(null != method.getRequestHeader("Authorization"));
  -        String expected = "Basic " + new 
String(Base64.encode("username:password".getBytes()));
  +        String expected = "Basic " + 
HttpConstants.getString(Base64.encode(HttpConstants.getBytes("username:password")));
           assertEquals(expected, method.getRequestHeader("Authorization").getValue());
       }
   
  
  
  
  1.6       +187 -187  
jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestBase64.java
  
  Index: TestBase64.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestBase64.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TestBase64.java   17 Dec 2002 02:26:57 -0000      1.5
  +++ TestBase64.java   16 Jan 2003 10:53:09 -0000      1.6
  @@ -101,7 +101,7 @@
               byte[] data = new byte[i];
               _rand.nextBytes(data);
               byte[] enc =  Base64.encode(data);
  -            assertTrue("\"" + (new String(enc)) + "\" is Base64 
data.",Base64.isBase64((new String(enc))));
  +            assertTrue("\"" + (HttpConstants.getAsciiString(enc)) + "\" is Base64 
data.",Base64.isBase64((HttpConstants.getAsciiString(enc))));
               byte[] data2 = Base64.decode(enc);
               assertTrue(toString(data) + " equals " + 
toString(data2),isEqual(data,data2));
           }
  @@ -113,203 +113,203 @@
               byte[] data = new byte[_rand.nextInt(10000)+1];
               _rand.nextBytes(data);
               byte[] enc =  Base64.encode(data);
  -            assertTrue(Base64.isBase64(new String(enc)));
  +            assertTrue(Base64.isBase64(HttpConstants.getAsciiString(enc)));
               byte[] data2 = Base64.decode(enc);
               assertTrue(isEqual(data,data2));
           }
       }
   
       public void testSingletons() {
  -        assertEquals("AA==",new String(Base64.encode(new byte[] { (byte)0 })));
  -        assertEquals("AQ==",new String(Base64.encode(new byte[] { (byte)1 })));
  -        assertEquals("Ag==",new String(Base64.encode(new byte[] { (byte)2 })));
  -        assertEquals("Aw==",new String(Base64.encode(new byte[] { (byte)3 })));
  -        assertEquals("BA==",new String(Base64.encode(new byte[] { (byte)4 })));
  -        assertEquals("BQ==",new String(Base64.encode(new byte[] { (byte)5 })));
  -        assertEquals("Bg==",new String(Base64.encode(new byte[] { (byte)6 })));
  -        assertEquals("Bw==",new String(Base64.encode(new byte[] { (byte)7 })));
  -        assertEquals("CA==",new String(Base64.encode(new byte[] { (byte)8 })));
  -        assertEquals("CQ==",new String(Base64.encode(new byte[] { (byte)9 })));
  -        assertEquals("Cg==",new String(Base64.encode(new byte[] { (byte)10 })));
  -        assertEquals("Cw==",new String(Base64.encode(new byte[] { (byte)11 })));
  -        assertEquals("DA==",new String(Base64.encode(new byte[] { (byte)12 })));
  -        assertEquals("DQ==",new String(Base64.encode(new byte[] { (byte)13 })));
  -        assertEquals("Dg==",new String(Base64.encode(new byte[] { (byte)14 })));
  -        assertEquals("Dw==",new String(Base64.encode(new byte[] { (byte)15 })));
  -        assertEquals("EA==",new String(Base64.encode(new byte[] { (byte)16 })));
  -        assertEquals("EQ==",new String(Base64.encode(new byte[] { (byte)17 })));
  -        assertEquals("Eg==",new String(Base64.encode(new byte[] { (byte)18 })));
  -        assertEquals("Ew==",new String(Base64.encode(new byte[] { (byte)19 })));
  -        assertEquals("FA==",new String(Base64.encode(new byte[] { (byte)20 })));
  -        assertEquals("FQ==",new String(Base64.encode(new byte[] { (byte)21 })));
  -        assertEquals("Fg==",new String(Base64.encode(new byte[] { (byte)22 })));
  -        assertEquals("Fw==",new String(Base64.encode(new byte[] { (byte)23 })));
  -        assertEquals("GA==",new String(Base64.encode(new byte[] { (byte)24 })));
  -        assertEquals("GQ==",new String(Base64.encode(new byte[] { (byte)25 })));
  -        assertEquals("Gg==",new String(Base64.encode(new byte[] { (byte)26 })));
  -        assertEquals("Gw==",new String(Base64.encode(new byte[] { (byte)27 })));
  -        assertEquals("HA==",new String(Base64.encode(new byte[] { (byte)28 })));
  -        assertEquals("HQ==",new String(Base64.encode(new byte[] { (byte)29 })));
  -        assertEquals("Hg==",new String(Base64.encode(new byte[] { (byte)30 })));
  -        assertEquals("Hw==",new String(Base64.encode(new byte[] { (byte)31 })));
  -        assertEquals("IA==",new String(Base64.encode(new byte[] { (byte)32 })));
  -        assertEquals("IQ==",new String(Base64.encode(new byte[] { (byte)33 })));
  -        assertEquals("Ig==",new String(Base64.encode(new byte[] { (byte)34 })));
  -        assertEquals("Iw==",new String(Base64.encode(new byte[] { (byte)35 })));
  -        assertEquals("JA==",new String(Base64.encode(new byte[] { (byte)36 })));
  -        assertEquals("JQ==",new String(Base64.encode(new byte[] { (byte)37 })));
  -        assertEquals("Jg==",new String(Base64.encode(new byte[] { (byte)38 })));
  -        assertEquals("Jw==",new String(Base64.encode(new byte[] { (byte)39 })));
  -        assertEquals("KA==",new String(Base64.encode(new byte[] { (byte)40 })));
  -        assertEquals("KQ==",new String(Base64.encode(new byte[] { (byte)41 })));
  -        assertEquals("Kg==",new String(Base64.encode(new byte[] { (byte)42 })));
  -        assertEquals("Kw==",new String(Base64.encode(new byte[] { (byte)43 })));
  -        assertEquals("LA==",new String(Base64.encode(new byte[] { (byte)44 })));
  -        assertEquals("LQ==",new String(Base64.encode(new byte[] { (byte)45 })));
  -        assertEquals("Lg==",new String(Base64.encode(new byte[] { (byte)46 })));
  -        assertEquals("Lw==",new String(Base64.encode(new byte[] { (byte)47 })));
  -        assertEquals("MA==",new String(Base64.encode(new byte[] { (byte)48 })));
  -        assertEquals("MQ==",new String(Base64.encode(new byte[] { (byte)49 })));
  -        assertEquals("Mg==",new String(Base64.encode(new byte[] { (byte)50 })));
  -        assertEquals("Mw==",new String(Base64.encode(new byte[] { (byte)51 })));
  -        assertEquals("NA==",new String(Base64.encode(new byte[] { (byte)52 })));
  -        assertEquals("NQ==",new String(Base64.encode(new byte[] { (byte)53 })));
  -        assertEquals("Ng==",new String(Base64.encode(new byte[] { (byte)54 })));
  -        assertEquals("Nw==",new String(Base64.encode(new byte[] { (byte)55 })));
  -        assertEquals("OA==",new String(Base64.encode(new byte[] { (byte)56 })));
  -        assertEquals("OQ==",new String(Base64.encode(new byte[] { (byte)57 })));
  -        assertEquals("Og==",new String(Base64.encode(new byte[] { (byte)58 })));
  -        assertEquals("Ow==",new String(Base64.encode(new byte[] { (byte)59 })));
  -        assertEquals("PA==",new String(Base64.encode(new byte[] { (byte)60 })));
  -        assertEquals("PQ==",new String(Base64.encode(new byte[] { (byte)61 })));
  -        assertEquals("Pg==",new String(Base64.encode(new byte[] { (byte)62 })));
  -        assertEquals("Pw==",new String(Base64.encode(new byte[] { (byte)63 })));
  -        assertEquals("QA==",new String(Base64.encode(new byte[] { (byte)64 })));
  -        assertEquals("QQ==",new String(Base64.encode(new byte[] { (byte)65 })));
  -        assertEquals("Qg==",new String(Base64.encode(new byte[] { (byte)66 })));
  -        assertEquals("Qw==",new String(Base64.encode(new byte[] { (byte)67 })));
  -        assertEquals("RA==",new String(Base64.encode(new byte[] { (byte)68 })));
  -        assertEquals("RQ==",new String(Base64.encode(new byte[] { (byte)69 })));
  -        assertEquals("Rg==",new String(Base64.encode(new byte[] { (byte)70 })));
  -        assertEquals("Rw==",new String(Base64.encode(new byte[] { (byte)71 })));
  -        assertEquals("SA==",new String(Base64.encode(new byte[] { (byte)72 })));
  -        assertEquals("SQ==",new String(Base64.encode(new byte[] { (byte)73 })));
  -        assertEquals("Sg==",new String(Base64.encode(new byte[] { (byte)74 })));
  -        assertEquals("Sw==",new String(Base64.encode(new byte[] { (byte)75 })));
  -        assertEquals("TA==",new String(Base64.encode(new byte[] { (byte)76 })));
  -        assertEquals("TQ==",new String(Base64.encode(new byte[] { (byte)77 })));
  -        assertEquals("Tg==",new String(Base64.encode(new byte[] { (byte)78 })));
  -        assertEquals("Tw==",new String(Base64.encode(new byte[] { (byte)79 })));
  -        assertEquals("UA==",new String(Base64.encode(new byte[] { (byte)80 })));
  -        assertEquals("UQ==",new String(Base64.encode(new byte[] { (byte)81 })));
  -        assertEquals("Ug==",new String(Base64.encode(new byte[] { (byte)82 })));
  -        assertEquals("Uw==",new String(Base64.encode(new byte[] { (byte)83 })));
  -        assertEquals("VA==",new String(Base64.encode(new byte[] { (byte)84 })));
  -        assertEquals("VQ==",new String(Base64.encode(new byte[] { (byte)85 })));
  -        assertEquals("Vg==",new String(Base64.encode(new byte[] { (byte)86 })));
  -        assertEquals("Vw==",new String(Base64.encode(new byte[] { (byte)87 })));
  -        assertEquals("WA==",new String(Base64.encode(new byte[] { (byte)88 })));
  -        assertEquals("WQ==",new String(Base64.encode(new byte[] { (byte)89 })));
  -        assertEquals("Wg==",new String(Base64.encode(new byte[] { (byte)90 })));
  -        assertEquals("Ww==",new String(Base64.encode(new byte[] { (byte)91 })));
  -        assertEquals("XA==",new String(Base64.encode(new byte[] { (byte)92 })));
  -        assertEquals("XQ==",new String(Base64.encode(new byte[] { (byte)93 })));
  -        assertEquals("Xg==",new String(Base64.encode(new byte[] { (byte)94 })));
  -        assertEquals("Xw==",new String(Base64.encode(new byte[] { (byte)95 })));
  -        assertEquals("YA==",new String(Base64.encode(new byte[] { (byte)96 })));
  -        assertEquals("YQ==",new String(Base64.encode(new byte[] { (byte)97 })));
  -        assertEquals("Yg==",new String(Base64.encode(new byte[] { (byte)98 })));
  -        assertEquals("Yw==",new String(Base64.encode(new byte[] { (byte)99 })));
  -        assertEquals("ZA==",new String(Base64.encode(new byte[] { (byte)100 })));
  -        assertEquals("ZQ==",new String(Base64.encode(new byte[] { (byte)101 })));
  -        assertEquals("Zg==",new String(Base64.encode(new byte[] { (byte)102 })));
  -        assertEquals("Zw==",new String(Base64.encode(new byte[] { (byte)103 })));
  -        assertEquals("aA==",new String(Base64.encode(new byte[] { (byte)104 })));
  +        assertEquals("AA==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0 })));
  +        assertEquals("AQ==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)1 })));
  +        assertEquals("Ag==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)2 })));
  +        assertEquals("Aw==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)3 })));
  +        assertEquals("BA==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)4 })));
  +        assertEquals("BQ==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)5 })));
  +        assertEquals("Bg==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)6 })));
  +        assertEquals("Bw==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)7 })));
  +        assertEquals("CA==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)8 })));
  +        assertEquals("CQ==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)9 })));
  +        assertEquals("Cg==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)10 })));
  +        assertEquals("Cw==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)11 })));
  +        assertEquals("DA==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)12 })));
  +        assertEquals("DQ==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)13 })));
  +        assertEquals("Dg==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)14 })));
  +        assertEquals("Dw==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)15 })));
  +        assertEquals("EA==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)16 })));
  +        assertEquals("EQ==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)17 })));
  +        assertEquals("Eg==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)18 })));
  +        assertEquals("Ew==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)19 })));
  +        assertEquals("FA==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)20 })));
  +        assertEquals("FQ==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)21 })));
  +        assertEquals("Fg==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)22 })));
  +        assertEquals("Fw==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)23 })));
  +        assertEquals("GA==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)24 })));
  +        assertEquals("GQ==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)25 })));
  +        assertEquals("Gg==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)26 })));
  +        assertEquals("Gw==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)27 })));
  +        assertEquals("HA==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)28 })));
  +        assertEquals("HQ==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)29 })));
  +        assertEquals("Hg==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)30 })));
  +        assertEquals("Hw==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)31 })));
  +        assertEquals("IA==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)32 })));
  +        assertEquals("IQ==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)33 })));
  +        assertEquals("Ig==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)34 })));
  +        assertEquals("Iw==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)35 })));
  +        assertEquals("JA==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)36 })));
  +        assertEquals("JQ==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)37 })));
  +        assertEquals("Jg==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)38 })));
  +        assertEquals("Jw==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)39 })));
  +        assertEquals("KA==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)40 })));
  +        assertEquals("KQ==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)41 })));
  +        assertEquals("Kg==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)42 })));
  +        assertEquals("Kw==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)43 })));
  +        assertEquals("LA==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)44 })));
  +        assertEquals("LQ==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)45 })));
  +        assertEquals("Lg==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)46 })));
  +        assertEquals("Lw==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)47 })));
  +        assertEquals("MA==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)48 })));
  +        assertEquals("MQ==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)49 })));
  +        assertEquals("Mg==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)50 })));
  +        assertEquals("Mw==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)51 })));
  +        assertEquals("NA==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)52 })));
  +        assertEquals("NQ==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)53 })));
  +        assertEquals("Ng==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)54 })));
  +        assertEquals("Nw==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)55 })));
  +        assertEquals("OA==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)56 })));
  +        assertEquals("OQ==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)57 })));
  +        assertEquals("Og==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)58 })));
  +        assertEquals("Ow==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)59 })));
  +        assertEquals("PA==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)60 })));
  +        assertEquals("PQ==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)61 })));
  +        assertEquals("Pg==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)62 })));
  +        assertEquals("Pw==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)63 })));
  +        assertEquals("QA==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)64 })));
  +        assertEquals("QQ==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)65 })));
  +        assertEquals("Qg==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)66 })));
  +        assertEquals("Qw==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)67 })));
  +        assertEquals("RA==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)68 })));
  +        assertEquals("RQ==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)69 })));
  +        assertEquals("Rg==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)70 })));
  +        assertEquals("Rw==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)71 })));
  +        assertEquals("SA==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)72 })));
  +        assertEquals("SQ==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)73 })));
  +        assertEquals("Sg==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)74 })));
  +        assertEquals("Sw==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)75 })));
  +        assertEquals("TA==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)76 })));
  +        assertEquals("TQ==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)77 })));
  +        assertEquals("Tg==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)78 })));
  +        assertEquals("Tw==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)79 })));
  +        assertEquals("UA==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)80 })));
  +        assertEquals("UQ==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)81 })));
  +        assertEquals("Ug==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)82 })));
  +        assertEquals("Uw==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)83 })));
  +        assertEquals("VA==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)84 })));
  +        assertEquals("VQ==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)85 })));
  +        assertEquals("Vg==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)86 })));
  +        assertEquals("Vw==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)87 })));
  +        assertEquals("WA==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)88 })));
  +        assertEquals("WQ==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)89 })));
  +        assertEquals("Wg==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)90 })));
  +        assertEquals("Ww==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)91 })));
  +        assertEquals("XA==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)92 })));
  +        assertEquals("XQ==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)93 })));
  +        assertEquals("Xg==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)94 })));
  +        assertEquals("Xw==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)95 })));
  +        assertEquals("YA==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)96 })));
  +        assertEquals("YQ==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)97 })));
  +        assertEquals("Yg==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)98 })));
  +        assertEquals("Yw==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)99 })));
  +        assertEquals("ZA==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)100 })));
  +        assertEquals("ZQ==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)101 })));
  +        assertEquals("Zg==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)102 })));
  +        assertEquals("Zw==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)103 })));
  +        assertEquals("aA==",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)104 })));
       }
   
       public void testTriplets() {
  -        assertEquals("AAAA",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)0 })));
  -        assertEquals("AAAB",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)1 })));
  -        assertEquals("AAAC",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)2 })));
  -        assertEquals("AAAD",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)3 })));
  -        assertEquals("AAAE",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)4 })));
  -        assertEquals("AAAF",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)5 })));
  -        assertEquals("AAAG",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)6 })));
  -        assertEquals("AAAH",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)7 })));
  -        assertEquals("AAAI",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)8 })));
  -        assertEquals("AAAJ",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)9 })));
  -        assertEquals("AAAK",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)10 })));
  -        assertEquals("AAAL",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)11 })));
  -        assertEquals("AAAM",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)12 })));
  -        assertEquals("AAAN",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)13 })));
  -        assertEquals("AAAO",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)14 })));
  -        assertEquals("AAAP",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)15 })));
  -        assertEquals("AAAQ",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)16 })));
  -        assertEquals("AAAR",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)17 })));
  -        assertEquals("AAAS",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)18 })));
  -        assertEquals("AAAT",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)19 })));
  -        assertEquals("AAAU",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)20 })));
  -        assertEquals("AAAV",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)21 })));
  -        assertEquals("AAAW",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)22 })));
  -        assertEquals("AAAX",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)23 })));
  -        assertEquals("AAAY",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)24 })));
  -        assertEquals("AAAZ",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)25 })));
  -        assertEquals("AAAa",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)26 })));
  -        assertEquals("AAAb",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)27 })));
  -        assertEquals("AAAc",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)28 })));
  -        assertEquals("AAAd",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)29 })));
  -        assertEquals("AAAe",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)30 })));
  -        assertEquals("AAAf",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)31 })));
  -        assertEquals("AAAg",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)32 })));
  -        assertEquals("AAAh",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)33 })));
  -        assertEquals("AAAi",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)34 })));
  -        assertEquals("AAAj",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)35 })));
  -        assertEquals("AAAk",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)36 })));
  -        assertEquals("AAAl",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)37 })));
  -        assertEquals("AAAm",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)38 })));
  -        assertEquals("AAAn",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)39 })));
  -        assertEquals("AAAo",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)40 })));
  -        assertEquals("AAAp",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)41 })));
  -        assertEquals("AAAq",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)42 })));
  -        assertEquals("AAAr",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)43 })));
  -        assertEquals("AAAs",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)44 })));
  -        assertEquals("AAAt",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)45 })));
  -        assertEquals("AAAu",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)46 })));
  -        assertEquals("AAAv",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)47 })));
  -        assertEquals("AAAw",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)48 })));
  -        assertEquals("AAAx",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)49 })));
  -        assertEquals("AAAy",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)50 })));
  -        assertEquals("AAAz",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)51 })));
  -        assertEquals("AAA0",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)52 })));
  -        assertEquals("AAA1",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)53 })));
  -        assertEquals("AAA2",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)54 })));
  -        assertEquals("AAA3",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)55 })));
  -        assertEquals("AAA4",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)56 })));
  -        assertEquals("AAA5",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)57 })));
  -        assertEquals("AAA6",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)58 })));
  -        assertEquals("AAA7",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)59 })));
  -        assertEquals("AAA8",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)60 })));
  -        assertEquals("AAA9",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)61 })));
  -        assertEquals("AAA+",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)62 })));
  -        assertEquals("AAA/",new String(Base64.encode(new byte[] { (byte)0, (byte)0, 
(byte)63 })));
  +        assertEquals("AAAA",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)0 })));
  +        assertEquals("AAAB",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)1 })));
  +        assertEquals("AAAC",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)2 })));
  +        assertEquals("AAAD",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)3 })));
  +        assertEquals("AAAE",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)4 })));
  +        assertEquals("AAAF",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)5 })));
  +        assertEquals("AAAG",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)6 })));
  +        assertEquals("AAAH",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)7 })));
  +        assertEquals("AAAI",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)8 })));
  +        assertEquals("AAAJ",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)9 })));
  +        assertEquals("AAAK",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)10 })));
  +        assertEquals("AAAL",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)11 })));
  +        assertEquals("AAAM",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)12 })));
  +        assertEquals("AAAN",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)13 })));
  +        assertEquals("AAAO",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)14 })));
  +        assertEquals("AAAP",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)15 })));
  +        assertEquals("AAAQ",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)16 })));
  +        assertEquals("AAAR",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)17 })));
  +        assertEquals("AAAS",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)18 })));
  +        assertEquals("AAAT",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)19 })));
  +        assertEquals("AAAU",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)20 })));
  +        assertEquals("AAAV",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)21 })));
  +        assertEquals("AAAW",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)22 })));
  +        assertEquals("AAAX",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)23 })));
  +        assertEquals("AAAY",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)24 })));
  +        assertEquals("AAAZ",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)25 })));
  +        assertEquals("AAAa",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)26 })));
  +        assertEquals("AAAb",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)27 })));
  +        assertEquals("AAAc",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)28 })));
  +        assertEquals("AAAd",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)29 })));
  +        assertEquals("AAAe",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)30 })));
  +        assertEquals("AAAf",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)31 })));
  +        assertEquals("AAAg",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)32 })));
  +        assertEquals("AAAh",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)33 })));
  +        assertEquals("AAAi",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)34 })));
  +        assertEquals("AAAj",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)35 })));
  +        assertEquals("AAAk",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)36 })));
  +        assertEquals("AAAl",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)37 })));
  +        assertEquals("AAAm",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)38 })));
  +        assertEquals("AAAn",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)39 })));
  +        assertEquals("AAAo",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)40 })));
  +        assertEquals("AAAp",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)41 })));
  +        assertEquals("AAAq",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)42 })));
  +        assertEquals("AAAr",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)43 })));
  +        assertEquals("AAAs",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)44 })));
  +        assertEquals("AAAt",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)45 })));
  +        assertEquals("AAAu",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)46 })));
  +        assertEquals("AAAv",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)47 })));
  +        assertEquals("AAAw",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)48 })));
  +        assertEquals("AAAx",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)49 })));
  +        assertEquals("AAAy",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)50 })));
  +        assertEquals("AAAz",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)51 })));
  +        assertEquals("AAA0",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)52 })));
  +        assertEquals("AAA1",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)53 })));
  +        assertEquals("AAA2",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)54 })));
  +        assertEquals("AAA3",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)55 })));
  +        assertEquals("AAA4",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)56 })));
  +        assertEquals("AAA5",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)57 })));
  +        assertEquals("AAA6",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)58 })));
  +        assertEquals("AAA7",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)59 })));
  +        assertEquals("AAA8",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)60 })));
  +        assertEquals("AAA9",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)61 })));
  +        assertEquals("AAA+",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)62 })));
  +        assertEquals("AAA/",HttpConstants.getAsciiString(Base64.encode(new byte[] { 
(byte)0, (byte)0, (byte)63 })));
       }
   
       public void testKnownEncodings() {
  -        
assertEquals("VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2dzLg==",new 
String(Base64.encode("The quick brown fox jumped over the lazy dogs.".getBytes())));
  -        
assertEquals("SXQgd2FzIHRoZSBiZXN0IG9mIHRpbWVzLCBpdCB3YXMgdGhlIHdvcnN0IG9mIHRpbWVzLg==",new
 String(Base64.encode("It was the best of times, it was the worst of 
times.".getBytes())));
  -        assertEquals("aHR0cDovL2pha2FydGEuYXBhY2hlLm9yZy9jb21tbW9ucw==",new 
String(Base64.encode("http://jakarta.apache.org/commmons".getBytes())));
  -        
assertEquals("QWFCYkNjRGRFZUZmR2dIaElpSmpLa0xsTW1Obk9vUHBRcVJyU3NUdFV1VnZXd1h4WXlaeg==",new
 
String(Base64.encode("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz".getBytes())));
  -        assertEquals("eyAwLCAxLCAyLCAzLCA0LCA1LCA2LCA3LCA4LCA5IH0=",new 
String(Base64.encode("{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }".getBytes())));
  -        assertEquals("eHl6enkh",new String(Base64.encode("xyzzy!".getBytes())));
  +        
assertEquals("VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2dzLg==",HttpConstants.getAsciiString(Base64.encode(HttpConstants.getAsciiBytes("The
 quick brown fox jumped over the lazy dogs."))));
  +        
assertEquals("SXQgd2FzIHRoZSBiZXN0IG9mIHRpbWVzLCBpdCB3YXMgdGhlIHdvcnN0IG9mIHRpbWVzLg==",HttpConstants.getAsciiString(Base64.encode(HttpConstants.getAsciiBytes("It
 was the best of times, it was the worst of times."))));
  +        
assertEquals("aHR0cDovL2pha2FydGEuYXBhY2hlLm9yZy9jb21tbW9ucw==",HttpConstants.getAsciiString(Base64.encode(HttpConstants.getAsciiBytes("http://jakarta.apache.org/commmons";))));
  +        
assertEquals("QWFCYkNjRGRFZUZmR2dIaElpSmpLa0xsTW1Obk9vUHBRcVJyU3NUdFV1VnZXd1h4WXlaeg==",HttpConstants.getAsciiString(Base64.encode(HttpConstants.getAsciiBytes("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"))));
  +        
assertEquals("eyAwLCAxLCAyLCAzLCA0LCA1LCA2LCA3LCA4LCA5IH0=",HttpConstants.getAsciiString(Base64.encode(HttpConstants.getAsciiBytes("{
 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }"))));
  +        
assertEquals("eHl6enkh",HttpConstants.getAsciiString(Base64.encode(HttpConstants.getAsciiBytes("xyzzy!"))));
       }
   
       public void testKnownDecodings() {
  -        assertEquals("The quick brown fox jumped over the lazy dogs.",new 
String(Base64.decode("VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2dzLg==".getBytes())));
  -        assertEquals("It was the best of times, it was the worst of times.",new 
String(Base64.decode("SXQgd2FzIHRoZSBiZXN0IG9mIHRpbWVzLCBpdCB3YXMgdGhlIHdvcnN0IG9mIHRpbWVzLg==".getBytes())));
  -        assertEquals("http://jakarta.apache.org/commmons",new 
String(Base64.decode("aHR0cDovL2pha2FydGEuYXBhY2hlLm9yZy9jb21tbW9ucw==".getBytes())));
  -        assertEquals("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz",new 
String(Base64.decode("QWFCYkNjRGRFZUZmR2dIaElpSmpLa0xsTW1Obk9vUHBRcVJyU3NUdFV1VnZXd1h4WXlaeg==".getBytes())));
  -        assertEquals("{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }",new 
String(Base64.decode("eyAwLCAxLCAyLCAzLCA0LCA1LCA2LCA3LCA4LCA5IH0=".getBytes())));
  -        assertEquals("xyzzy!",new String(Base64.decode("eHl6enkh".getBytes())));
  +        assertEquals("The quick brown fox jumped over the lazy 
dogs.",HttpConstants.getAsciiString(Base64.decode(HttpConstants.getAsciiBytes("VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2dzLg=="))));
  +        assertEquals("It was the best of times, it was the worst of 
times.",HttpConstants.getAsciiString(Base64.decode(HttpConstants.getAsciiBytes("SXQgd2FzIHRoZSBiZXN0IG9mIHRpbWVzLCBpdCB3YXMgdGhlIHdvcnN0IG9mIHRpbWVzLg=="))));
  +        
assertEquals("http://jakarta.apache.org/commmons",HttpConstants.getAsciiString(Base64.decode(HttpConstants.getAsciiBytes("aHR0cDovL2pha2FydGEuYXBhY2hlLm9yZy9jb21tbW9ucw=="))));
  +        
assertEquals("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz",HttpConstants.getAsciiString(Base64.decode(HttpConstants.getAsciiBytes("QWFCYkNjRGRFZUZmR2dIaElpSmpLa0xsTW1Obk9vUHBRcVJyU3NUdFV1VnZXd1h4WXlaeg=="))));
  +        assertEquals("{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 
}",HttpConstants.getAsciiString(Base64.decode(HttpConstants.getAsciiBytes("eyAwLCAxLCAyLCAzLCA0LCA1LCA2LCA3LCA4LCA5IH0="))));
  +        
assertEquals("xyzzy!",HttpConstants.getAsciiString(Base64.decode(HttpConstants.getAsciiBytes("eHl6enkh"))));
       }
   
       // -------------------------------------------------------- Private Methods
  
  
  
  1.7       +10 -10    
jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestStreams.java
  
  Index: TestStreams.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestStreams.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestStreams.java  7 Jan 2003 23:51:01 -0000       1.6
  +++ TestStreams.java  16 Jan 2003 10:53:09 -0000      1.7
  @@ -26,14 +26,14 @@
           HttpMethod method = new SimpleHttpMethod();
   
           //Test for when buffer is larger than chunk size
  -        InputStream in = new ChunkedInputStream(new 
ByteArrayInputStream(correctInput.getBytes()), method);
  +        InputStream in = new ChunkedInputStream(new 
ByteArrayInputStream(HttpConstants.getBytes(correctInput)), method);
           byte[] buffer = new byte[300];
           ByteArrayOutputStream out = new ByteArrayOutputStream();
           int len;
           while ((len = in.read(buffer)) > 0) {
               out.write(buffer, 0, len);
           }
  -        String result = new String(out.toByteArray());
  +        String result = HttpConstants.getContentString(out.toByteArray());
           assertEquals(result, correctResult);
           Header footer = method.getResponseFooter("footer1");
           assertEquals(footer.getValue(), "abcde");
  @@ -42,13 +42,13 @@
   
   
           //Test for when buffer is smaller than chunk size.
  -        in = new ChunkedInputStream(new 
ByteArrayInputStream(correctInput.getBytes()), method);
  +        in = new ChunkedInputStream(new 
ByteArrayInputStream(HttpConstants.getBytes(correctInput)), method);
           buffer = new byte[7];
           out = new ByteArrayOutputStream();
           while ((len = in.read(buffer)) > 0) {
               out.write(buffer, 0, len);
           }
  -        result = new String(out.toByteArray());
  +        result = HttpConstants.getContentString(out.toByteArray());
           assertEquals(result, correctResult);
           footer = method.getResponseFooter("footer1");
           assertEquals(footer.getValue(), "abcde");
  @@ -61,7 +61,7 @@
           String corrupInput = 
"10;key=\"value\"\r\n123456789012345\r\n5\r\n12345\r\n0\r\nFooter1: abcde\r\nFooter2: 
fghij\r\n";
           HttpMethod method = new SimpleHttpMethod();
   
  -        InputStream in = new ChunkedInputStream(new 
ByteArrayInputStream(corrupInput.getBytes()), method);
  +        InputStream in = new ChunkedInputStream(new 
ByteArrayInputStream(HttpConstants.getBytes(corrupInput)), method);
           byte[] buffer = new byte[300];
           ByteArrayOutputStream out = new ByteArrayOutputStream();
           int len;
  @@ -79,7 +79,7 @@
           String input = "0\r\n";
           HttpMethod method = new SimpleHttpMethod();
   
  -        InputStream in = new ChunkedInputStream(new 
ByteArrayInputStream(input.getBytes()), method);
  +        InputStream in = new ChunkedInputStream(new 
ByteArrayInputStream(HttpConstants.getBytes(input)), method);
           byte[] buffer = new byte[300];
           ByteArrayOutputStream out = new ByteArrayOutputStream();
           int len;
  @@ -91,12 +91,12 @@
   
       public void testContentLengthInputStream() throws IOException {
           String correct = "1234567890123456";
  -        InputStream in = new ContentLengthInputStream(new 
ByteArrayInputStream(correct.getBytes()), 10);
  +        InputStream in = new ContentLengthInputStream(new 
ByteArrayInputStream(HttpConstants.getBytes(correct)), 10);
           byte[] buffer = new byte[50];
           int len = in.read(buffer);
           ByteArrayOutputStream out = new ByteArrayOutputStream();
           out.write(buffer, 0, len);
  -        String result = new String(out.toByteArray());
  +        String result = HttpConstants.getContentString(out.toByteArray());
           assertEquals(result, "1234567890");
       }
   
  @@ -104,7 +104,7 @@
           String input = 
"76126;27823abcd;:q38a-\nkjc\rk%1ad\tkh/asdui\r\njkh+?\\suweb";
           ByteArrayOutputStream buffer = new ByteArrayOutputStream();
           OutputStream out = new ChunkedOutputStream(buffer);
  -        out.write(input.getBytes());
  +        out.write(HttpConstants.getBytes(input));
           out.close();
           buffer.close();
           InputStream in = new ChunkedInputStream(new 
ByteArrayInputStream(buffer.toByteArray()), new GetMethod());
  @@ -116,7 +116,7 @@
               result.write(d, 0, len);
           }
   
  -        String output = new String(result.toByteArray());
  +        String output = HttpConstants.getContentString(result.toByteArray());
           assertEquals(input, output);
       }
   
  
  
  
  1.10      +12 -10    
jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappMethods.java
  
  Index: TestWebappMethods.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappMethods.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- TestWebappMethods.java    16 Dec 2002 15:19:37 -0000      1.9
  +++ TestWebappMethods.java    16 Jan 2003 10:53:09 -0000      1.10
  @@ -331,9 +331,11 @@
           client.getHostConfiguration().setHost(host, port, "http");
           PostMethod method = new PostMethod("/" + context + "/body");
           method.setUseDisk(false);
  -        String body = 
"quote=It+was+the+best+of+times%2C+it+was+the+worst+of+times.";
  -        method.setRequestBody(new ByteArrayInputStream(body.getBytes()));
  -        method.setRequestContentLength(body.length());
  +        String bodyStr = 
"quote=It+was+the+best+of+times%2C+it+was+the+worst+of+times.";
  +             byte[] body = HttpConstants.getContentBytes(bodyStr);
  +
  +        method.setRequestBody(new ByteArrayInputStream(body));
  +        method.setRequestContentLength(body.length);
           try {
               client.executeMethod(method);
           } catch (Throwable t) {
  @@ -351,7 +353,7 @@
           PostMethod method = new PostMethod("/" + context + "/body");
           method.setUseDisk(false);
           String body = 
"quote=It+was+the+best+of+times%2C+it+was+the+worst+of+times.";
  -        method.setRequestBody(new ByteArrayInputStream(body.getBytes()));
  +        method.setRequestBody(body);
           method.setRequestContentLength(PostMethod.CONTENT_LENGTH_AUTO);
           try {
               client.executeMethod(method);
  @@ -370,7 +372,7 @@
           PostMethod method = new PostMethod("/" + context + "/body");
           method.setUseDisk(false);
           String body = 
"quote=It+was+the+best+of+times%2C+it+was+the+worst+of+times.";
  -        method.setRequestBody(new ByteArrayInputStream(body.getBytes()));
  +        method.setRequestBody(body);
           method.setRequestContentLength(PostMethod.CONTENT_LENGTH_CHUNKED);
           try {
               client.executeMethod(method);
  @@ -405,7 +407,7 @@
           PostMethod method = new PostMethod("/" + context + "/body");
           method.setUseDisk(false);
           String bodyStr = "Like, hello, and stuff";
  -        byte [] body = bodyStr.getBytes();
  +        byte [] body = HttpConstants.getContentBytes(bodyStr);
           method.setRequestHeader("Content-Type", "text/plain");
           method.setRequestBody(new ByteArrayInputStream(body));
           method.setRequestContentLength(body.length);
  
  
  
  1.11      +9 -8      
jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappRedirect.java
  
  Index: TestWebappRedirect.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappRedirect.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- TestWebappRedirect.java   26 Oct 2002 15:38:18 -0000      1.10
  +++ TestWebappRedirect.java   16 Jan 2003 10:53:09 -0000      1.11
  @@ -206,15 +206,16 @@
       }
   
       public void testPostRedirect() throws Exception {
  -        String body = "Hello World";
  +        String bodyStr = "Hello World";
           HttpClient client = new HttpClient();
           client.startSession(host, port);
           PostMethod method = new PostMethod("/" + context + "/redirect");
           method.setQueryString("to=" + URIUtil.encodeWithinQuery("http://"; +
                       host + ":" + port + "/" + context +
                       "/params?foo=bar&bar=foo"));
  -        method.setRequestBody(new ByteArrayInputStream(body.getBytes()));
  -        method.setRequestContentLength(body.length());  //unbuffered request
  +        byte[] body = HttpConstants.getContentBytes(bodyStr);
  +        method.setRequestBody(new ByteArrayInputStream(body));
  +        method.setRequestContentLength(body.length);  //unbuffered request
           method.setFollowRedirects(true);
           method.setUseDisk(false);
           try {
  @@ -230,7 +231,7 @@
           method.setQueryString("to=" + URIUtil.encodeWithinQuery("http://"; +
                       host + ":" + port + "/" + context +
                       "/params?foo=bar&bar=foo"));
  -        method.setRequestBody(new ByteArrayInputStream(body.getBytes()));
  +        method.setRequestBody(new ByteArrayInputStream(body));
           method.setRequestContentLength(PostMethod.CONTENT_LENGTH_AUTO); //buffered 
request
           method.setFollowRedirects(true);
           method.setUseDisk(false);
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to