if (o instanceof TextBody){
/*
* A text body. Display its contents.
*/
TextBody body = (TextBody) o;
StringBuilder sb = new StringBuilder();
try {
Reader r = body.getReader();
int c;
while ((c = r.read()) != -1) {
sb.append((char) c);
}
} catch (IOException ex) {
ex.printStackTrace();
}
textView.setText(sb.toString());
} else if (o instanceof BinaryBody){
/*
* A binary body. Display its MIME type and length in bytes.
*/
BinaryBody body = (BinaryBody) o;
int size = 0;
try {
InputStream is = body.getInputStream();
while ((is.read()) != -1) {
size++;
}
} catch (IOException ex) {
ex.printStackTrace();
}
textView.setText("Binary body\n"
+ "MIME type: "
+ body.getParent().getMimeType() + "\n"
+ "Size of decoded data: " + size + " bytes");
} else if (o instanceof ContentTypeField) {
/*
* Content-Type field.