[jdom-interest] fail to output Document to encrypted file

Phill_Perryman at Mitel.COM Phill_Perryman at Mitel.COM
Fri Dec 5 07:41:37 PST 2003


I use the following in my extended document to serialize itself

      XMLOutputter serializer = new XMLOutputter();
      FileOutputStream fos = new FileOutputStream(file);
      CipherOutputStream out = new CipherOutputStream(fos, pbeCipher);
      serializer.setOmitEncoding(true);
      serializer.setOmitDeclaration(true);
      serializer.output(this, out);
      out.flush();
      out.close();

/Phill
IS Dept, Software Engineer.
phill_perryman at mitel.com
http://www.mitel.com
Tel: +44 1291 436023


                                                                                                                                          
                      Laurent Bihanic                                                                                                     
                      <laurent.bihanic at atos       To:       ÁÎÃûѧ <mxliao at mails.gscas.ac.cn>                                             
                      origin.com>                 cc:       jdom-interest at jdom.org                                                        
                      Sent by:                    Subject:  Re: [jdom-interest] fail to output Document to encrypted file                 
                      jdom-interest-admin at j                                                                                               
                      dom.org                                                                                                             
                                                                                                                                          
                                                                                                                                          
                      05/12/2003 14:38                                                                                                    
                                                                                                                                          
                                                                                                                                          





XMLOutputter does not close the stream. You should try :

       OutputStream os = new CipherOutputStream(                        new
FileOutputStream(catFilePath),cipher);
       outp.output(doc, os);
       os.close();

Laurent


On 05/12/2003 15:29, ÁÎÃûѧ wrote:

> Using "flowfish", I encrypted an xml file which is from a Document
instance and
> successfully rebuilt the Document instance from the encypted file. Then
before
> closing my application, I output the Document instance to an encrypted
file. The
> code is as below, but the resulting file is not all right and seems to
lack a few
> bytes(especially the last bytes) after it is decrypted.
>
>     try
>     {
>       String indent = " ";
>       boolean newLines = true;
>       XMLOutputter outp = new XMLOutputter(indent, newLines, "GB2312");
>       outp.setTextTrim(true);
>       // doc is a correct Document instance
>       // catFilePath is a String instance
>       // cipher is a Cipher instance for encrypting
>       outp.output(doc,new CipherOutputStream( >                       new
FileOutputStream(catFilePath),cipher));
>     }
>     catch (Exception e) {e.printStackTrace();}
>
> If I change indent,newLines,or remove "outp.setTextTrim(true)", the
resulting file
> changes a little accordingly.
>
>
> _______________________________________________
> To control your jdom-interest membership:
>
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com

>

--
                  wWw
                 (o o)
-------------ooO-(_)-Ooo-----------------------------------------------
Laurent Bihanic                | Tel: +33 (0)1 55.91.21.93 (direct)
AtosOrigin Systems Integration |      +33 (0)1 55.91.20.00
Generic Solutions / SC         | Fax: +33 (0)1 55.91.22.31
Les Miroirs - Bat. C           |
18, avenue d'Alsace            |
F-92926 La Defense Cedex       | E-mail: laurent.bihanic at atosorigin.com
-----------------------------------------------------------------------

"Most Linux are trying to model themselves after the dysfunctional
  MS desktop. What joy is there in running a cheap knockoff of a
  second rate desktop?"

DISCLAIMER:
The opinions expressed are entirely my own and may not necessarily be
those of my employer.  Also, I am not now nor have I ever been a
lawyer.  My opinions are provided as-is with absolutely no warrantee of
merchantability or fitness for any particular use.  Besides, you can't
prove I typed this.  No body saw me type this.  Who says I typed this?

_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com









More information about the jdom-interest mailing list