<commit_before>package com.webimageloader.loader;

import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;

import android.graphics.Bitmap;
import android.util.Log;

import com.webimageloader.ImageLoader.Logger;
import com.webimageloader.transformation.Transformation;

public class TransformingLoader implements Loader {
    private static final String TAG = "TransformingLoader";

    @Override
    public void load(LoaderRequest request, Iterator<Loader> chain, final Listener listener) {
        if (Logger.VERBOSE) Log.v(TAG, "Transforming " + request);

        final Transformation transformation = request.getTransformation();

        // Modify request
        LoaderRequest modified = request.withoutTransformation();
        chain.next().load(modified, chain, new Listener() {
            @Override
            public void onStreamLoaded(InputStream is, Metadata metadata) {
                try {
                    Bitmap b = transformation.transform(is);
                    deliverResult(b, metadata);
                } catch (IOException e) {
                    listener.onError(e);
                }
            }

            @Override
            public void onBitmapLoaded(Bitmap b, Metadata metadata) {
                b = transformation.transform(b);
                deliverResult(b, metadata);
            }

            private void deliverResult(Bitmap b, Metadata metadata) {
                if (b == null) {
                    onError(new NullPointerException("Transformer returned null"));
                } else {
                    listener.onBitmapLoaded(b, metadata);
                }
            }

            @Override
            public void onNotModified(Metadata metadata) {
                listener.onNotModified(metadata);
            }

            @Override
            public void onError(Throwable t) {
                listener.onError(t);<commit_msg>Throw IllegalStateException instead of NPE<commit_after>package com.webimageloader.loader;

import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;

import android.graphics.Bitmap;
import android.util.Log;

import com.webimageloader.ImageLoader.Logger;
import com.webimageloader.transformation.Transformation;

public class TransformingLoader implements Loader {
    private static final String TAG = "TransformingLoader";

    @Override
    public void load(LoaderRequest request, Iterator<Loader> chain, final Listener listener) {
        if (Logger.VERBOSE) Log.v(TAG, "Transforming " + request);

        final Transformation transformation = request.getTransformation();

        // Modify request
        LoaderRequest modified = request.withoutTransformation();
        chain.next().load(modified, chain, new Listener() {
            @Override
            public void onStreamLoaded(InputStream is, Metadata metadata) {
                try {
                    Bitmap b = transformation.transform(is);
                    deliverResult(b, metadata);
                } catch (IOException e) {
                    listener.onError(e);
                }
            }

            @Override
            public void onBitmapLoaded(Bitmap b, Metadata metadata) {
                b = transformation.transform(b);
                deliverResult(b, metadata);
            }

            private void deliverResult(Bitmap b, Metadata metadata) {
                if (b == null) {
                    onError(new IllegalStateException("Transformer returned null"));
                } else {
                    listener.onBitmapLoaded(b, metadata);
                }
            }

            @Override
            public void onNotModified(Metadata metadata) {
                listener.onNotModified(metadata);
            }

            @Override
            public void onError(Throwable t) {
                listener.onError(t);
{'fraction_non_alphanumeric': 0.08088614116434828, 'fraction_numerical': 0.0, 'mean_word_length': 1.975478927203065, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3021101', 'n_tokens_mistral': 940, 'n_tokens_neox': 893, 'n_words': 225}