You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by "Sye, Karin" <ka...@lmco.com> on 2000/08/02 00:24:01 UTC

how to encode double to a Base64 string

Hi,

  I'm having problems to save doubles into my xml file as Base64 encoding
strings.
  The source code and  error messages are attached below.   Can someone
point
  out to me what's been done wrong in the source code?  Thanks for the help.

karin



    try {
      ByteArrayOutputStream byteOut = new ByteArrayOutputStream();;
      DataOutputStream out = new DataOutputStream(byteOut);
     
      double d = 1.1;
      out.writeDouble(d);
	out.flush();
	byte[] buf  = byteOut.toByteArray();
      System.out.println(buf.length);
      byte[] buf2 = (new Base64()).encode(buf);
    } catch (Exception e) {
      e.printStackTrace();
    }

     
       8 
       java.lang.ArrayIndexOutOfBoundsException
        at org.apache.xerces.utils.Base64.encode(Base64.java, Compiled Code)
        at byteTest.main(byteTest.java:18)