Q:

Java file download isn't downloading an exact copy of the file

I have a Java servlet that implements a file download.   It includes the following code:
String filename = request.getParameter("filename");
File file = new File(filename);
FileInputStream inputStream = null;
ServletOutputStream outputStream = response.getOutputStream();
ServletContext servletContext = getServletContext();
String mimeType = servletContext.getMimeType(filename);
if (mimeType == null)
    mimeType = "application/octet-stream";
logger.trace("MIME type for " + filename + " is " + mimeType);
response.setContentType(mimeType);
response.setContentLength((int)file.length());
response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");

inputStream = new FileInputStream(file);
byte[] buffer = new byte[1024];
int bytesRead = 0;
while ((bytesRead = inputStream.read(buffer)) ! = -1) {
    outputStream.write(buffer, 0, bytesRead);
}
outputStream.close();
if (inputStream ! = null)
    inputStream.close();

On the server we have a file.tar.gz, and when the browser sends the request to download that file, I see a line in the log file saying that the "MIME type for file.tar.gz is application/x-gzip".   But when we compare the file that the browser saved to the file on the server, they are not the same. 
Then I commented out the "if (mimeType == null)" line so that the MIME type would always be set to "application/octet-stream", and the downloaded file still wasn't identical to the one on the server. 
Any idea why the downloaded file isn't exactly the same as the file on the server? 
EDIT: This is really strange.   I tested a text file, a PDF file, a ZIP file (created in Windows), a JPG file, and they all download exact copies.   Just this file.tar.gz doesn't get downloaded exactly for some reason (on the server it's 882,273 bytes, and the downloaded copy is 881,968 bytes). 
EDIT 2: When I use curl to download the file.tar.gz, it gets saved as an exact copy, so that tells me there's nothing wrong with the servlet code.   Chrome is modifying the file before it saves it for some reason.   Could Chrome be detecting that the file is a gzipped file and thinks that the server compressed the response (when it really didn't), so it tries to uncompress it?   Then again the file that Chrome saves is smaller than the file on the server...

A:

This problem occurred due to a bug in Chrome, as described here:
https://code.google.com/p/chromium/issues/detail?id=268085
Our web server was configured to use HTTP gzip compression for everything sent back to the browser, so due to the Chrome bug, it ended up saving the file with another layer of gzip compression.