Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Size of an InputStream

 
Andr� Latour
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good morning everyone,

one (simple) question, regarding these lines of code:

this.in = this.urlConHttp.getInputStream( );
ObjectInputStream oin = new ObjectInputStream( in );
Collection result = ( Collection ) oin.readObject( );

Now, i want to know how "big" the InputStream is, that was transmitted. Is there a simple solution?

Thanks in advance
Andr�
 
Joe Ess
Bartender
Posts: 9300
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't tell us what this.urlConHttp is, so we'll have to speculate. If you have a URLConnection instance, you could try using getHeader() to read the Content-Length header field.
 
Andr� Latour
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Joe,

excuse me that was my fault, i thought that the name was self explaining.
You are right, this is a HttpURLConnection. Unfortunately i resolved the following Map after using .getHeaderFields()


{Connection=[Keep-Alive], Content-Language=[en-US], Date=[Fri, 25 Aug 2006 13:39:14 GMT], Keep-Alive=[timeout=15, max=100], Server=[IBM_HTTP_SERVER/1.3.28.1 Apache/1.3.28 (Unix)], Content-Type=[text/html; charset=ISO-8859-1], Transfer-Encoding=[chunked], null=[HTTP/1.1 200 OK]}

I cannot find the "Content-Length" field. :-(

Thank you very much
Andr�
 
Andr� Latour
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
addendum:

when i use .getContentLength i only receive -1, although i transfer over 20000 Objects within a Collection via Http.... ???

Andr�
 
Joe Ess
Bartender
Posts: 9300
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Content-Length is set by the server. It is not required. If you are using a servlet then you would have to set the content length.
Why do you want to know the length of an input stream when you are transferring Objects? I like to think we use Objects so we don't have to think about bytes.
 
Andr� Latour
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Joe,

i would like to know how much "traffic" is on the net depending on the size of transfered objects.

Thankyou for your answers
Andr�
 
Joe Ess
Bartender
Posts: 9300
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you just want a ballpark figure, serialize a known number of objects to a file and read the size. Keep in mind that there will be overhead for serialization housekeeping information and, if you serialize one, the collection itself. The size of the objects themselves may be variable, especially if they contain wildly variable Strings or collections.
If you want an exact figure, you could try wrapping the ServletOutputStream you hook the ObjectOutputStream to and measure the bytes being written.
You could also observe the network traffic with a sniffer, but I have no experience with that.
 
Dana Bothner-By
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A general idea: if you want to see how may bytes are read from an input stream, define the obvious decorator and include it in your pipeline:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic