pull/83/head
kunfei 5 years ago
parent a388f9eb9b
commit a64bf91749
  1. 1
      app/src/main/java/io/legado/app/help/http/EncodeConverter.kt
  2. 21
      app/src/main/java/io/legado/app/model/localbook/AnalyzeTxtFile.kt
  3. 18
      app/src/main/java/io/legado/app/utils/EncodingDetect.java

@ -1,5 +1,6 @@
package io.legado.app.help.http
import io.legado.app.utils.EncodingDetect
import io.legado.app.utils.UTF8BOMFighter
import okhttp3.ResponseBody
import retrofit2.Converter

@ -0,0 +1,21 @@
package io.legado.app.model.localbook
import android.content.Context
import android.net.Uri
import io.legado.app.data.entities.Book
import io.legado.app.utils.EncodingDetect
object AnalyzeTxtFile {
fun analyze(context: Context, book: Book) {
context.contentResolver.openInputStream(Uri.parse(book.bookUrl))?.use { stream ->
val rawByteArray = ByteArray(2000)
stream.read(rawByteArray)
book.charset = EncodingDetect.getJavaEncode(rawByteArray)
}
}
}

@ -1,6 +1,7 @@
package io.legado.app.help.http;
package io.legado.app.utils;
import androidx.annotation.NonNull;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
@ -119,19 +120,19 @@ public class EncodingDetect {
class BytesEncodingDetect extends Encoding {
// Frequency tables to hold the GB, Big5, and EUC-TW character
// frequencies
int GBFreq[][];
int[][] GBFreq;
int GBKFreq[][];
int[][] GBKFreq;
int Big5Freq[][];
int[][] Big5Freq;
int Big5PFreq[][];
int[][] Big5PFreq;
int EUC_TWFreq[][];
int[][] EUC_TWFreq;
int KRFreq[][];
int[][] KRFreq;
int JPFreq[][];
int[][] JPFreq;
// int UnicodeFreq[94][128];
// public static String[] nicename;
@ -170,7 +171,6 @@ class BytesEncodingDetect extends Encoding {
rawtext.length - byteoffset)) > 0) {
byteoffset += bytesread;
}
;
chinesestream.close();
guess = detectEncoding(rawtext);
} catch (Exception e) {
Loading…
Cancel
Save