Merge pull request #2692 from ag2s20150909/master

修复中文AndroidZipFile不能读取非ASCII字符文件名
This commit is contained in:
kunfei
2023-01-09 16:54:01 +08:00
committed by GitHub
4 changed files with 35 additions and 11 deletions
@@ -8,6 +8,10 @@
*/
package io.legado.app.lib.icu4j;
import android.os.ParcelFileDescriptor;
import android.system.OsConstants;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.io.IOException;
@@ -88,13 +92,25 @@ public class CharsetDetector {
* @return This CharsetDetector
* @stable ICU 3.4
*/
public CharsetDetector setText(byte[] in) {
public CharsetDetector setText(@NonNull byte[] in) {
fRawInput = in;
fRawLength = in.length;
return this;
}
public CharsetDetector setText(@NonNull ParcelFileDescriptor pfd) {
fRawInput = new byte[kBufSize];
try {
android.system.Os.lseek(pfd.getFileDescriptor(), 0, OsConstants.SEEK_SET);
fRawLength = android.system.Os.read(pfd.getFileDescriptor(), fRawInput, 0, fRawInput.length);
android.system.Os.lseek(pfd.getFileDescriptor(), 0, OsConstants.SEEK_SET);
} catch (Exception e) {
throw new RuntimeException(e);
}
return this;
}
private static final int kBufSize = 8000;
/**
@@ -111,7 +127,7 @@ public class CharsetDetector {
* @stable ICU 3.4
*/
public CharsetDetector setText(InputStream in) throws IOException {
public CharsetDetector setText(@NonNull InputStream in) throws IOException {
fInputStream = in;
fInputStream.mark(kBufSize);
fRawInput = new byte[kBufSize]; // Always make a new buffer because the