Skip to content

Instantly share code, notes, and snippets.

@Gowiem
Created June 18, 2012 14:19
Show Gist options
  • Save Gowiem/2948608 to your computer and use it in GitHub Desktop.
Save Gowiem/2948608 to your computer and use it in GitHub Desktop.
Reading byte data from a url.
HttpClient client = new DefaultHttpClient();
HttpURLConnection.setFollowRedirects(false);
HttpURLConnection connection = (HttpURLConnection) new URL(serverDirectoryUrl).openConnection();
connection.setIfModifiedSince(ifModifiedBeforeDate.getTime());
int byteArraySize = connection.getContentLength();
Log.d(TAG, "Byte Array Size: " + byteArraySize);
byte[] response = new byte[byteArraySize];
InputStream connectionInputStream = connection.getInputStream();
int bytesRead = connectionInputStream.read(response);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment