Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,16 @@

/**
* A simple bitmap loader that delegates all tasks to an executor and supports fetching images from
* HTTP/HTTPS endpoints.
* {@code file} and {@code http}/{@code https} URIs.
*
* <p>Loading tasks are delegated to an {@link ExecutorService} (or {@link
* ListeningExecutorService}) defined during construction. If no executor service is defined, all
* tasks are delegated to a single-thread executor service that is shared between instances of this
* class.
*
* <p>The supported URI scheme is only HTTP/HTTPS and this class reads a resource only when the
* endpoint responds with an {@code HTTP 200} after sending the HTTP request.
* <p>The supported URIs schemes are {@code file} and {@code http}/{@code https}.
* For HTTP(S) transfers, this class reads a resource only when the endpoint responds
* with an {@code HTTP 200} after sending the HTTP request.
*/
@UnstableApi
public final class SimpleBitmapLoader implements BitmapLoader {
Expand Down Expand Up @@ -89,6 +90,9 @@ private static Bitmap decode(byte[] data) {
}

private static Bitmap load(Uri uri) throws IOException {
if (uri.getScheme().equals("file")) {
return BitmapFactory.decodeFile(uri.getPath());
}
URLConnection connection = new URL(uri.toString()).openConnection();
if (!(connection instanceof HttpURLConnection)) {
throw new UnsupportedOperationException("Unsupported scheme: " + uri.getScheme());
Expand Down