You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Dominique <op...@gmail.com> on 2006/09/05 14:10:11 UTC

custom Serializer: not getting the last 20 bytes , setOutputStream

Hi,

because I need to write XML streams to binary encrypted files, I made
a custom serializer, which replaces the outputStream with a
CipherOutputStream, based on the code of the XMLSerializer. This seems
to work, however, I got a problem:
it does not receive the last 20 bytes. When decrypting the result, I
get at the end eg.:

</body></SessionIt

at the end, instead of :

</body></SessionItem></MeetingMinutes>.

I 'm not sure if I'm implementing the serializer the wright way...

thx,

Dominique

CODE:

public class EncryptedSerializer extends AbstractTextSerializer {

	private Logger log = Logger.getLogger( this.getClass());
	

    public void setOutputStream(OutputStream out) throws IOException {
        //this is a replacement of function call, to show the meaning
    	CipherOutputStream encr_stream = new CipherOutputStream(out, encrypter);	
    	
        super.setOutputStream(encr_stream);
        log.debug("Setting encrypted stream");
		try {
            TransformerHandler handler = this.getTransformerHandler();
            handler.getTransformer().setOutputProperties(this.format);
            handler.setResult(new StreamResult(encr_stream));
            this.setContentHandler(handler);
            this.setLexicalHandler(handler);
        } catch (Exception e) {
            final String message = "Cannot set XMLSerializer outputstream";
            throw new CascadingIOException(message, e);
        }
    }


/**
     * Set the configurations for this serializer.
     */
    public void configure(Configuration conf)
    throws ConfigurationException {
        super.configure( conf );
        this.format.put(OutputKeys.METHOD,"xml");

    }

}

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: custom Serializer: not getting the last 20 bytes , setOutputStream

Posted by Dominique <op...@gmail.com>.
I thought in that direction too, yet the flush() doesn't seem to do the trick.
I just tried output.flush() before super.endDocument() and after, it
was called,
but I'm having the same problem.

On 05/09/06, Bertrand Delacretaz <bd...@apache.org> wrote:
> On 9/5/06, Dominique <op...@gmail.com> wrote:
>
> > ...it does not receive the last 20 bytes...
>
> You're most probably missing a flush() call somewhere, maybe your
> CipherOutputStream is not auto-flushing? You can override
> endDocument() and do the flush there.
>
> -Bertrand
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: custom Serializer: not getting the last 20 bytes , setOutputStream

Posted by Bertrand Delacretaz <bd...@apache.org>.
On 9/5/06, Dominique <op...@gmail.com> wrote:

> ...it does not receive the last 20 bytes...

You're most probably missing a flush() call somewhere, maybe your
CipherOutputStream is not auto-flushing? You can override
endDocument() and do the flush there.

-Bertrand

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org