@Nullable @Override public ImageItem handle(@NonNull String raw, @NonNull Uri uri) { ImageItem item = null; try { final byte[] bytes = raw.substring(SCHEME.length()).getBytes("UTF-8"); item = new ImageItem( CONTENT_TYPE, new ByteArrayInputStream(bytes), null ); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return item; }
@Nullable @Override public ImageItem handle(@NonNull String raw, @NonNull Uri uri) { ImageItem out = null; final Request request = new Request.Builder() .url(raw) .tag(raw) .build(); Response response = null; try { response = client.newCall(request).execute(); } catch (IOException e) { e.printStackTrace(); } if (response != null) { final ResponseBody body = response.body(); if (body != null) { final InputStream inputStream = body.byteStream(); if (inputStream != null) { final String contentType = response.header(HEADER_CONTENT_TYPE); out = new ImageItem(contentType, inputStream, null); } } } return out; }
@Nullable @Override public ImageItem handle(@NonNull String raw, @NonNull Uri uri) { if (!raw.startsWith(START)) { return null; } String part = raw.substring(START.length()); // this part is added to support `data://` with which this functionality was released if (part.startsWith("//")) { part = part.substring(2); } final DataUri dataUri = uriParser.parse(part); if (dataUri == null) { return null; } final byte[] bytes = uriDecoder.decode(dataUri); if (bytes == null) { return null; } return new ImageItem( dataUri.contentType(), new ByteArrayInputStream(bytes), null ); }
out = new ImageItem(fileName, inputStream, fileName); } else { out = null;