File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Size of the response sent by the server.

 
Robin Sharma
Ranch Hand
Posts: 76
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

How do i calculate the size of the response sent by the server for a request? I am using a servlet filter which just prints the size of the request/response. Now, I can get the size of the request using the request.getContentLength() method. But, how do i get the size of the response?

Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you feel you need it?
 
dema rogatkin
Ranch Hand
Posts: 294
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's quite simple. You need to wrap a response object in your object which plays a role of proxy. You should care only about two methods: getOutputStream and getWriter. Return your own implementation wrapping objects returned by original response for these methods. Your implementation is also a proxy which counts a number of processed bytes. You can use Java proxy capabilities or HttpServletResponseWrapper to simplify your implementation.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13047
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If, on the other hand, he needs the size to set the response content-length header, this size is needed before anything is written to the response. In that case all output should be to a local buffer - see java.io CharArrayWriter or ByteArrayOutputStream - finish the output, use the size to set the header, write the whole buffer at one go.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic