chewiebug/GCViewer — pull request #78 by hbswn (2013-09-10 20:20:43+00:00)
Title: Handle HTTP error response + set Accept-Encoding to request gzip'd data.

Includes JUnit test using Mockito. (See https://code.google.com/p/mockito/ )

I've replaced "readModel(URL)"s:

InputStream in = url.openStream();

with:

URLConnection conn = url.openConnection();
InputStream in = conn instanceof HttpURLConnection
? openInputStream((HttpURLConnection)conn, "gzip")
: conn.getInputStream();

That makes "openInputStream()" testable by mocking HttpURLConnection.

openInputStream():
- sets HTTP request Accept-Encoding header, so that the server will send gzip'd data if it can.
- disables caches. Otherwise you won't see updates when the application on the server writes to the gc log file.
- reads response status
- reads error stream if response is not OK
- decodes gzip'd stream if server sets Content-Encoding response header.