日期:2014-05-19 浏览次数:20838 次
// Copyright (C) 1999-2002 by Jason Hunter <jhunter_AT_acm_DOT_org>.
// All rights reserved. Use of this class is limited.
// Please see the LICENSE for more information.
package org.apache.commons.mvc.util;
import java.io.*;
/***
* A class to encode Base64 streams and strings.
* See RFC 1521 section 5.2 for details of the Base64 algorithm.
* <p>
* This class can be used for encoding strings:
* <blockquote><pre>
* String unencoded = "webmaster:try2gueSS";
* String encoded = Base64Encoder.encode(unencoded);
* </pre></blockquote>
* or for encoding streams:
* <blockquote><pre>
* OutputStream out = new Base64Encoder(System.out);
* </pre></blockquote>
*
* @author <b>Jason Hunter</b>, Copyright © 2000
* @version 1.2, 2002/11/01, added encode(byte[]) method to better handle
* binary data (thanks to Sean Graham)
* @version 1.1, 2000/11/17, fixed bug with sign bit for char values
* @version 1.0, 2000/06/11
*/
public class Base64Encoder extends FilterOutputStream {
private static final char[] chars = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',
'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', '+', '/'
};
private int charCount;
private int carryOver;
/***
* Constructs a new Base64 encoder that writes output to the given
* OutputStream.
*
* @param out the output stream