⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 base64outputstream.java

📁 java版的网络蚂蚁软件
💻 JAVA
字号:
package com.heaton.bot;import java.io.*;/** * This filter is used to 64-bit encode the specified string. * This allows a string to be displayed with only ASCII characters. * It is also used to provide HTTP authorization. * * Copyright 2001-2003 by Jeff Heaton (http://www.jeffheaton.com) * * @author Jeff Heaton * @version 1.2 */class Base64OutputStream extends FilterOutputStream {  /**   * The constructor.   *   * @param out The stream used to write to.   */  public Base64OutputStream(OutputStream out)  {    super(out);  }  /**   * Write a byte to be encoded.   *   * @param c The character to be written.   * @exception java.io.IOException   */  public void write(int c) throws IOException  {    buffer[index] = c;    index++;    if ( index==3 ) {      super.write(toBase64[(buffer[0]&0xfc)>>2]);      super.write(toBase64[((buffer[0] &0x03)<<4) |                           ((buffer[1]&0xf0)>>4)]);      super.write(toBase64[((buffer[1]&0x0f)<<2) |                           ((buffer[2]&0xc0)>>6)]);      super.write(toBase64[buffer[2]&0x3f]);      column+=4;      index=0;      if ( column>=76 ) {        super.write('\n');        column = 0;      }    }  }  /**   * Ensure all bytes are written.   *   * @exception java.io.IOException   */  public void flush()  throws IOException  {    if ( index==1 ) {      super.write(toBase64[(buffer[2]&0x3f) >> 2]);      super.write(toBase64[(buffer[0]&0x03) << 4]);      super.write('=');      super.write('=');    } else if ( index==2 ) {      super.write(toBase64[(buffer[0]&0xfc) >> 2]);      super.write(toBase64[((buffer[0]&0x03)<<4)|                           ((buffer[1]&0xf0)>>4)]);      super.write(toBase64[(buffer[1]&0x0f)<<2]);      super.write('=');    }  }  /**   * Allowable characters for base-64.   */  private static char[] toBase64 =  { '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','+','/'};  /**   * Current column.   */  private int column=0;  /**   * Current index.   */  private int index=0;  /**   * Outbound buffer.   */  private int buffer[] = new int[3];}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -