[Jukebox-cvs] CVS update: J4/src/java/gnu/j4/examples Base64Example.java
Brought to you by:
vtt
From: CVS B. <vt...@fr...> - 2000-08-04 23:21:13
|
User: vt Date: 00/08/04 16:21:08 Modified: src/java/gnu/j4/examples Base64Example.java Log: Checkpoint. It's not exactly clear what is going on here. Revision Changes Path 1.2 +37 -4 J4/src/java/gnu/j4/examples/Base64Example.java CVSWEB Options: ------------------- CVSWeb: Annotate this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/examples/Base64Example.java?annotate=1.2&cvsroot=jukebox4 CVSWeb: View this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/examples/Base64Example.java?rev=1.2&content-type=text/x-cvsweb-markup&cvsroot=jukebox4 CVSWeb: Diff to previous version: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/examples/Base64Example.java.diff?r1=1.2&r2=1.1&cvsroot=jukebox4 ----------------------------------- Index: Base64Example.java =================================================================== RCS file: /usr/local/cvs/J4/src/java/gnu/j4/examples/Base64Example.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- Base64Example.java 2000/07/25 09:22:17 1.1 +++ Base64Example.java 2000/08/04 23:21:07 1.2 @@ -15,7 +15,7 @@ * MIME Base64 encoding/decoding example. * * @author Copyright © <a href="mailto:vt...@fr...">Vadim Tkachenko</a> 1995-1998 - * @version $Id: Base64Example.java,v 1.1 2000/07/25 09:22:17 vt Exp $ + * @version $Id: Base64Example.java,v 1.2 2000/08/04 23:21:07 vt Exp $ */ public class Base64Example extends ActiveService { @@ -81,10 +81,33 @@ ByteArrayOutputStream out = new ByteArrayOutputStream(); + // This is guaranteed to work, has been tested before. + + while ( true ) { + + int ch = encoderStream.read(); + + if ( ch == -1 ) { + + break; + } + + out.write(ch); + } + + String encodedReliable = out.toString(); + + complain(LOG_NOTICE, CH_BASE64, "Encoded: '" + encodedReliable + "'"); + + in = new ByteArrayInputStream(source.getBytes()); + encoderStream = new Base64EncoderInputStream(in, 0); + + out = new ByteArrayOutputStream(); + while ( encoderStream.available() != 0 ) { // while ( true ) { - complain(LOG_NOTICE, CH_BASE64, "Available: " + encoderStream.available()); + complain(LOG_INFO, CH_BASE64, "Available: " + encoderStream.available()); int ch = encoderStream.read(); // complain(LOG_NOTICE, CH_BASE64, "Encoded: '" + (char)ch + "' (" + ch + ")"); @@ -99,9 +122,14 @@ } String encoded = out.toString(); + + complain(LOG_NOTICE, CH_BASE64, "Encoded: '" + encoded + "', length " + encoded.length()); - complain(LOG_NOTICE, CH_BASE64, "Encoded: '" + encoded + "'"); + if ( !encodedReliable.equals(encoded) ) { + complain(LOG_ERR, CH_BASE64, "FAILED: '" + encodedReliable + "', length " + encodedReliable.length()); + } + in = new ByteArrayInputStream(encoded.getBytes()); Base64DecoderInputStream decoderStream = new Base64DecoderInputStream(in); @@ -110,7 +138,7 @@ while ( decoderStream.available() != 0 ) { // while ( true ) { - complain(LOG_NOTICE, CH_BASE64, "Available: " + decoderStream.available()); + complain(LOG_INFO, CH_BASE64, "Available: " + decoderStream.available()); int ch = decoderStream.read(); // complain(LOG_NOTICE, CH_BASE64, "Decoded: '" + (char)ch + "' (" + ch + ")"); @@ -127,6 +155,11 @@ String decoded = out.toString(); complain(LOG_NOTICE, CH_BASE64, "Decoded: '" + decoded + "'"); + + if ( !source.equals(decoded) ) { + + complain(LOG_ERR, CH_BASE64, "FAILED: '" + source + "', length " + source.length()); + } } } |