com.oreilly.servlet
类 Base64Encoder

java.lang.Object
  继承者 java.io.OutputStream
      继承者 java.io.FilterOutputStream
          继承者 com.oreilly.servlet.Base64Encoder
所有已实现的接口:
Closeable, Flushable

public class Base64Encoder
extends FilterOutputStream

A class to encode Base64 streams and strings. See RFC 1521 section 5.2 for details of the Base64 algorithm.

This class can be used for encoding strings:

 String unencoded = "webmaster:try2gueSS";
 String encoded = Base64Encoder.encode(unencoded);
 
or for encoding streams:
 OutputStream out = new Base64Encoder(System.out);
 

版本:
1.2, 2002/11/01, added encode(byte[]) method to better handle binary data (thanks to Sean Graham), 1.1, 2000/11/17, fixed bug with sign bit for char values, 1.0, 2000/06/11
作者:
Jason Hunter, Copyright © 2000

字段摘要
 
从类 java.io.FilterOutputStream 继承的字段
out
 
构造方法摘要
Base64Encoder(OutputStream out)
          Constructs a new Base64 encoder that writes output to the given OutputStream.
 
方法摘要
 void close()
          Closes the stream, this MUST be called to ensure proper padding is written to the end of the output stream.
static String encode(byte[] bytes)
          Returns the encoded form of the given unencoded string.
static String encode(String unencoded)
          Returns the encoded form of the given unencoded string.
static void main(String[] args)
           
 void write(byte[] buf, int off, int len)
          Writes the given byte array to the output stream in an encoded form.
 void write(int b)
          Writes the given byte to the output stream in an encoded form.
 
从类 java.io.FilterOutputStream 继承的方法
flush, write
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

Base64Encoder

public Base64Encoder(OutputStream out)
Constructs a new Base64 encoder that writes output to the given OutputStream.

参数:
out - the output stream
方法详细信息

write

public void write(int b)
           throws IOException
Writes the given byte to the output stream in an encoded form.

覆盖:
FilterOutputStream 中的 write
抛出:
IOException - if an I/O error occurs

write

public void write(byte[] buf,
                  int off,
                  int len)
           throws IOException
Writes the given byte array to the output stream in an encoded form.

覆盖:
FilterOutputStream 中的 write
参数:
buf - the data to be written
off - the start offset of the data
len - the length of the data
抛出:
IOException - if an I/O error occurs

close

public void close()
           throws IOException
Closes the stream, this MUST be called to ensure proper padding is written to the end of the output stream.

指定者:
接口 Closeable 中的 close
覆盖:
FilterOutputStream 中的 close
抛出:
IOException - if an I/O error occurs

encode

public static String encode(String unencoded)
Returns the encoded form of the given unencoded string. The encoder uses the ISO-8859-1 (Latin-1) encoding to convert the string to bytes. For greater control over the encoding, encode the string to bytes yourself and use encode(byte[]).

参数:
unencoded - the string to encode
返回:
the encoded form of the unencoded string

encode

public static String encode(byte[] bytes)
Returns the encoded form of the given unencoded string.

参数:
bytes - the bytes to encode
返回:
the encoded form of the unencoded string

main

public static void main(String[] args)
                 throws Exception
抛出:
Exception


Copyright © 2013. All Rights Reserved.