MD5 校验值:47dc1c492bf2859d50823a0fe72087d7
c.java 文件包含反编译后的源代码,请注意,该内容仅供学习和参考使用,不得用于非法用途。
package d.a.a; import android.support.v4.app.NotificationCompat; import android.support.v4.media.session.PlaybackStateCompat; import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.Closeable; import java.io.DataOutput; import java.io.DataOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.FilterOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.RandomAccessFile; import java.io.UnsupportedEncodingException; import java.io.Writer; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.ServerSocket; import java.net.Socket; import java.net.SocketException; import java.net.SocketTimeoutException; import java.net.URL; import java.net.URLDecoder; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.nio.charset.Charset; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Properties; import java.util.StringTokenizer; import java.util.TimeZone; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.zip.GZIPOutputStream; public abstract class c { public static final Pattern f4312a = Pattern.compile("[ |\t]*(charset)[ |\t]*=[ |\t]*['|\"]?([^\"^'^;]*)['|\"]?", 2); public static final Pattern f4313b = Pattern.compile("[ |\t]*(boundary)[ |\t]*=[ |\t]*['|\"]?([^\"^'^;]*)['|\"]?", 2); public static final Pattern f4314c = Pattern.compile("([ |\t]*Content-Disposition[ |\t]*:)(.*)", 2); public static final Pattern f4315d = Pattern.compile("([ |\t]*content-type[ |\t]*:)(.*)", 2); public static final Pattern f4316e = Pattern.compile("[ |\t]*([a-zA-Z]*)[ |\t]*=[ |\t]*['|\"]([^\"^']*)['|\"]"); public static final Logger f4317f = Logger.getLogger(c.class.getName()); public static Map<String, String> f4318g; public final String f4319h; public final int i; public volatile ServerSocket j; public Thread l; public p k = new f(); public s n = new i(this, null); public a m = new e(); public interface a { } public class b implements Runnable { public final InputStream f4320a; public final Socket f4321b; public b(InputStream inputStream, Socket socket, d.a.a.b bVar) { this.f4320a = inputStream; this.f4321b = socket; } @Override public void run() { a aVar; OutputStream outputStream = null; try { try { outputStream = this.f4321b.getOutputStream(); j jVar = new j(((i) c.this.n).a(), this.f4320a, outputStream, this.f4321b.getInetAddress()); while (!this.f4321b.isClosed()) { jVar.a(); } c.b(outputStream); c.b(this.f4320a); c.b(this.f4321b); aVar = c.this.m; } catch (Exception e2) { if ((!(e2 instanceof SocketException) || !"NanoHttpd Shutdown".equals(e2.getMessage())) && !(e2 instanceof SocketTimeoutException)) { c.f4317f.log(Level.FINE, "Communication with the client broken", (Throwable) e2); } c.b(outputStream); c.b(this.f4320a); c.b(this.f4321b); aVar = c.this.m; } ((e) aVar).f4329b.remove(this); } catch (Throwable th) { c.b(outputStream); c.b(this.f4320a); c.b(this.f4321b); ((e) c.this.m).f4329b.remove(this); throw th; } } } public static class C0020c { public final String f4323a; public final String f4324b; public final String f4325c; public String a() { return String.format("%s=%s; expires=%s", this.f4323a, this.f4324b, this.f4325c); } } public class d implements Iterable<String> { public final HashMap<String, String> f4326a = new HashMap<>(); public final ArrayList<C0020c> f4327b = new ArrayList<>(); public d(c cVar, Map<String, String> map) { String str = map.get("cookie"); if (str != null) { for (String str2 : str.split(";")) { String[] split = str2.trim().split("="); if (split.length == 2) { this.f4326a.put(split[0], split[1]); } } } } public void a(m mVar) { Iterator<C0020c> it = this.f4327b.iterator(); while (it.hasNext()) { mVar.f4354e.put("Set-Cookie", it.next().a()); } } @Override public Iterator<String> iterator() { return this.f4326a.keySet().iterator(); } } public static class f implements p { public ServerSocket a() throws IOException { return new ServerSocket(); } } public static class g implements q { public final File f4330a; public final OutputStream f4331b; public g(File file) throws IOException { this.f4330a = File.createTempFile("NanoHTTPD-", "", file); this.f4331b = new FileOutputStream(this.f4330a); } public String a() { return this.f4330a.getAbsolutePath(); } } private class i implements s { public i(c cVar, d.a.a.b bVar) { } public r a() { return new h(); } } public interface k { } public enum l { GET, PUT, POST, DELETE, HEAD, OPTIONS, TRACE, CONNECT, PATCH; public static l a(String str) { for (l lVar : values()) { if (lVar.toString().equalsIgnoreCase(str)) { return lVar; } } return null; } } public static class m implements Closeable { public b f4350a; public String f4351b; public InputStream f4352c; public long f4353d; public final Map<String, String> f4354e = new HashMap(); public l f4355f; public boolean f4356g; public boolean f4357h; public boolean i; public interface b { } public enum EnumC0021c implements b { SWITCH_PROTOCOL(101, "Switching Protocols"), OK(200, "OK"), CREATED(201, "Created"), ACCEPTED(202, "Accepted"), NO_CONTENT(204, "No Content"), PARTIAL_CONTENT(206, "Partial Content"), REDIRECT(301, "Moved Permanently"), TEMPORARY_REDIRECT(302, "Moved Temporarily"), NOT_MODIFIED(304, "Not Modified"), BAD_REQUEST(400, "Bad Request"), UNAUTHORIZED(401, "Unauthorized"), FORBIDDEN(403, "Forbidden"), NOT_FOUND(404, "Not Found"), METHOD_NOT_ALLOWED(405, "Method Not Allowed"), NOT_ACCEPTABLE(406, "Not Acceptable"), REQUEST_TIMEOUT(408, "Request Timeout"), CONFLICT(409, "Conflict"), RANGE_NOT_SATISFIABLE(416, "Requested Range Not Satisfiable"), INTERNAL_ERROR(500, "Internal Server Error"), NOT_IMPLEMENTED(501, "Not Implemented"), UNSUPPORTED_HTTP_VERSION(505, "HTTP Version Not Supported"); public final int w; public final String x; EnumC0021c(int i, String str) { this.w = i; this.x = str; } public String a() { StringBuilder b2 = c.c.b.a.a.b(""); b2.append(this.w); b2.append(" "); b2.append(this.x); return b2.toString(); } } public m(b bVar, String str, InputStream inputStream, long j) { this.f4350a = bVar; this.f4351b = str; if (inputStream == null) { this.f4352c = new ByteArrayInputStream(new byte[0]); this.f4353d = 0L; } else { this.f4352c = inputStream; this.f4353d = j; } this.f4356g = this.f4353d < 0; this.i = true; } public String a(String str) { for (String str2 : this.f4354e.keySet()) { if (str2.equalsIgnoreCase(str)) { return this.f4354e.get(str2); } } return null; } public void b(boolean z) { this.i = z; } @Override public void close() throws IOException { InputStream inputStream = this.f4352c; if (inputStream != null) { inputStream.close(); } } public static class a extends FilterOutputStream { public a(OutputStream outputStream) { super(outputStream); } public void a() throws IOException { ((FilterOutputStream) this).out.write("0\r\n\r\n".getBytes()); } @Override public void write(int i) throws IOException { write(new byte[]{(byte) i}, 0, 1); } @Override public void write(byte[] bArr) throws IOException { write(bArr, 0, bArr.length); } @Override public void write(byte[] bArr, int i, int i2) throws IOException { if (i2 == 0) { return; } ((FilterOutputStream) this).out.write(String.format("%x\r\n", Integer.valueOf(i2)).getBytes()); ((FilterOutputStream) this).out.write(bArr, i, i2); ((FilterOutputStream) this).out.write("\r\n".getBytes()); } } public final void b(OutputStream outputStream, long j) throws IOException { if (this.f4357h) { GZIPOutputStream gZIPOutputStream = new GZIPOutputStream(outputStream); a(gZIPOutputStream, -1L); gZIPOutputStream.finish(); return; } a(outputStream, j); } public void a(boolean z) { this.f4357h = z; } public static boolean a(Map<String, String> map, String str) { Iterator<String> it = map.keySet().iterator(); boolean z = false; while (it.hasNext()) { z |= it.next().equalsIgnoreCase(str); } return z; } public void a(OutputStream outputStream) { String str = this.f4351b; SimpleDateFormat simpleDateFormat = new SimpleDateFormat("E, d MMM yyyy HH:mm:ss 'GMT'", Locale.US); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); try { if (this.f4350a != null) { PrintWriter printWriter = new PrintWriter((Writer) new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8")), false); StringBuilder sb = new StringBuilder(); sb.append("HTTP/1.1 "); sb.append(((EnumC0021c) this.f4350a).a()); sb.append(" \r\n"); printWriter.print(sb.toString()); if (str != null) { printWriter.print("Content-Type: " + str + "\r\n"); } if (this.f4354e == null || this.f4354e.get("Date") == null) { printWriter.print("Date: " + simpleDateFormat.format(new Date()) + "\r\n"); } if (this.f4354e != null) { for (String str2 : this.f4354e.keySet()) { printWriter.print(str2 + ": " + this.f4354e.get(str2) + "\r\n"); } } if (!a(this.f4354e, "connection")) { StringBuilder sb2 = new StringBuilder(); sb2.append("Connection: "); sb2.append(this.i ? "keep-alive" : "close"); sb2.append("\r\n"); printWriter.print(sb2.toString()); } if (a(this.f4354e, "content-length")) { this.f4357h = false; } if (this.f4357h) { printWriter.print("Content-Encoding: gzip\r\n"); this.f4356g = true; } long j = this.f4352c != null ? this.f4353d : 0L; if (this.f4355f != l.HEAD && this.f4356g) { printWriter.print("Transfer-Encoding: chunked\r\n"); } else if (!this.f4357h) { j = a(printWriter, this.f4354e, j); } printWriter.print("\r\n"); printWriter.flush(); if (this.f4355f != l.HEAD && this.f4356g) { a aVar = new a(outputStream); b(aVar, -1L); aVar.a(); } else { b(outputStream, j); } outputStream.flush(); c.b(this.f4352c); return; } throw new Error("sendResponse(): Status can't be null."); } catch (IOException e2) { c.f4317f.log(Level.SEVERE, "Could not send response to the client", (Throwable) e2); } } public final void a(OutputStream outputStream, long j) throws IOException { byte[] bArr = new byte[(int) PlaybackStateCompat.ACTION_PREPARE]; boolean z = j == -1; while (true) { if (j <= 0 && !z) { return; } int read = this.f4352c.read(bArr, 0, (int) (z ? 16384L : Math.min(j, PlaybackStateCompat.ACTION_PREPARE))); if (read <= 0) { return; } outputStream.write(bArr, 0, read); if (!z) { j -= read; } } } public static long a(PrintWriter printWriter, Map<String, String> map, long j) { for (String str : map.keySet()) { if (str.equalsIgnoreCase("content-length")) { try { return Long.parseLong(map.get(str)); } catch (NumberFormatException unused) { return j; } } } printWriter.print("Content-Length: " + j + "\r\n"); return j; } public void a(l lVar) { this.f4355f = lVar; } } public class o implements Runnable { public final int f4367a; public IOException f4368b; public boolean f4369c = false; public o(int i, d.a.a.b bVar) { this.f4367a = i; } @Override public void run() { try { c.this.j.bind(c.this.f4319h != null ? new InetSocketAddress(c.this.f4319h, c.this.i) : new InetSocketAddress(c.this.i)); this.f4369c = true; do { try { Socket accept = c.this.j.accept(); if (this.f4367a > 0) { accept.setSoTimeout(this.f4367a); } ((e) c.this.m).a(c.this.a(accept, accept.getInputStream())); } catch (IOException e2) { c.f4317f.log(Level.FINE, "Communication with the client broken", (Throwable) e2); } } while (!c.this.j.isClosed()); } catch (IOException e3) { this.f4368b = e3; } } } public interface p { } public interface q { } public interface r { } public interface s { } public c(String str, int i2) { this.f4319h = str; this.i = i2; } public static final class n extends Exception { public final m.EnumC0021c f4366a; public n(m.EnumC0021c enumC0021c, String str) { super(str); this.f4366a = enumC0021c; } public m.EnumC0021c a() { return this.f4366a; } public n(m.EnumC0021c enumC0021c, String str, Exception exc) { super(str, exc); this.f4366a = enumC0021c; } } public static String b(String str) { String str2; int lastIndexOf = str.lastIndexOf(46); if (lastIndexOf >= 0) { if (f4318g == null) { f4318g = new HashMap(); a(f4318g, "META-INF/nanohttpd/default-mimetypes.properties"); a(f4318g, "META-INF/nanohttpd/mimetypes.properties"); if (f4318g.isEmpty()) { f4317f.log(Level.WARNING, "no mime types found in the classpath! please provide mimetypes.properties"); } } str2 = f4318g.get(str.substring(lastIndexOf + 1).toLowerCase()); } else { str2 = null; } return str2 == null ? "application/octet-stream" : str2; } public boolean a(m mVar) { return mVar.f4351b != null && mVar.f4351b.toLowerCase().contains("text/"); } public static class e implements a { public long f4328a; public final List<b> f4329b = Collections.synchronizedList(new ArrayList()); public void a() { Iterator it = new ArrayList(this.f4329b).iterator(); while (it.hasNext()) { b bVar = (b) it.next(); c.b(bVar.f4320a); c.b(bVar.f4321b); } } public void a(b bVar) { this.f4328a++; Thread thread = new Thread(bVar); thread.setDaemon(true); StringBuilder b2 = c.c.b.a.a.b("NanoHttpd Request Processor (#"); b2.append(this.f4328a); b2.append(")"); thread.setName(b2.toString()); this.f4329b.add(bVar); thread.start(); } } public static void a(Map<String, String> map, String str) { try { Enumeration<URL> resources = c.class.getClassLoader().getResources(str); while (resources.hasMoreElements()) { URL nextElement = resources.nextElement(); Properties properties = new Properties(); InputStream inputStream = null; try { try { inputStream = nextElement.openStream(); properties.load(nextElement.openStream()); } catch (IOException e2) { f4317f.log(Level.SEVERE, "could not load mimetypes from " + nextElement, (Throwable) e2); } b(inputStream); map.putAll(properties); } catch (Throwable th) { b(inputStream); throw th; } } } catch (IOException unused) { f4317f.log(Level.INFO, "no mime types available at " + str); } } public static class h implements r { public final File f4332a = new File(System.getProperty("java.io.tmpdir")); public final List<q> f4333b; public h() { if (!this.f4332a.exists()) { this.f4332a.mkdirs(); } this.f4333b = new ArrayList(); } public void a() { g gVar; Iterator<q> it = this.f4333b.iterator(); while (it.hasNext()) { try { gVar = (g) it.next(); c.b(gVar.f4331b); } catch (Exception e2) { c.f4317f.log(Level.WARNING, "could not delete file ", (Throwable) e2); } if (!gVar.f4330a.delete()) { throw new Exception("could not delete temporary file"); break; } } this.f4333b.clear(); } public q a(String str) throws Exception { g gVar = new g(this.f4332a); this.f4333b.add(gVar); return gVar; } } public static final void b(Object obj) { if (obj != null) { try { if (obj instanceof Closeable) { ((Closeable) obj).close(); } else if (obj instanceof Socket) { ((Socket) obj).close(); } else { if (obj instanceof ServerSocket) { ((ServerSocket) obj).close(); return; } throw new IllegalArgumentException("Unknown object to close"); } } catch (IOException e2) { f4317f.log(Level.SEVERE, "Could not close", (Throwable) e2); } } } public b a(Socket socket, InputStream inputStream) { return new b(inputStream, socket, null); } public static String a(String str) { try { return URLDecoder.decode(str, "UTF8"); } catch (UnsupportedEncodingException e2) { f4317f.log(Level.WARNING, "Encoding not supported, ignored", (Throwable) e2); return null; } } public void a() throws IOException { this.j = ((f) this.k).a(); this.j.setReuseAddress(true); o oVar = new o(5000, null); this.l = new Thread(oVar); this.l.setDaemon(true); this.l.setName("NanoHttpd Main Listener"); this.l.start(); while (!oVar.f4369c && oVar.f4368b == null) { try { Thread.sleep(10L); } catch (Throwable unused) { } } if (oVar.f4368b != null) { throw oVar.f4368b; } } public void b() { try { b(this.j); ((e) this.m).a(); if (this.l != null) { this.l.join(); } } catch (Exception e2) { f4317f.log(Level.SEVERE, "Could not stop all connections", (Throwable) e2); } } public class j implements k { public final r f4334a; public final OutputStream f4335b; public final BufferedInputStream f4336c; public int f4337d; public int f4338e; public String f4339f; public l f4340g; public Map<String, String> f4341h; public Map<String, String> i; public d j; public String k; public String l; public String m; public j(r rVar, InputStream inputStream, OutputStream outputStream, InetAddress inetAddress) { this.f4334a = rVar; this.f4336c = new BufferedInputStream(inputStream, 8192); this.f4335b = outputStream; this.l = (inetAddress.isLoopbackAddress() || inetAddress.isAnyLocalAddress()) ? "127.0.0.1" : inetAddress.getHostAddress().toString(); this.i = new HashMap(); } public final void a(BufferedReader bufferedReader, Map<String, String> map, Map<String, String> map2, Map<String, String> map3) throws n { String a2; try { String readLine = bufferedReader.readLine(); if (readLine == null) { return; } StringTokenizer stringTokenizer = new StringTokenizer(readLine); if (stringTokenizer.hasMoreTokens()) { map.put("method", stringTokenizer.nextToken()); if (stringTokenizer.hasMoreTokens()) { String nextToken = stringTokenizer.nextToken(); int indexOf = nextToken.indexOf(63); if (indexOf >= 0) { a(nextToken.substring(indexOf + 1), map2); a2 = c.a(nextToken.substring(0, indexOf)); } else { a2 = c.a(nextToken); } if (stringTokenizer.hasMoreTokens()) { this.m = stringTokenizer.nextToken(); } else { this.m = "HTTP/1.1"; c.f4317f.log(Level.FINE, "no protocol version specified, strange. Assuming HTTP/1.1."); } String readLine2 = bufferedReader.readLine(); while (readLine2 != null && readLine2.trim().length() > 0) { int indexOf2 = readLine2.indexOf(58); if (indexOf2 >= 0) { map3.put(readLine2.substring(0, indexOf2).trim().toLowerCase(Locale.US), readLine2.substring(indexOf2 + 1).trim()); } readLine2 = bufferedReader.readLine(); } map.put(NotificationCompat.MessagingStyle.Message.KEY_DATA_URI, a2); return; } throw new n(m.EnumC0021c.BAD_REQUEST, "BAD REQUEST: Missing URI. Usage: GET /example/file.html"); } throw new n(m.EnumC0021c.BAD_REQUEST, "BAD REQUEST: Syntax error. Usage: GET /example/file.html"); } catch (IOException e2) { m.EnumC0021c enumC0021c = m.EnumC0021c.INTERNAL_ERROR; StringBuilder b2 = c.c.b.a.a.b("SERVER INTERNAL ERROR: IOException: "); b2.append(e2.getMessage()); throw new n(enumC0021c, b2.toString(), e2); } } public final void a(String str, String str2, ByteBuffer byteBuffer, Map<String, String> map, Map<String, String> map2) throws n { try { int[] a2 = a(byteBuffer, str.getBytes()); int i = 2; if (a2.length >= 2) { int i2 = 1024; byte[] bArr = new byte[1024]; int i3 = 0; int i4 = 0; while (i4 < a2.length - 1) { byteBuffer.position(a2[i4]); int remaining = byteBuffer.remaining() < i2 ? byteBuffer.remaining() : 1024; byteBuffer.get(bArr, i3, remaining); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(bArr, i3, remaining), Charset.forName(str2)), remaining); if (bufferedReader.readLine().contains(str)) { String readLine = bufferedReader.readLine(); String str3 = null; String str4 = null; String str5 = null; int i5 = 2; while (readLine != null && readLine.trim().length() > 0) { Matcher matcher = c.f4314c.matcher(readLine); if (matcher.matches()) { Matcher matcher2 = c.f4316e.matcher(matcher.group(i)); while (matcher2.find()) { String str6 = str3; String group = matcher2.group(1); if (group.equalsIgnoreCase("name")) { str4 = matcher2.group(2); } else if (group.equalsIgnoreCase("filename")) { str3 = matcher2.group(2); } str3 = str6; } } Matcher matcher3 = c.f4315d.matcher(readLine); if (matcher3.matches()) { str5 = matcher3.group(2).trim(); } readLine = bufferedReader.readLine(); i5++; i = 2; } int i6 = 0; while (true) { int i7 = i5 - 1; if (i5 <= 0) { break; } while (bArr[i6] != 10) { i6++; } i6++; i5 = i7; } if (i6 < remaining - 4) { int i8 = a2[i4] + i6; i4++; int i9 = a2[i4] - 4; byteBuffer.position(i8); if (str5 == null) { byte[] bArr2 = new byte[i9 - i8]; byteBuffer.get(bArr2); map.put(str4, new String(bArr2, str2)); } else { String a3 = a(byteBuffer, i8, i9 - i8, str3); if (!map2.containsKey(str4)) { map2.put(str4, a3); } else { int i10 = 2; while (true) { if (!map2.containsKey(str4 + i10)) { break; } else { i10++; } } map2.put(str4 + i10, a3); } map.put(str4, str3); } i2 = 1024; i = 2; i3 = 0; } else { throw new n(m.EnumC0021c.INTERNAL_ERROR, "Multipart header size exceeds MAX_HEADER_SIZE."); } } else { throw new n(m.EnumC0021c.BAD_REQUEST, "BAD REQUEST: Content type is multipart/form-data but chunk does not start with boundary."); } } return; } throw new n(m.EnumC0021c.BAD_REQUEST, "BAD REQUEST: Content type is multipart/form-data but contains less than two boundary strings."); } catch (n e2) { throw e2; } catch (Exception e3) { throw new n(m.EnumC0021c.INTERNAL_ERROR, e3.toString()); } } public final void a(String str, Map<String, String> map) { if (str == null) { this.k = ""; return; } this.k = str; StringTokenizer stringTokenizer = new StringTokenizer(str, "&"); while (stringTokenizer.hasMoreTokens()) { String nextToken = stringTokenizer.nextToken(); int indexOf = nextToken.indexOf(61); if (indexOf >= 0) { map.put(c.a(nextToken.substring(0, indexOf)).trim(), c.a(nextToken.substring(indexOf + 1))); } else { map.put(c.a(nextToken).trim(), ""); } } } public void a() throws IOException { byte[] bArr; boolean z; int read; m mVar = null; try { try { try { try { bArr = new byte[8192]; z = false; this.f4337d = 0; this.f4338e = 0; this.f4336c.mark(8192); try { read = this.f4336c.read(bArr, 0, 8192); } catch (Exception unused) { c.b(this.f4336c); c.b(this.f4335b); throw new SocketException("NanoHttpd Shutdown"); } } catch (IOException e2) { c.a(m.EnumC0021c.INTERNAL_ERROR, "text/plain", "SERVER INTERNAL ERROR: IOException: " + e2.getMessage()).a(this.f4335b); c.b(this.f4335b); } } catch (n e3) { c.a(e3.a(), "text/plain", e3.getMessage()).a(this.f4335b); c.b(this.f4335b); } if (read == -1) { c.b(this.f4336c); c.b(this.f4335b); throw new SocketException("NanoHttpd Shutdown"); } while (read > 0) { this.f4338e += read; this.f4337d = a(bArr, this.f4338e); if (this.f4337d > 0) { break; } else { read = this.f4336c.read(bArr, this.f4338e, 8192 - this.f4338e); } } if (this.f4337d < this.f4338e) { this.f4336c.reset(); this.f4336c.skip(this.f4337d); } this.f4341h = new HashMap(); if (this.i == null) { this.i = new HashMap(); } else { this.i.clear(); } BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(bArr, 0, this.f4338e))); HashMap hashMap = new HashMap(); a(bufferedReader, hashMap, this.f4341h, this.i); if (this.l != null) { this.i.put("remote-addr", this.l); this.i.put("http-client-ip", this.l); } this.f4340g = l.a(hashMap.get("method")); if (this.f4340g != null) { this.f4339f = hashMap.get(NotificationCompat.MessagingStyle.Message.KEY_DATA_URI); this.j = new d(c.this, this.i); String str = this.i.get("connection"); boolean z2 = this.m.equals("HTTP/1.1") && (str == null || !str.matches("(?i).*close.*")); mVar = c.this.a((k) this); if (mVar != null) { String str2 = this.i.get("accept-encoding"); this.j.a(mVar); mVar.a(this.f4340g); if (c.this.a(mVar) && str2 != null && str2.contains("gzip")) { z = true; } mVar.a(z); mVar.b(z2); mVar.a(this.f4335b); if (!z2 || "close".equalsIgnoreCase(mVar.a("connection"))) { throw new SocketException("NanoHttpd Shutdown"); } return; } throw new n(m.EnumC0021c.INTERNAL_ERROR, "SERVER INTERNAL ERROR: Serve() returned a null response."); } throw new n(m.EnumC0021c.BAD_REQUEST, "BAD REQUEST: Syntax error."); } catch (SocketException e4) { throw e4; } catch (SocketTimeoutException e5) { throw e5; } } finally { c.b((Object) null); ((h) this.f4334a).a(); } } public final int a(byte[] bArr, int i) { int i2; int i3 = 0; while (true) { int i4 = i3 + 1; if (i4 >= i) { return 0; } if (bArr[i3] == 13 && bArr[i4] == 10 && (i2 = i3 + 3) < i && bArr[i3 + 2] == 13 && bArr[i2] == 10) { return i3 + 4; } if (bArr[i3] == 10 && bArr[i4] == 10) { return i3 + 2; } i3 = i4; } } public final int[] a(ByteBuffer byteBuffer, byte[] bArr) { int[] iArr = new int[0]; if (byteBuffer.remaining() < bArr.length) { return iArr; } byte[] bArr2 = new byte[bArr.length + 4096]; int remaining = byteBuffer.remaining() < bArr2.length ? byteBuffer.remaining() : bArr2.length; byteBuffer.get(bArr2, 0, remaining); int length = remaining - bArr.length; int[] iArr2 = iArr; int i = 0; while (true) { int[] iArr3 = iArr2; int i2 = 0; while (i2 < length) { int[] iArr4 = iArr3; for (int i3 = 0; i3 < bArr.length && bArr2[i2 + i3] == bArr[i3]; i3++) { if (i3 == bArr.length - 1) { int[] iArr5 = new int[iArr4.length + 1]; System.arraycopy(iArr4, 0, iArr5, 0, iArr4.length); iArr5[iArr4.length] = i + i2; iArr4 = iArr5; } } i2++; iArr3 = iArr4; } i += length; System.arraycopy(bArr2, bArr2.length - bArr.length, bArr2, 0, bArr.length); length = bArr2.length - bArr.length; if (byteBuffer.remaining() < length) { length = byteBuffer.remaining(); } byteBuffer.get(bArr2, bArr.length, length); if (length <= 0) { return iArr3; } iArr2 = iArr3; } } public void a(Map<String, String> map) throws IOException, n { long j; ByteArrayOutputStream byteArrayOutputStream; DataOutput dataOutput; RandomAccessFile randomAccessFile; ByteBuffer map2; StringTokenizer stringTokenizer; try { if (this.i.containsKey("content-length")) { j = Long.parseLong(this.i.get("content-length")); } else { j = this.f4337d < this.f4338e ? r3 - r2 : 0L; } if (j < PlaybackStateCompat.ACTION_PLAY_FROM_MEDIA_ID) { byteArrayOutputStream = new ByteArrayOutputStream(); dataOutput = new DataOutputStream(byteArrayOutputStream); randomAccessFile = 0; } else { try { DataOutput randomAccessFile2 = new RandomAccessFile(((g) ((h) this.f4334a).a(null)).a(), "rw"); byteArrayOutputStream = null; dataOutput = randomAccessFile2; randomAccessFile = randomAccessFile2; } catch (Exception e2) { throw new Error(e2); } } } catch (Throwable th) { th = th; c.b((Object) r1); throw th; } try { byte[] bArr = new byte[512]; while (this.f4338e >= 0 && j > 0) { this.f4338e = this.f4336c.read(bArr, 0, (int) Math.min(j, 512L)); j -= this.f4338e; if (this.f4338e > 0) { dataOutput.write(bArr, 0, this.f4338e); } } if (byteArrayOutputStream != null) { map2 = ByteBuffer.wrap(byteArrayOutputStream.toByteArray(), 0, byteArrayOutputStream.size()); } else { map2 = randomAccessFile.getChannel().map(FileChannel.MapMode.READ_ONLY, 0L, randomAccessFile.length()); randomAccessFile.seek(0L); } ByteBuffer byteBuffer = map2; if (l.POST.equals(this.f4340g)) { String str = ""; String str2 = this.i.get("content-type"); if (str2 != null) { stringTokenizer = new StringTokenizer(str2, ",; "); if (stringTokenizer.hasMoreTokens()) { str = stringTokenizer.nextToken(); } } else { stringTokenizer = null; } if ("multipart/form-data".equalsIgnoreCase(str)) { if (stringTokenizer.hasMoreTokens()) { Matcher matcher = c.f4313b.matcher(str2); String group = matcher.find() ? matcher.group(2) : null; Matcher matcher2 = c.f4312a.matcher(str2); a(group, matcher2.find() ? matcher2.group(2) : "US-ASCII", byteBuffer, this.f4341h, map); } else { throw new n(m.EnumC0021c.BAD_REQUEST, "BAD REQUEST: Content type is multipart/form-data but boundary missing. Usage: GET /example/file.html"); } } else { byte[] bArr2 = new byte[byteBuffer.remaining()]; byteBuffer.get(bArr2); String trim = new String(bArr2).trim(); if ("application/x-www-form-urlencoded".equalsIgnoreCase(str)) { a(trim, this.f4341h); } else if (trim.length() != 0) { map.put("postData", trim); } } } else if (l.PUT.equals(this.f4340g)) { map.put("content", a(byteBuffer, 0, byteBuffer.limit(), (String) null)); } c.b(randomAccessFile); } catch (Throwable th2) { th = th2; r1 = randomAccessFile; c.b((Object) r1); throw th; } } public final String a(ByteBuffer byteBuffer, int i, int i2, String str) { ByteBuffer duplicate; FileOutputStream fileOutputStream; g gVar; if (i2 <= 0) { return ""; } FileOutputStream fileOutputStream2 = null; try { try { q a2 = ((h) this.f4334a).a(str); duplicate = byteBuffer.duplicate(); gVar = (g) a2; fileOutputStream = new FileOutputStream(gVar.a()); } catch (Exception e2) { e = e2; } } catch (Throwable th) { th = th; } try { FileChannel channel = fileOutputStream.getChannel(); duplicate.position(i).limit(i + i2); channel.write(duplicate.slice()); String a3 = gVar.a(); c.b(fileOutputStream); return a3; } catch (Exception e3) { e = e3; fileOutputStream2 = fileOutputStream; throw new Error(e); } catch (Throwable th2) { th = th2; fileOutputStream2 = fileOutputStream; c.b(fileOutputStream2); throw th; } } } public static m a(m.b bVar, String str, InputStream inputStream, long j2) { return new m(bVar, str, inputStream, j2); } public static m a(m.b bVar, String str, String str2) { byte[] bArr; if (str2 == null) { return a(bVar, str, new ByteArrayInputStream(new byte[0]), 0L); } try { bArr = str2.getBytes("UTF-8"); } catch (UnsupportedEncodingException e2) { f4317f.log(Level.SEVERE, "encoding problem, responding nothing", (Throwable) e2); bArr = new byte[0]; } return a(bVar, str, new ByteArrayInputStream(bArr), bArr.length); } public m a(k kVar) { HashMap hashMap = new HashMap(); j jVar = (j) kVar; l lVar = jVar.f4340g; if (l.PUT.equals(lVar) || l.POST.equals(lVar)) { try { jVar.a(hashMap); } catch (n e2) { return a(e2.f4366a, "text/plain", e2.getMessage()); } catch (IOException e3) { m.EnumC0021c enumC0021c = m.EnumC0021c.INTERNAL_ERROR; StringBuilder b2 = c.c.b.a.a.b("SERVER INTERNAL ERROR: IOException: "); b2.append(e3.getMessage()); return a(enumC0021c, "text/plain", b2.toString()); } } jVar.f4341h.put("NanoHttpd.QUERY_STRING", jVar.k); String str = jVar.f4339f; Map<String, String> map = jVar.i; return a(m.EnumC0021c.NOT_FOUND, "text/plain", "Not Found"); } }