My app distributes files and collects statistics.
Some time ago I noticed if user try download file from android - server received two requests instead one. First request failed due to Caused by: java.net.SocketException: Connection reset by peer: socket write error
Second request was processed correctly and user received file on phone. So it's more or less ok but in such case my statistics are incorrect. I saw similiar issue on [the other thread][1]
[1]: https://stackoverflow.com/a/8579181/273418 but there is no any solution
Code of servlet that distributes files
try {
StringBuilder typeHeader = new StringBuilder("application/vnd.android.package-archive");
String contentType = FdConstants.CONTENT_TYPE_HEADER.getValue();
response.setHeader(contentType, typeHeader.toString());
StringBuilder dispositionHeader = new StringBuilder("attachment; filename=\"");
dispositionHeader.append(fileName.toUpperCase());
dispositionHeader.append("\"");
String contentDisposition = FdConstants.CONTENT_DISPOSITION_HEADER.getValue();
response.setHeader(contentDisposition, dispositionHeader.toString());
response.setContentLength(fileStream.available());
// copy it to response's OutputStream
IOUtils.copy(fileStream, response.getOutputStream());
response.flushBuffer();
} finally {
IOUtils.closeQuietly(fileStream);
}