/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.common.mime.ContentTypeHeader
 *  com.l7tech.util.HexUtils
 *  com.l7tech.util.IOUtils
 *  jakarta.servlet.ServletConfig
 *  jakarta.servlet.ServletContext
 *  jakarta.servlet.ServletException
 *  jakarta.servlet.http.HttpServlet
 *  jakarta.servlet.http.HttpServletRequest
 *  jakarta.servlet.http.HttpServletResponse
 *  org.apache.commons.collections.map.LRUMap
 *  org.springframework.web.context.WebApplicationContext
 *  org.springframework.web.context.support.WebApplicationContextUtils
 */
package com.l7tech.server;

import com.l7tech.common.mime.ContentTypeHeader;
import com.l7tech.server.b3;
import com.l7tech.server.z;
import com.l7tech.util.HexUtils;
import com.l7tech.util.IOUtils;
import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.security.SecureRandom;
import java.util.Timer;
import java.util.TimerTask;
import org.apache.commons.collections.map.LRUMap;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

public class FileDownloadServlet
extends HttpServlet {
    private final int INITIAL_TASK_DELAY = 30000;
    private final int NORMAL_TASK_DELAY = 90000;
    private final int FILE_EXPIRY_PERIOD = 60000;
    private static final SecureRandom random;
    private final LRUMap fileMap = new LRUMap(10);
    private WebApplicationContext applicationContext;
    private Timer timer;
    static final long serialVersionUID = 2383879360811632234L;
    private static final String[] a;

    public void init(ServletConfig servletConfig) throws ServletException {
        try {
            super.init(servletConfig);
            this.applicationContext = WebApplicationContextUtils.getWebApplicationContext((ServletContext)this.getServletContext());
            if (this.applicationContext == null) {
                throw new ServletException(a[4]);
            }
        }
        catch (ServletException servletException) {
            throw FileDownloadServlet.a(servletException);
        }
        this.timer = (Timer)this.applicationContext.getBean(a[3], Timer.class);
        this.timer.schedule((TimerTask)new b3(this), 30000L, 90000L);
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    public void doPost(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException {
        String string = httpServletRequest.getParameter(a[5]);
        byte[] byArray = IOUtils.slurpStream((InputStream)httpServletRequest.getInputStream(), (int)100000);
        byte[] byArray2 = new byte[20];
        random.nextBytes(byArray2);
        String string2 = HexUtils.hexDump((byte[])byArray2);
        LRUMap lRUMap = this.fileMap;
        synchronized (lRUMap) {
            this.fileMap.put((Object)string2, (Object)new z(byArray, string));
        }
        httpServletResponse.setContentType(ContentTypeHeader.TEXT_DEFAULT.getFullValue());
        httpServletResponse.getWriter().write(string2);
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException {
        z z2;
        String[] stringArray = a;
        String string = httpServletRequest.getParameter(stringArray[6]);
        LRUMap lRUMap = this.fileMap;
        synchronized (lRUMap) {
            z2 = (z)this.fileMap.get((Object)string);
        }
        try {
            if (z2 == null) {
                httpServletResponse.sendError(404, a[0]);
                return;
            }
        }
        catch (ServletException servletException) {
            throw FileDownloadServlet.a(servletException);
        }
        httpServletResponse.reset();
        stringArray = a;
        httpServletResponse.addHeader(stringArray[2], stringArray[1] + z2.b + "\"");
        httpServletResponse.setContentType(stringArray[7]);
        lRUMap = httpServletResponse.getOutputStream();
        lRUMap.write(z2.a);
        lRUMap.flush();
        lRUMap.close();
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    private void removeExpiredFiles() {
        LRUMap lRUMap = this.fileMap;
        synchronized (lRUMap) {
            if (this.fileMap.isEmpty()) {
                return;
            }
            Object object = this.fileMap.firstKey();
            while (object != null) {
                z z2 = (z)this.fileMap.get(object);
                long l2 = z2.a();
                long l3 = System.currentTimeMillis();
                if (l3 - l2 >= 60000L) {
                    this.fileMap.remove(object);
                }
                if (this.fileMap.isEmpty()) {
                    return;
                }
                object = this.fileMap.nextKey(object);
            }
        }
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[8];
                var3_1 = 0;
                var2_2 = "bm%<a\r\u0010D\"7u~\u001dSIz8of\u000b]\u0016Mv%}q\u0010\u001eIl%'2\u001e\u001a@g?}\u007f\u001dN\u000e\u0013om?hw\u0016\u0007\u0001F8ob\u0017\u0000Ev8s|\u0016Ac?}u\u001d\u0017nc2wu\n\u001cYl5H{\u0015\u0016^6om?z{\u001f\u0006^c%u}\u0016SIp#s`CSOm$pvX\u001dCvq{w\fSMr!p{\u001b\u0012Xk>r2\u001b\u001cBv4df\bJk=y|\u0019\u001eI";
                var4_3 = "bm%<a\r\u0010D\"7u~\u001dSIz8of\u000b]\u0016Mv%}q\u0010\u001eIl%'2\u001e\u001a@g?}\u007f\u001dN\u000e\u0013om?hw\u0016\u0007\u0001F8ob\u0017\u0000Ev8s|\u0016Ac?}u\u001d\u0017nc2wu\n\u001cYl5H{\u0015\u0016^6om?z{\u001f\u0006^c%u}\u0016SIp#s`CSOm$pvX\u001dCvq{w\fSMr!p{\u001b\u0012Xk>r2\u001b\u001cBv4df\bJk=y|\u0019\u001eI".length();
                var1_4 = 21;
                var0_5 = -1;
lbl7:
                // 2 sources

                while (true) {
                    v0 = 125;
                    v1 = ++var0_5;
                    v2 = var2_2.substring(v1, v1 + var1_4);
                    v3 = -1;
                    break block9;
                    break;
                }
lbl13:
                // 1 sources

                while (true) {
                    var5[var3_1++] = FileDownloadServlet.a(v0, FileDownloadServlet.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "tT\u001b\u0018~A\u0012CH(!kX\rA\u000e$#kT\u0016\u0002R?2zP\u000f";
                    var4_3 = "tT\u001b\u0018~A\u0012CH(!kX\rA\u000e$#kT\u0016\u0002R?2zP\u000f".length();
                    var1_4 = 3;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 78;
                        v4 = ++var0_5;
                        v2 = var2_2.substring(v4, v4 + var1_4);
                        v3 = 0;
                        break block9;
                        break;
                    }
                    break;
                }
lbl28:
                // 1 sources

                while (true) {
                    var5[var3_1++] = FileDownloadServlet.a(v0, FileDownloadServlet.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    break block10;
                    break;
                }
            }
            switch (v3) {
                default: {
                    ** continue;
                }
                ** case 0:
lbl39:
                // 1 sources

                ** continue;
            }
        }
        FileDownloadServlet.a = var5;
        FileDownloadServlet.random = new SecureRandom();
    }

    private static ServletException a(ServletException servletException) {
        return servletException;
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0xE);
        }
        return cArray;
    }

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String a(int n2, char[] cArray) {
        char[] cArray2;
        block11: {
            int n3;
            int n4;
            int n5;
            block10: {
                n5 = n2;
                cArray2 = cArray;
                n4 = cArray.length;
                n3 = 0;
                if (!true) break block10;
                n4 = n4;
                if (n4 <= n3) break block11;
            }
            do {
                n5 = n5;
                cArray2 = cArray2;
                int n6 = n3;
                cArray2[n6] = (char)(cArray2[n6] ^ (n5 ^ (switch (n3 % 7) {
                    case 0 -> 81;
                    case 1 -> 127;
                    case 2 -> 44;
                    case 3 -> 97;
                    case 4 -> 111;
                    case 5 -> 5;
                    default -> 14;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

