Created
August 22, 2011 06:10
-
-
Save mryoshio/1161769 to your computer and use it in GitHub Desktop.
get image and process into byte[]
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
private byte[] requestImage(String path) throws ServerConnectionException { | |
BufferedInputStream inStream = null; | |
try { | |
HttpResponse response = client.execute(buildGetRequest( | |
HttpGet.METHOD_NAME, path, new HashMap())); | |
HttpEntity entity = response.getEntity(); | |
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); | |
if (entity == null) { | |
return new byte[0]; | |
} else { | |
inStream = new BufferedInputStream(entity.getContent()); | |
byte[] bytes = new byte[1024]; | |
int b = 0; | |
while ((b = inStream.read(bytes)) != -1) { | |
outputStream.write(bytes); | |
} | |
outputStream.flush(); | |
outputStream.close(); | |
return outputStream.toByteArray(); | |
} | |
} catch (Exception e) { | |
throw new ServerConnectionException(e); | |
} finally { | |
if (inStream != null) | |
try { | |
inStream.close(); | |
} catch (IOException e) { | |
throw new ServerConnectionException(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment