Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from gedoor:master #204

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/src/main/java/io/legado/app/help/http/CookieManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,11 @@ object CookieManager {
}

fun applyToWebView(url: String) {
val baseUrl = NetworkUtils.getBaseUrl(url) ?: return
val cookies = CookieStore.getCookie(url).splitNotBlank(";")
val cookieManager = CookieManager.getInstance()
cookies.forEach {
cookieManager.setCookie(url, it)
cookieManager.setCookie(baseUrl, it)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,13 @@ public byte readByte() throws IOException {
}

public byte[] readBytes(int len) throws IOException {
if (len < 1) {
if (len < 0) {
System.out.println(len);
throw new IllegalArgumentException("Length must > 0: " + len);
}
if (len==0){
return null;
}
byte[] b = new byte[len];
is.read(b);
incCount(len);
Expand Down
64 changes: 19 additions & 45 deletions modules/book/src/main/java/me/ag2s/umdlib/tool/UmdUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Random;
import java.util.zip.InflaterInputStream;
import java.util.zip.Inflater;
import java.nio.charset.StandardCharsets;


public class UmdUtils {
Expand All @@ -30,23 +30,7 @@ public static byte[] stringToUnicodeBytes(String s) {
throw new NullPointerException();
}

int len = s.length();
byte[] ret = new byte[len * 2];
int a, b, c;
for (int i = 0; i < len; i++) {
c = s.charAt(i);
a = c >> 8;
b = c & 0xFF;
if (a < 0) {
a += 0xFF;
}
if (b < 0) {
b += 0xFF;
}
ret[i * 2] = (byte) b;
ret[i * 2 + 1] = (byte) a;
}
return ret;
return s.getBytes(StandardCharsets.UTF_16LE);
}

/**
Expand All @@ -56,21 +40,11 @@ public static byte[] stringToUnicodeBytes(String s) {
* @return 原始字符串
*/
public static String unicodeBytesToString(byte[] bytes) {
char[] s = new char[bytes.length / 2];
StringBuilder sb = new StringBuilder();
int a, b, c;
for (int i = 0; i < s.length; i++) {
a = bytes[i * 2 + 1];
b = bytes[i * 2];
c = (a & 0xff) << 8 | (b & 0xff);
if (c < 0) {
c += 0xffff;
}
char[] c1 = Character.toChars(c);
sb.append(c1);

//修复一些文件属性空值的问题
if (bytes==null){
return "";
}
return sb.toString();
return new String(bytes, StandardCharsets.UTF_16LE);
}

/**
Expand Down Expand Up @@ -101,19 +75,19 @@ public static String toHex(byte[] bArr) {
* @throws Exception 解码时失败时
*/
public static byte[] decompress(byte[] compress) throws Exception {
ByteArrayInputStream bais = new ByteArrayInputStream(compress);
InflaterInputStream iis = new InflaterInputStream(bais);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int c = 0;
byte[] buf = new byte[BUFFER_SIZE];
while (true) {
c = iis.read(buf);

if (c == EOF)
break;
baos.write(buf, 0, c);
Inflater inflater = new Inflater();
inflater.reset();
inflater.setInput(compress);

ByteArrayOutputStream baos = new ByteArrayOutputStream(compress.length);
try (baos) {
byte[] buff = new byte[BUFFER_SIZE];
while (!inflater.finished()) {
int count = inflater.inflate(buff);
baos.write(buff, 0, count);
}
}
baos.flush();
inflater.end();
return baos.toByteArray();
}

Expand Down
Loading