🐛 don't close source after processing partial request without cache #43

prevent invalid calling source.close() in different threads to avoid crashes on Lollipop (#37, #29, #63, #66)
This commit is contained in:
Alexey Danilov
2016-07-29 14:09:11 +03:00
parent 582832f8b5
commit 6c996ea66c
5 changed files with 121 additions and 27 deletions

View File

@@ -83,18 +83,18 @@ class HttpProxyCache extends ProxyCache {
}
private void responseWithoutCache(OutputStream out, long offset) throws ProxyCacheException, IOException {
HttpUrlSource newSourceNoCache = new HttpUrlSource(this.source);
try {
HttpUrlSource source = new HttpUrlSource(this.source);
source.open((int) offset);
newSourceNoCache.open((int) offset);
byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
int readBytes;
while ((readBytes = source.read(buffer)) != -1) {
while ((readBytes = newSourceNoCache.read(buffer)) != -1) {
out.write(buffer, 0, readBytes);
offset += readBytes;
}
out.flush();
} finally {
source.close();
newSourceNoCache.close();
}
}