Calling a web service to obtain an byte[] in Android
I've writing a application on Android which calls a .Net restful wcf web service I've written. I'm successfully obtaining XML and String results, but cannot call a method on the web service which returns a byte[] - it looks like its encoding is alerted.
I am using the org.apache.http.HttpHost library and an currently reading the byte[] as a string (the encoding in eclipse looks like unicode);
InputStream in = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder str = new StringBuilder();
String line = null;
while((line = reader.readLine()) != null){
str.append(line);
}
in.close();
String asciiString = str.toString();
Basically I want to convert the data held in asciiString to a Bitmap (the WCF serv开发者_开发技巧ice outputs a byte[] of a PNG image)
If anyone can offer pointers as what I am doing wrong or how to do this (if it is possible) it would be most welcome.
Many thanks
I believe you should use a ByteArrayOutputStream
. I don't have an IDE installed here, but here's how I think it should go: open a ByteArrayOutputStream
, to which you write byte by byte (or better, buffering in some way, of course) what you read from your InputStream in
. To obtain your byte[]
use the method toByteArray()
.
精彩评论