How to calculate the data transfered over a HTTP Connection

Posted on 2007-08-05
Last Modified: 2013-11-22

I am working on a mobile application that will transfer data to a server but in order to calculate the cost for the transfer ie. Network data charge, I need to know the complete amount of data transfered including header, body content and response etc.

How can this be done?

Using: Java in NetBeans 5.5.1 with Apache 5.5.17

Thanks for your help
Question by:Dudach
    LVL 16

    Accepted Solution

    LVL 86

    Expert Comment

    Probably the best thing to do is to use a loggable proxy
    LVL 51

    Expert Comment

    do you mean the request or the response data?

    Author Comment

    I am looking to calculate the number of bytes being received at the server.

    What I have on the server side is:
    ServletInputStream in = request.getInputStream();
    DataInputStream din = new DataInputStream(in);

    But I want to get the number of bytes in the DataInputStream din. How can this be done?

    Thanks in advance

    LVL 86

    Assisted Solution

    >>But I want to get the number of bytes in the DataInputStream din. How can this be done?

    By reading it and counting them as it's read
    LVL 51

    Assisted Solution

    number_of_bytes += din.length;

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
    Cloud file services can fill many different roles for your business. Often, the use of cloud file services begins with employees using consumer products, like Dropbox, to share files with customers and each other. While sync-and-share can be an effe…
    Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
    Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now