|
|
@ -20,8 +20,7 @@ class TextFile(private val book: Book) { |
|
|
|
|
|
|
|
|
|
|
|
@Throws(FileNotFoundException::class) |
|
|
|
@Throws(FileNotFoundException::class) |
|
|
|
fun getChapterList(): ArrayList<BookChapter> { |
|
|
|
fun getChapterList(): ArrayList<BookChapter> { |
|
|
|
var rulePattern: Pattern? = null |
|
|
|
val rulePattern: Pattern? = if (book.charset == null || book.tocUrl.isEmpty()) { |
|
|
|
if (book.charset == null || book.tocUrl.isEmpty()) { |
|
|
|
|
|
|
|
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 |
|
|
@ -29,19 +28,19 @@ class TextFile(private val book: Book) { |
|
|
|
book.charset = EncodingDetect.getEncode(buffer) |
|
|
|
book.charset = EncodingDetect.getEncode(buffer) |
|
|
|
charset = book.fileCharset() |
|
|
|
charset = book.fileCharset() |
|
|
|
blockContent = String(buffer, 0, length, charset) |
|
|
|
blockContent = String(buffer, 0, length, charset) |
|
|
|
rulePattern = if (book.tocUrl.isNotEmpty()) { |
|
|
|
if (book.tocUrl.isNotEmpty()) { |
|
|
|
Pattern.compile(book.tocUrl, Pattern.MULTILINE) |
|
|
|
book.tocUrl.toPattern(Pattern.MULTILINE) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (blockContent.isEmpty()) { |
|
|
|
if (blockContent.isEmpty()) { |
|
|
|
length = bis.read(buffer) |
|
|
|
length = bis.read(buffer) |
|
|
|
book.charset = EncodingDetect.getEncode(buffer) |
|
|
|
book.charset = EncodingDetect.getEncode(buffer) |
|
|
|
blockContent = String(buffer, 0, length, charset) |
|
|
|
blockContent = String(buffer, 0, length, charset) |
|
|
|
} |
|
|
|
} |
|
|
|
getTocRule(blockContent)?.let { |
|
|
|
getTocRule(blockContent)?.rule?.toPattern(Pattern.MULTILINE) |
|
|
|
Pattern.compile(it.rule, Pattern.MULTILINE) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
book.tocUrl.toPattern(Pattern.MULTILINE) |
|
|
|
} |
|
|
|
} |
|
|
|
return analyze(rulePattern) |
|
|
|
return analyze(rulePattern) |
|
|
|
} |
|
|
|
} |
|
|
|