<commit_before>package com.platform.middlewares;

import android.app.Activity;
import android.util.Log;

import com.breadwallet.BreadApp;
import com.platform.APIClient;
import com.platform.BRHTTPHelper;
import com.platform.HTTPServer;
import com.platform.interfaces.Middleware;

import junit.framework.Assert;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * BreadWallet
 * <p/>
 * Created by <NAME> on <<EMAIL>> 10/19/16.
 * Copyright (c) 2016 breadwallet LLC
 * <p/>
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * <p/>
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * <p/>
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
public class HTTPIndexMiddleware implements Middleware {
    public static final String TAG = HTTPIndexMiddleware.class.getName();

    @Override
    public boolean handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) {
        Log.i(TAG, "handling: " + target + " " + baseRequest.getMethod());
        Activity app = BreadApp.getBreadContext();
        if (app == null) {
            Log.e(TAG, "handle: app is null!");
            return true;
        }

        String indexFile = APIClient.getInstance(app).getExtractedPath(app, "/index.html");

        File temp = new File(indexFile);
        if (!temp.exists()) {
            Log.e(TAG, "handle: FILE DOES NOT EXIST: " + temp.getAbsolutePath());
            return false;
        }

        try {
            byte[] body = FileUtils.readFileToByteArray(temp);
            Assert.assertNotNull(body);
            Assert.assertNotSame(body.length, 0);
            response.setHeader("Content-Length", String.valueOf(body.length));
            return BRHTTPHelper.handleSuccess(200, body, baseRequest, response, "text/html;charset=utf-8");
        } catch (IOException e) {
            e.printStackTrace();
            Log.d(TAG, "handle: error sending response: " + target + " " + baseRequest.getMethod());
            return BRHTTPHelper.handleError(500, null, baseRequest, response);
        }

    }
}<commit_msg>fixed the support center<commit_after>package com.platform.middlewares;

import android.app.Activity;
import android.util.Log;

import com.breadwallet.BreadApp;
import com.platform.APIClient;
import com.platform.BRHTTPHelper;
import com.platform.HTTPServer;
import com.platform.interfaces.Middleware;

import junit.framework.Assert;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * BreadWallet
 * <p/>
 * Created by <NAME> on <<EMAIL>> 10/19/16.
 * Copyright (c) 2016 breadwallet LLC
 * <p/>
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * <p/>
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * <p/>
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
public class HTTPIndexMiddleware implements Middleware {
    public static final String TAG = HTTPIndexMiddleware.class.getName();

    @Override
    public boolean handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) {
        Log.i(TAG, "handling: " + target + " " + baseRequest.getMethod());
        Activity app = BreadApp.getBreadContext();
        if (app == null) {
            Log.e(TAG, "handle: app is null!");
            return true;
        }

        String indexFile = APIClient.getInstance(app).getExtractedPath(app, rTrim(target, "/") + "/index.html");
        Log.e(TAG, "handle: indexFile: " + indexFile);

        File temp = new File(indexFile);
        if (!temp.exists()) {
            Log.e(TAG, "handle: FILE DOES NOT EXIST: " + temp.getAbsolutePath());
            return false;
        }

        try {
            byte[] body = FileUtils.readFileToByteArray(temp);
            Assert.assertNotNull(body);
            Assert.assertNotSame(body.length, 0);
            response.setHeader("Content-Length", String.valueOf(body.length));
            return BRHTTPHelper.handleSuccess(200, body, baseRequest, response, "text/html;charset=utf-8");
        } catch (IOException e) {
            e.printStackTrace();
            Log.d(TAG, "handle: error sending response: " + target + " " + baseRequest.getMethod());
            return BRHTTPHelper.handleError(500, null, baseRequest, response);
        }

    }

    public String rTrim(String str, String piece) {
        if (str.endsWith(piece)) {
            return str.substring(str.lastIndexOf(piece), str.length());
        }
        return str;
    }
}
{'fraction_non_alphanumeric': 0.09937604626388677, 'fraction_numerical': 0.0054786181707502666, 'mean_word_length': 3.3436880370125577, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '5629179', 'n_tokens_mistral': 1792, 'n_tokens_neox': 1751, 'n_words': 611}