- Bitmap image = BitmapFactory.decodeByteArray(img.getData(), 0,
- img.getData().length);
- if (image == null) {
- throw new IOException("Failed to convert input to image");
- }
+ InputStream stream = img.newInputStream();
+ try {
+ Bitmap image = BitmapFactory.decodeStream(stream);
+ if (image == null) {
+ String extra = "";
+ if (img.getSize() <= 1024) {
+ try {
+ extra = ", content: "
+ + new String(img.getData(), "UTF-8");
+ } catch (Exception e) {
+ extra = ", content unavailable";
+ }
+ }
+ String ssize = StringUtils.formatNumber(img.getSize());
+ throw new IOException(
+ "Failed to convert input to image, size was: " + ssize
+ + extra);
+ }