I am trying to get the lowest byte count using URLConnection . I already went to count the data passing through two streams: CountingInputStream and CountingOutputStream from Apache Commons IO, but the byte count that I receive is equal to the size of the body that I send + the size of the response body that I receive.
In HttpClient, I had a MeasuringClientConnManager with what I assume is a lower byte byte.
To get the most accurate value, I compare the count of these libraries with these methods using TrafficStats :
public static long getCurrentRx(Context context){ int uid = context.getApplicationInfo().uid; return TrafficStats.getUidRxBytes(uid); } public static long getCurrentTx(Context context){ int uid = context.getApplicationInfo().uid; return TrafficStats.getUidTxBytes(uid); } public static long getCurrentNetworkUsage(Context context){ return getCurrentRx(context) + getCurrentTx(context); } public static long getDiffNetworkUsage(Context context, long previousNetworkUsage){ return getCurrentNetworkUsage(context) - previousNetworkUsage; }
Using these methods, I got much closer values ββwith HttpClient than URLConnection.
Two questions:
How on URLConnection I donβt see headers sent on the byte size indicator of OutputStream? Why do I see there only body size? Where are the headlines? Phone call? Does DNS resolve bytes?
Is there a way to measure every byte so that the URLConnection library call is sent over the network interface? The lowest level the better!
java android io apache network-programming
galex
source share