Holger: I knew something had been said on this subject previously...I took note but it is not impacting me yet. See the attached note from Jason Robertson on 1/29/2001. I didn't see any ack of someone handling his patch.
Dale -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, February 08, 2001 9:25 AM To: [EMAIL PROTECTED] Subject: base64 encoded content Hi, I'm using the Base64 class to encode and decode binary data in xml files and encountered some strange things I hope someone can explain. If I'm encoding a byte array with a size of 33552 bytes I get an array of the length 44736, which seems correct to me. Decoding it returns an array with 33553 bytes - one more than the original byte array. This looks like a bug, am I right? If I'm right, does anyone has fixed it already? The second strange effect occurs while parsing the xml document with the encoded data. The document looks like that: <content>/KJjndlkh/lhjnlkj...</content> The SAX parser splits my content into three parts, invoking the "characters" method three times. Am I doing something wrong? Thanks for any idea! Holger --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--- Begin Message ---The utils class Base64 has a bug in the decode method - the byte array returned has the wrong length. This simple example shows the problem: public class test { public static void main( String args[] ) { byte[] original = new byte[1]; original[0] = 'A'; byte[] encoded = org.apache.xerces.utils.Base64.encode( original ); byte[] decoded = org.apache.xerces.utils.Base64.decode( encoded ); if ( original.length != decoded.length ) { System.out.println( "Sizes aren't the same!" ); System.out.println( "Original: '" + new String( original ) + "'" ); System.out.println( "Decoded : '" + new String( decoded ) + "'" ); } } } The output is this: Sizes aren't the same! Original: 'A' Decoded : 'A ' Note the extra spaces after the decoded value (actually zero-value bytes, I think). The problem in the code is that no adjustment is made for padding characters when the size of the output buffer is determined: decodedData = new byte[ numberQuadruple*3 + 1 ]; Should be: decodedData = new byte[ numberQuadruple*3 - numberPadCharacters ]; (where numberPadCharacters must be determined). Not really sure why the +1 is there on the current code, seems very C-ish in that the code is assuming it's a string and is making room for the null-terminating character. Jason
--- End Message ---
