|
|
@ -25,17 +25,17 @@ class TextFile(private val book: Book) { |
|
|
|
LocalBook.getBookInputStream(book).use { bis -> |
|
|
|
LocalBook.getBookInputStream(book).use { bis -> |
|
|
|
val buffer = ByteArray(BUFFER_SIZE) |
|
|
|
val buffer = ByteArray(BUFFER_SIZE) |
|
|
|
var blockContent: String |
|
|
|
var blockContent: String |
|
|
|
bis.read(buffer) |
|
|
|
var length = bis.read(buffer) |
|
|
|
book.charset = EncodingDetect.getEncode(buffer) |
|
|
|
book.charset = EncodingDetect.getEncode(buffer) |
|
|
|
charset = book.fileCharset() |
|
|
|
charset = book.fileCharset() |
|
|
|
blockContent = String(buffer, charset) |
|
|
|
blockContent = String(buffer, 0, length, charset) |
|
|
|
rulePattern = if (book.tocUrl.isNotEmpty()) { |
|
|
|
rulePattern = if (book.tocUrl.isNotEmpty()) { |
|
|
|
Pattern.compile(book.tocUrl, Pattern.MULTILINE) |
|
|
|
Pattern.compile(book.tocUrl, Pattern.MULTILINE) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (blockContent.isEmpty()) { |
|
|
|
if (blockContent.isEmpty()) { |
|
|
|
bis.read(buffer) |
|
|
|
length = bis.read(buffer) |
|
|
|
book.charset = EncodingDetect.getEncode(buffer) |
|
|
|
book.charset = EncodingDetect.getEncode(buffer) |
|
|
|
blockContent = String(buffer, charset) |
|
|
|
blockContent = String(buffer, 0, length, charset) |
|
|
|
} |
|
|
|
} |
|
|
|
getTocRule(blockContent)?.let { |
|
|
|
getTocRule(blockContent)?.let { |
|
|
|
Pattern.compile(it.rule, Pattern.MULTILINE) |
|
|
|
Pattern.compile(it.rule, Pattern.MULTILINE) |
|
|
|