Copyright (c) 2011, 2012, Digital Lizard (Oscar Key, Thomas Boby)
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the...
If you think the Android project BBC-News-Reader listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*******************************************************************************
* BBC News Reader/*www.java2s.com*/
* Released under the BSD License. See README or LICENSE.
* Copyright (c) 2011, Digital Lizard (Oscar Key, Thomas Boby)
* All rights reserved.
******************************************************************************/package com.digitallizard.bbcnewsreader.resource.web;
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import org.apache.http.util.ByteArrayBuffer;
publicclass ImageDownloader {
publicstaticbyte[] getImage(URL url) throws Exception {
URLConnection connection = url.openConnection();
InputStream stream = connection.getInputStream();
BufferedInputStream inputbuffer = new BufferedInputStream(stream, 8000);
ByteArrayBuffer arraybuffer = new ByteArrayBuffer(50);
int current = 0;
while ((current = inputbuffer.read()) != -1) {
arraybuffer.append((byte) current);
}
byte[] image = arraybuffer.toByteArray();
return image;
}
}