|
|
@ -132,7 +132,7 @@ class TextFile(private val book: Book) { |
|
|
|
if (StringUtils.trim(chapterContent).isNotEmpty()) { |
|
|
|
if (StringUtils.trim(chapterContent).isNotEmpty()) { |
|
|
|
val qyChapter = BookChapter() |
|
|
|
val qyChapter = BookChapter() |
|
|
|
qyChapter.title = "前言" |
|
|
|
qyChapter.title = "前言" |
|
|
|
qyChapter.start = 0 |
|
|
|
qyChapter.start = curOffset |
|
|
|
qyChapter.end = chapterLength.toLong() |
|
|
|
qyChapter.end = chapterLength.toLong() |
|
|
|
toc.add(qyChapter) |
|
|
|
toc.add(qyChapter) |
|
|
|
} |
|
|
|
} |
|
|
@ -167,7 +167,7 @@ class TextFile(private val book: Book) { |
|
|
|
} else { //如果章节不存在则创建章节 |
|
|
|
} else { //如果章节不存在则创建章节 |
|
|
|
val curChapter = BookChapter() |
|
|
|
val curChapter = BookChapter() |
|
|
|
curChapter.title = matcher.group() |
|
|
|
curChapter.title = matcher.group() |
|
|
|
curChapter.start = 0 |
|
|
|
curChapter.start = curOffset |
|
|
|
curChapter.end = 0 |
|
|
|
curChapter.end = 0 |
|
|
|
toc.add(curChapter) |
|
|
|
toc.add(curChapter) |
|
|
|
} |
|
|
|
} |
|
|
@ -182,10 +182,8 @@ class TextFile(private val book: Book) { |
|
|
|
|
|
|
|
|
|
|
|
//block的偏移点 |
|
|
|
//block的偏移点 |
|
|
|
curOffset += length.toLong() |
|
|
|
curOffset += length.toLong() |
|
|
|
|
|
|
|
|
|
|
|
//设置上一章的结尾 |
|
|
|
//设置上一章的结尾 |
|
|
|
val lastChapter = toc.last() |
|
|
|
toc.lastOrNull()?.end = curOffset |
|
|
|
lastChapter.end = curOffset |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
toc.forEachIndexed { index, bookChapter -> |
|
|
|
toc.forEachIndexed { index, bookChapter -> |
|
|
@ -209,10 +207,10 @@ class TextFile(private val book: Book) { |
|
|
|
} |
|
|
|
} |
|
|
|
val toc = arrayListOf<BookChapter>() |
|
|
|
val toc = arrayListOf<BookChapter>() |
|
|
|
LocalBook.getBookInputStream(book).use { bis -> |
|
|
|
LocalBook.getBookInputStream(book).use { bis -> |
|
|
|
//加载章节 |
|
|
|
|
|
|
|
var curOffset: Long = 0 |
|
|
|
|
|
|
|
//block的个数 |
|
|
|
//block的个数 |
|
|
|
var blockPos = 0 |
|
|
|
var blockPos = 0 |
|
|
|
|
|
|
|
//加载章节 |
|
|
|
|
|
|
|
var curOffset: Long = 0 |
|
|
|
//读取的长度 |
|
|
|
//读取的长度 |
|
|
|
var length: Int |
|
|
|
var length: Int |
|
|
|
val buffer = ByteArray(bufferSize) |
|
|
|
val buffer = ByteArray(bufferSize) |
|
|
@ -226,7 +224,6 @@ class TextFile(private val book: Book) { |
|
|
|
while (bis.read(buffer, bufferStart, bufferSize - bufferStart) |
|
|
|
while (bis.read(buffer, bufferStart, bufferSize - bufferStart) |
|
|
|
.also { length = it } > 0 |
|
|
|
.also { length = it } > 0 |
|
|
|
) { |
|
|
|
) { |
|
|
|
bufferStart = 0 |
|
|
|
|
|
|
|
blockPos++ |
|
|
|
blockPos++ |
|
|
|
//章节在buffer的偏移量 |
|
|
|
//章节在buffer的偏移量 |
|
|
|
var chapterOffset = 0 |
|
|
|
var chapterOffset = 0 |
|
|
@ -256,18 +253,15 @@ class TextFile(private val book: Book) { |
|
|
|
//设置偏移的位置 |
|
|
|
//设置偏移的位置 |
|
|
|
chapterOffset = end |
|
|
|
chapterOffset = end |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
val chapter = BookChapter() |
|
|
|
buffer.copyInto(buffer, 0, length - strLength, strLength) |
|
|
|
chapter.title = "第" + blockPos + "章" + "(" + chapterPos + ")" |
|
|
|
bufferStart = strLength |
|
|
|
chapter.start = curOffset + chapterOffset |
|
|
|
|
|
|
|
chapter.end = curOffset + length |
|
|
|
|
|
|
|
toc.add(chapter) |
|
|
|
|
|
|
|
strLength = 0 |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//block的偏移点 |
|
|
|
//block的偏移点 |
|
|
|
curOffset += length.toLong() |
|
|
|
curOffset += length.toLong() |
|
|
|
|
|
|
|
//设置上一章的结尾 |
|
|
|
|
|
|
|
toc.lastOrNull()?.end = curOffset |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
toc.forEachIndexed { index, bookChapter -> |
|
|
|
toc.forEachIndexed { index, bookChapter -> |
|
|
|