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

List:       bouncycastle-crypto-dev
Subject:    Re: [dev-crypto] DerOutPutStream.writeObject(ASN1InputStream.readObject()); heap problem
From:       "Don Vito Carry Flag" <d0nvit0cf () gmail ! com>
Date:       2008-10-22 7:52:43
Message-ID: c63a41e50810220052n4a1c48b3nede388cb6a1c0013 () mail ! gmail ! com
[Download RAW message or body]

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