-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Create Blob from InputStream
PostPosted: Tue May 25, 2010 4:48 pm 
Newbie

Joined: Tue Nov 01, 2005 12:38 pm
Posts: 12
Hi,

I tried to create a Blob from an InputStream and had the problem that the Blob was sometimes empty.

I looked into the Hibernate source and found the reason:

Code:
   
public static Blob createBlob(InputStream stream) throws IOException {
    return new SerializableBlob( new BlobImpl( stream, stream.available() ) );
}


This works when reading from a file, because stream.available() returns the correct size. But how can this work when the size of the streamed data is unknown? I would have expected that this method reads until the end of the stream. According to the JDK documentation, the result of stream.available() should not be used here:

http://java.sun.com/javase/6/docs/api/java/io/InputStream.html#available%28%29

Quote:
Note that while some implementations of InputStream will return the total number of bytes in the stream, many will not. It is never correct to use the return value of this method to allocate a buffer intended to hold all data in this stream.


Regards,

Sven


Top
 Profile  
 
 Post subject: Re: Create Blob from InputStream
PostPosted: Wed May 26, 2010 3:29 am 
Newbie

Joined: Tue Nov 01, 2005 12:38 pm
Posts: 12
Solved:

http://opensource.atlassian.com/project ... issuepanel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.