|
|
|
@ -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
|
|
|
|
|