1package com.bumptech.glide.load.data;
2
3import com.bumptech.glide.Priority;
4
5import java.io.ByteArrayInputStream;
6import java.io.InputStream;
7
8/**
9 * A simple resource fetcher to convert byte arrays into input stream. Requires an id to be passed in to identify the
10 * data in the byte array because there is no cheap/simple way to obtain a useful id from the data itself.
11 */
12public class ByteArrayFetcher implements DataFetcher<InputStream> {
13    private final byte[] bytes;
14    private final String id;
15
16    public ByteArrayFetcher(byte[] bytes, String id) {
17        this.bytes = bytes;
18        this.id = id;
19    }
20
21    @Override
22    public InputStream loadData(Priority priority) throws Exception {
23        return new ByteArrayInputStream(bytes);
24    }
25
26    @Override
27    public void cleanup() {
28        // Do nothing.
29    }
30
31    @Override
32    public String getId() {
33        return id;
34    }
35
36    @Override
37    public void cancel() {
38        // Do nothing.
39    }
40}
41