Created
July 10, 2012 16:28
-
-
Save anonymous/3084469 to your computer and use it in GitHub Desktop.
Patch File containing the diff for RemoteImageLoaderJob.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/original.txt b/change.txt | |
index 733993c..d63617c 100644 | |
--- a/original.txt | |
+++ b/change.txt | |
@@ -25,14 +25,16 @@ public class RemoteImageLoaderJob implements Runnable { | |
private RemoteImageLoaderHandler handler; | |
private ImageCache imageCache; | |
private int numRetries, defaultBufferSize; | |
+ private boolean disableCompression; | |
public RemoteImageLoaderJob(String imageUrl, RemoteImageLoaderHandler handler, ImageCache imageCache, | |
- int numRetries, int defaultBufferSize) { | |
+ int numRetries, int defaultBufferSize, boolean disableCompression) { | |
this.imageUrl = imageUrl; | |
this.handler = handler; | |
this.imageCache = imageCache; | |
this.numRetries = numRetries; | |
this.defaultBufferSize = defaultBufferSize; | |
+ this.disableCompression = disableCompression; | |
} | |
/** | |
@@ -96,10 +98,19 @@ public class RemoteImageLoaderJob implements Runnable { | |
BufferedInputStream istream = new BufferedInputStream(connection.getInputStream()); | |
try { | |
- if (fileSize <= 0) { | |
- Log.w(LOG_TAG, | |
- "Server did not set a Content-Length header, will default to buffer size of " | |
- + defaultBufferSize + " bytes"); | |
+ if (this.disableCompression && fileSize > 0) { | |
+ // Disable Gzip Compression | |
+ connection.setRequestProperty("Accept-Encoding", "identity"); | |
+ fileSize = connection.getContentLength(); | |
+ byte[] imageData = new byte[fileSize]; | |
+ int bytesRead = 0; | |
+ int offset = 0; | |
+ while (bytesRead != -1 && offset < fileSize) { | |
+ bytesRead = istream.read(imageData, offset, fileSize - offset); | |
+ offset += bytesRead; | |
+ } | |
+ return imageData; | |
+ } else { | |
ByteArrayOutputStream buf = new ByteArrayOutputStream(defaultBufferSize); | |
byte[] buffer = new byte[defaultBufferSize]; | |
int bytesRead = 0; | |
@@ -109,16 +120,6 @@ public class RemoteImageLoaderJob implements Runnable { | |
buf.write(buffer, 0, bytesRead); | |
} | |
return buf.toByteArray(); | |
- } else { | |
- byte[] imageData = new byte[fileSize]; | |
- | |
- int bytesRead = 0; | |
- int offset = 0; | |
- while (bytesRead != -1 && offset < fileSize) { | |
- bytesRead = istream.read(imageData, offset, fileSize - offset); | |
- offset += bytesRead; | |
- } | |
- return imageData; | |
} | |
} finally { | |
// clean up |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment