Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set IO Buffer size in ImageLoaderConfiguration #249

Closed
spacemase opened this issue Apr 15, 2013 · 2 comments
Closed

Set IO Buffer size in ImageLoaderConfiguration #249

spacemase opened this issue Apr 15, 2013 · 2 comments
Labels

Comments

@spacemase
Copy link

UIL appears to use an IO Buffer size of 8k, data seems to indicate 32k would be better performance: http://stackoverflow.com/questions/10143731/android-optimal-buffer-size

Would prefer to have an option to set in ImageLoaderConfiguration.

@nostra13
Copy link
Owner

Noted.

nostra13 added a commit that referenced this issue Jun 27, 2013
@nostra13
Copy link
Owner

You can use your own value of buffer size by extending BaseImageDownloader:

public class MyImageDownloader extends BaseImageDownloader {

    private static final int MY_BUFFER_SIZE = 128 * 1024; // this is your value

    public MyImageDownloader(Context context) {
        super(context);
    }

    public MyImageDownloader(Context context, int connectTimeout, int readTimeout) {
        super(context, connectTimeout, readTimeout);
    }

    protected InputStream getStreamFromNetwork(String imageUri, Object extra) throws IOException {
        HttpURLConnection conn = createConnection(imageUri);

        int redirectCount = 0;
        while (conn.getResponseCode() / 100 == 3 && redirectCount < MAX_REDIRECT_COUNT) {
            conn = createConnection(conn.getHeaderField("Location"));
            redirectCount++;
        }

        return new BufferedInputStream(conn.getInputStream(), MY_BUFFER_SIZE);
    }

    protected InputStream getStreamFromFile(String imageUri, Object extra) throws IOException {
        String filePath = Scheme.FILE.crop(imageUri);
        return new BufferedInputStream(new FileInputStream(filePath), MY_BUFFER_SIZE);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants