I’m reading a large xml file using HttpURLConnection in java as follows.
StringBuilder responseBuilder = new StringBuilder(1024);
char[] buffer = new char[4096];
BufferedReader br = new BufferedReader(new InputStreamReader(((InputStream)new DataInputStream(new GZIPInputStream(connection.getInputStream()))),"UTF-8"));
int n = 0;
while(n>=0){
n=br.read(buffer,0,buffer.length);
if(n>0) responseBuilder.append(buffer,0,n);
}
Is there any way to get the total number of bytes loaded to the BufferedReader before finish reading it char by char / line by line / char block by char block.
It sounds like you’re trying to find out the size of the
BufferedReaderwithout consuming it.You could try using the
HttpURLConnection‘sgetContentLength()method. This may or may not work. What it certainly wouldn’t do is give you the uncompressed size of the stream. If it’s the latter that you’re after, you’re almost certainly out of luck.If I have misunderstood your question, please clarify what it is exactly that you’re after.