Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected byte[] retrieveImageData() throws IOException {
- URL url = new URL(imageUrl);
- //HttpURLConnection connection = (HttpURLConnection) url.openConnection();
- HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
- // determine the image size and allocate a buffer
- int fileSize = connection.getContentLength();
- if (fileSize < 0) {
- return null;
- }
- byte[] imageData = new byte[fileSize];
- // download the file
- Log.d(LOG_TAG, "fetching image " + imageUrl + " (" + fileSize + ")");
- BufferedInputStream istream = new BufferedInputStream(connection.getInputStream());
- int bytesRead = 0;
- int offset = 0;
- while (bytesRead != -1 && offset < fileSize) {
- bytesRead = istream.read(imageData, offset, fileSize - offset);
- offset += bytesRead;
- }
- // clean up
- istream.close();
- connection.disconnect();
- return imageData;
- }
Add Comment
Please, Sign In to add comment