<commit_before>package org.sunger.lib.http.client;

import android.os.Build;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public final class HttpResponse {
    private final int statusCode;
    private final Map<String, List<String>> headers;
    private InputStream payload;
    private int contentLength;
    private String fileName;
    private String result;

    HttpResponse(final int statusCode, int contentLength, String fileName,
                 final InputStream payload,
                 final Map<String, List<String>> rawHeaders) {
        this.statusCode = statusCode;
        this.payload = payload;
        this.fileName = fileName;
        this.contentLength = contentLength;
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
            final Map<String, List<String>> newHeaders = new HashMap<String, List<String>>(
                    rawHeaders.size());
            for (final Map.Entry<String, List<String>> e : rawHeaders
                    .entrySet()) {
                final String key = e.getKey();
                final int keyLen = key.length();
                final StringBuilder newKey = new StringBuilder(keyLen);
                for (int i = 0; i < keyLen; ++i) {
                    final char c = key.charAt(i);
                    final char c2;
                    if (i == 0 || key.charAt(i - 1) == '-') {
                        c2 = Character.toUpperCase(c);
                    } else {
                        c2 = c;
                    }
                    newKey.append(c2);
                }
                newHeaders.put(newKey.toString(), e.getValue());
            }
            this.headers = Collections.unmodifiableMap(newHeaders);
        } else {
            this.headers = Collections.unmodifiableMap(rawHeaders);
        }
        this.result = readToText();
    }
    private String readToText() {
        StringBuilder buffer = new StringBuilder();
        try {
            String enc = getContentCharset();
            if (enc == null) {
                enc = "UTF-8";
            }
            InputStream input = getPayload();
            InputStreamReader reader = new InputStreamReader(input, enc);
            final char[] inBuf = new char[64];
            for (int charsRead; (charsRead = reader.read(inBuf)) != -1; ) {
                buffer.append(inBuf, 0, charsRead);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return buffer.toString();

    }

    public String getContentType() {
        final String contentType = getFirstHeaderValue("Content-Type");
        if (contentType == null) {
            return null;
        }

        final int i = contentType.indexOf(';');
        return i == -1 ? contentType : contentType.substring(0, i).trim();
    }

    public String getContentCharset() {
        final String contentType = getFirstHeaderValue("Content-Type");
        if (contentType == null) {
            return null;
        }
        final int i = contentType.indexOf('=');
        return i == -1 ? null : contentType.substring(i + 1).trim();
    }

    public InputStream getPayload() {
        return payload;
    }

    void preload(File temp) throws IOException {
        @SuppressWarnings("resource")
        final FileOutputStream out = new FileOutputStream(temp);
        final byte[] inBuf = new byte[1024];
        final InputStream in = getPayload();
        for (int bytesRead = 0; (bytesRead = in.read(inBuf)) != -1; ) {
            out.write(inBuf, 0, bytesRead);
        }

        payload = new FileInputStream(temp);
    }



    public int getStatusCode() {
        return statusCode;
    }

    public Map<String, List<String>> getHeaders() {
        return headers;
    }

    public String getFirstHeaderValue(String name) {
        final List<String> values = headers.get(name);
        if (values == null || values.isEmpty()) {
            return null;<commit_msg>修复已知bug<commit_after>package org.sunger.lib.http.client;

import android.os.Build;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public final class HttpResponse {
    private final int statusCode;
    private final Map<String, List<String>> headers;
    private InputStream payload;
    private int contentLength;
    private String fileName;
    private String result;

    HttpResponse(final int statusCode, int contentLength, String fileName,
                 final InputStream payload,
                 final Map<String, List<String>> rawHeaders) {
        this.statusCode = statusCode;
        this.payload = payload;
        this.fileName = fileName;
        this.contentLength = contentLength;
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
            final Map<String, List<String>> newHeaders = new HashMap<String, List<String>>(
                    rawHeaders.size());
            for (final Map.Entry<String, List<String>> e : rawHeaders
                    .entrySet()) {
                final String key = e.getKey();
                final int keyLen = key.length();
                final StringBuilder newKey = new StringBuilder(keyLen);
                for (int i = 0; i < keyLen; ++i) {
                    final char c = key.charAt(i);
                    final char c2;
                    if (i == 0 || key.charAt(i - 1) == '-') {
                        c2 = Character.toUpperCase(c);
                    } else {
                        c2 = c;
                    }
                    newKey.append(c2);
                }
                newHeaders.put(newKey.toString(), e.getValue());
            }
            this.headers = Collections.unmodifiableMap(newHeaders);
        } else {
            this.headers = Collections.unmodifiableMap(rawHeaders);
        }
        this.result = readToText();
    }
    private String readToText() {
        StringBuilder buffer = new StringBuilder();
        try {
            String enc = getContentCharset();
            if (enc == null) {
                enc = "UTF-8";
            }
            InputStream input = getPayload();
            InputStreamReader reader = new InputStreamReader(input, enc);
            final char[] inBuf = new char[64];
            for (int charsRead; (charsRead = reader.read(inBuf)) != -1; ) {
                buffer.append(inBuf, 0, charsRead);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return buffer.toString();

    }

    public String getContentType() {
        final String contentType = getFirstHeaderValue("Content-Type");
        if (contentType == null) {
            return null;
        }

        final int i = contentType.indexOf(';');
        return i == -1 ? contentType : contentType.substring(0, i).trim();
    }

    public String getContentCharset() {
        final String contentType = getFirstHeaderValue("Content-Type");
        if (contentType == null) {
            return null;
        }
        final int i = contentType.indexOf('=');
        return i == -1 ? null : contentType.substring(i + 1).trim();
    }

    public InputStream getPayload() {
        return payload;
    }

    public int getStatusCode() {
        return statusCode;
    }

    public Map<String, List<String>> getHeaders() {
        return headers;
    }

    public String getFirstHeaderValue(String name) {
        final List<String> values = headers.get(name);
        if (values == null || values.isEmpty()) {
            return null;
{'fraction_non_alphanumeric': 0.10704693694845888, 'fraction_numerical': 0.004987850108709554, 'mean_word_length': 1.865518504946867, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 29, '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': '2276522', 'n_tokens_mistral': 2081, 'n_tokens_neox': 2016, 'n_words': 532}