// one file B64Encoder
//##############################
package chage;import java.io.*;public class B64Encoder extends FilterWriter { public B64Encoder(Writer w) {
super(w);
} private int charctr = 0;
private int linectr = 0;
private int buffer = 0;
private int encodeByte(int byt) {
if( byt <= 25 ) return 'A' + byt;
if( byt <= 51 ) return 'a' + byt - 26;
if( byt <= 61 ) return '0' + byt - 52;
if( byt <= 62 ) return '+';
if( byt <= 63 ) return '/';
return -1;
} public void close() throws IOException {
flush();
super.close();
} private void writeit(int c) throws IOException {
if(linectr++ >= 76) {
out.write("\r\n");
linectr = 1;
}
out.write(c);
} public void flush() throws IOException {
if(charctr == 2) {
buffer<<=2;
writeit(encodeByte((buffer&0x3F000)>>12));
}
if(charctr == 1) buffer<<=4;
if(charctr != 0) {
writeit(encodeByte((buffer&0xFC0)>>6));
writeit(encodeByte(buffer&0x3F));
if(charctr == 1) writeit('=');
writeit('=');
} charctr = 0;
out.flush();
} public void write(int c) throws IOException {
int code[] = new int[3];
int i;
buffer<<=8;
buffer+=c;
if(++charctr != 3) return;
charctr = 0;
for(i=0; i<4; i++) {
writeit(encodeByte((buffer&0xFC0000)>>18));
buffer<<=6;
}
buffer = 0;
return;
} public void write(char c[], int o, int l) throws IOException {
while(l-- != 0) {
write(c[o++]);
}
} public void write(String s, int of, int l) throws IOException {
write(s.toCharArray(), of, l);
} public static void main(String args[]) throws Exception {
B64Encoder filter = new B64Encoder(
new OutputStreamWriter(System.out));
int x;
filter.write("Hello");
do {
x=System.in.read();
if(x != 1) filter.write(x);
} while(x != -1);
filter.flush();
}
}

解决方案 »

  1.   

    // two file
    //##############################################
    package chage;import java.util.Hashtable;
    //import java.io.Writer;public class MailMessage { public String sender;
    public String to;
    public String cc;
    public String bcc;
    public String subject;
    public String body;
    public Class encoder=null;
    public Hashtable headers=null; public MailMessage() {
    } public MailMessage(String _from, String _to, String _cc,
    String _bcc, String _subject, String _body)
    {
    sender = _from;
    to = _to;
    cc = _cc;
    bcc = _bcc;
    subject = _subject;
    body = _body;
    } public MailMessage(String _from, String _to,
    String _subject, String _body ) {
    sender = _from;
    to = _to;
    subject = _subject;
    body = _body;
    } public void addHeader(String header, String value) {
    if(headers==null) headers = new Hashtable();
    headers.put(header, value);
    }
    }
      

  2.   

    // three file
    //##############################################
    package chage;public class SMTPResults {
    static final public int SMTP_RESULT_UNRECOG = 500;
    static final public int SMTP_RESULT_PARAM = 501;
    static final public int SMTP_RESULT_UNIMPLEMENTED = 502;
    static final public int SMTP_RESULT_SEQUENCE = 503;
    static final public int SMTP_RESULT_PARAMNI = 504;
    static final public int SMTP_RESULT_SYSTEM = 211;
    static final public int SMTP_RESULT_HELP = 214;
    static final public int SMTP_RESULT_READY = 220;
    static final public int SMTP_RESULT_CLOSING = 221;
    static final public int SMTP_RESULT_SERUNAVAILABLE = 421;
    static final public int SMTP_RESULT_COMPLETED = 250;
    static final public int SMTP_RESULT_FORWARD = 251;
    static final public int SMTP_RESULT_MBXUNAVAILABLE = 450;
    static final public int SMTP_RESULT_NOTTAKEN = 550;
    static final public int SMTP_RESULT_ABORTED = 451;
    static final public int SMTP_RESULT_USER_NOT_LOCAL = 551;
    static final public int SMTP_RESULT_STORAGE = 452;
    static final public int SMTP_RESULT_EXSTORAGE = 552;
    static final public int SMTP_RESULT_NOT_ALLOWED = 553;
    static final public int SMTP_RESULT_MAIL_START = 354;
    static final public int SMTP_RESULT_TRANS_FAILED = 554;
    }