mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-28 16:40:47 +00:00
Searching in browsers cache (Chrome, Firefox)
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
package com.jpexs.browsers.cache;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class ChunkedInputStream extends InputStream {
|
||||
|
||||
private InputStream is;
|
||||
private int chunkPos = 0;
|
||||
private int chunkLen = 0;
|
||||
private boolean end = false;
|
||||
private boolean first = true;
|
||||
|
||||
public ChunkedInputStream(InputStream is) {
|
||||
this.is = is;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
if (end) {
|
||||
return -1;
|
||||
}
|
||||
if (chunkPos >= chunkLen) {
|
||||
if (!first) {
|
||||
if (is.read() != '\r') {
|
||||
throw new IOException("Invalid chunk");
|
||||
}
|
||||
if (is.read() != '\n') {
|
||||
throw new IOException("Invalid chunk");
|
||||
}
|
||||
}
|
||||
String lenStr = readLine();
|
||||
try {
|
||||
chunkLen = Integer.parseInt(lenStr);
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw new IOException("Invalid chunk");
|
||||
}
|
||||
if (chunkLen == 0) {
|
||||
is.read(); // \r
|
||||
is.read(); // \n
|
||||
end = true;
|
||||
return -1;
|
||||
}
|
||||
chunkPos = 0;
|
||||
first = false;
|
||||
}
|
||||
|
||||
chunkPos++;
|
||||
return is.read();
|
||||
}
|
||||
|
||||
private String readLine() throws IOException {
|
||||
int i;
|
||||
boolean inr = false;
|
||||
String ret = "";
|
||||
while ((i = is.read()) > -1) {
|
||||
if (inr) {
|
||||
inr = false;
|
||||
if (i == '\n') {
|
||||
break;
|
||||
} else {
|
||||
ret += "\r";
|
||||
}
|
||||
}
|
||||
if (i == '\r') {
|
||||
inr = true;
|
||||
continue;
|
||||
}
|
||||
ret += (char) i;
|
||||
}
|
||||
if (inr) {
|
||||
ret += "\r";
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user