[prev in list] [next in list] [prev in thread] [next in thread] 

List:       bouncycastle-crypto-dev
Subject:    Re: [dev-crypto]
From:       David Hook <dgh () lockboxlabs ! com>
Date:       2008-10-23 0:31:05
Message-ID: 1224721865.4101.30.camel () echidna
[Download RAW message or body]


The streaming classes can be identified as those that end in the string
Parser or Generator.

Regards,

David

On Wed, 2008-10-22 at 09:52 +0200, Don Vito Carry Flag wrote:
> Thank you for answering David,
> which are the classes you are referring to? I thought that
> ASN1InputStream is already a streaming class. I checked the javadocs
> for the package, but I'm not sure which class to pick.
> Thank you again.
> Regards
> 
> On Wed, Oct 22, 2008 at 12:54 AM, David Hook <dgh@lockboxlabs.com> wrote:
> >
> > You could get some improvement by using the streaming classes in the
> > ASN.1 package. You'll probably still have an issue though - the problem
> > is that DER is a definite-length encoding so it has to consume a lot
> > more memory as it needs a full copy of the data before it can write out
> > it's length.
> >
> > Regards,
> >
> > David
> >
> > On Tue, 2008-10-21 at 11:28 +0200, Don Vito Carry Flag wrote:
> >> Hello everybody,
> >> I'm converting an array rappresenting a BER encoded signature,
> >> generated using CMSSignedDataGenerator to a DER encoded one. The code
> >> is the following:
> >> byte[] signedData = data.getEncoded();
> >> ASN1InputStream asnIS = new ASN1InputStream(signedData);
> >> ByteArrayOutputStream bArr = new ByteArrayOutputStream();
> >> DEROutputStream dOut = new DEROutputStream(bArr);
> >> dOut.writeObject(asnIS.readObject());
> >> byte[] newSignedData = bArr.toByteArray();
> >> fos.write(newSignedData);
> >>
> >>
> >> Now my problem is that it takes too much memory, and every time I
> >> don't use -Xmx parameter when calling my application, it crashes
> >> throwing "OutOfMemoryError: Java heap space" error, referred to the
> >> line dOut.writeObject(asnIS.readObject()).
> >> Even when called with the -Xmx parameter, it needs up to 1023 Mb of
> >> memory in order to encode an 80Mb file...
> >> In the error stack trace I saw that it is related to
> >> ByteArrayOutputStream.write method and to java.util.Arrays.CopyOf.
> >> I tryed to use buffered streams this way, but it doesn't make any effect:
> >> byte[] signedData = data.getEncoded();
> >> ByteArrayInputStream bais = new ByteArrayInputStream(signedData);
> >> BufferedInputStream bis = new BufferedInputStream(bais,5);
> >> ASN1InputStream asnIS = new ASN1InputStream(bis);
> >> BufferedOutputStream bos = new BufferedOutputStream(fos,5);
> >> DEROutputStream dOut = new DEROutputStream(bos);
> >> dOut.writeObject(asnIS.readObject());
> >> bos.flush();
> >> bos.close();
> >> dOut.close();
> >>
> >>
> >> Thank you everybody in advance.
> >> Greetings
> >> Vito Carry Flag
> >>
> >
> >
> 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic