本文整理汇总了Java中nl.siegmann.epublib.epub.EpubReader类的典型用法代码示例。如果您正苦于以下问题:Java EpubReader类的具体用法?Java EpubReader怎么用?Java EpubReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EpubReader类属于nl.siegmann.epublib.epub包,在下文中一共展示了EpubReader类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadBook
import nl.siegmann.epublib.epub.EpubReader; //导入依赖的package包/类
private void loadBook() {
try {
// 打开书籍
EpubReader reader = new EpubReader();
InputStream is = new FileInputStream(mFilePath);
mBook = reader.readEpub(is);
mTocReferences = (ArrayList<TOCReference>) mBook.getTableOfContents().getTocReferences();
mSpineReferences = mBook.getSpine().getSpineReferences();
setSpineReferenceTitle();
// 解压epub至缓存目录
FileUtils.unzipFile(mFilePath, Constant.PATH_EPUB + "/" + mFileName);
} catch (IOException e) {
e.printStackTrace();
}
}
示例2: epubParse
import nl.siegmann.epublib.epub.EpubReader; //导入依赖的package包/类
public String epubParse(InputStream fileIn) throws IOException
{
EpubReader epubReader = new EpubReader();
Book book = epubReader.readEpub(fileIn);
for (int i = 0; i < book.getSpine().size(); i++)
{
InputStream is = book.getSpine().getSpineReferences().get(i).getResource().getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
htmltext = sb.toString();
htmltext = htmltext.replaceAll("\\<.*?\\>", "");
}
return htmltext;
}
示例3: getDocumentContent
import nl.siegmann.epublib.epub.EpubReader; //导入依赖的package包/类
/**
* Implementation of Public method that is used to return the entire content of a .epub file as a single value String.
* Turns one-by-one all internal html files into String values.
* @return String: the entire content of a .epub file
*/
@Override
public String getDocumentContent() throws IOException {
System.out.println(getUri());
EpubReader epubReader = new EpubReader();
Book book = epubReader.readEpub(new FileInputStream(getUri()));
String entireContent = "";
String textContent = "";
int fileNumber = book.getContents().size();
for(int i=0; i<fileNumber; i++) {
InputStream inputStream = book.getContents().get(i).getInputStream(); // file .html
try {
Scanner scanner = new Scanner(inputStream).useDelimiter("\\A");
entireContent = scanner.hasNext() ? scanner.next() : "";
} finally {
inputStream.close();
}
org.jsoup.nodes.Document doc = Jsoup.parse(entireContent);
textContent += doc.body().text();
textContent += "\n\n";
}
return textContent;
}
示例4: process
import nl.siegmann.epublib.epub.EpubReader; //导入依赖的package包/类
public void process(Context context){
try {
path = FileStorable.takePath(context, path);
if (path == null){
return;
}
File file = new File(path);
fileSize = file.length();
encoding = Constants.DEFAULT_ENCODING;
book = (new EpubReader()).readEpubLazy(path, encoding);
resources = book.getContents();
createRowData(context);
if (bytePosition > 0){
long passed = 0;
while (index < resources.size() && passed < bytePosition)
passed += resources.get(index++).getSize();
}
processed = true;
} catch (IOException e) {
e.printStackTrace();
}
}
示例5: importBook
import nl.siegmann.epublib.epub.EpubReader; //导入依赖的package包/类
private boolean importBook(File file) {
if (! libraryService.hasBook(file.getName() ) ) {
try {
String fileName = file.getAbsolutePath();
// read epub file
EpubReader epubReader = new EpubReader();
Book importedBook = epubReader.readEpubLazy(fileName, "UTF-8",
Arrays.asList(MediatypeService.mediatypes));
libraryService.storeBook(fileName, importedBook, false, this.copyToLibrary);
return true;
} catch (Exception io ) {
if ( ! isCancelled() ) {
errors.add( file + ": " + io.getMessage() );
LOG.error("Error while reading book: " + file, io);
} else {
LOG.info("Ignoring error since we were cancelled", io );
}
}
}
return false;
}
示例6: getEbook
import nl.siegmann.epublib.epub.EpubReader; //导入依赖的package包/类
/**
* Returns the book of the path
* @return
* @throws IOException
*/
public Book getEbook() throws IOException {
Book ebook;
EpubReader epubReader = new EpubReader();
zipInputStream =
new ZipInputStream(new FileInputStream(path.toFile()), Charset.forName("Cp437"));
ebook = epubReader.readEpub(zipInputStream);
zipInputStream.close();
return ebook;
}
示例7: EpubManipulator
import nl.siegmann.epublib.epub.EpubReader; //导入依赖的package包/类
public EpubManipulator(String fileName, String folder, int spineIndex,
int language, Context theContext) throws Exception {
List<String> spineElements;
List<SpineReference> spineList;
if (context == null) {
context = theContext;
}
this.fs = new FileInputStream(fileName);
this.book = (new EpubReader()).readEpub(fs);
this.fileName = fileName;
this.decompressedFolder = folder;
Spine spine = book.getSpine();
spineList = spine.getSpineReferences();
this.currentSpineElementIndex = spineIndex;
this.currentLanguage = language;
spineElements = new ArrayList<String>();
pages(spineList, spineElements);
this.pageCount = spineElements.size();
this.spineElementPaths = new String[spineElements.size()];
pathOPF = getPathOPF(location + folder);
for (int i = 0; i < spineElements.size(); ++i) {
// TODO: is there a robust path joiner in the java libs?
this.spineElementPaths[i] = "file://" + location + folder + "/"
+ pathOPF + "/" + spineElements.get(i);
}
goToPage(spineIndex);
}
示例8: readUncompressedBook
import nl.siegmann.epublib.epub.EpubReader; //导入依赖的package包/类
static Book readUncompressedBook(File folder) throws IOException {
Resources resources = readLazyResources(folder);
return new EpubReader().readEpub(resources);
}
示例9: readEpubFile
import nl.siegmann.epublib.epub.EpubReader; //导入依赖的package包/类
/**
* Get a {@link SuperBook} object from a file object.
* @param file The file to try and read as an ePub
* @return Book object, or {@code null} if there were issues.
*/
static SuperBook readEpubFile(File file, String relPath) {
if (file == null || !file.exists() || !file.isFile()) return null;
try (HashingInputStream in = new HashingInputStream(new FileInputStream(file))) {
Book book = new EpubReader().readEpub(in);
return new SuperBook(book, relPath, in.hash().asBytes());
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
示例10: initBook
import nl.siegmann.epublib.epub.EpubReader; //导入依赖的package包/类
public Book initBook(String fileName) throws IOException {
if (fileName == null) {
throw new IOException("No file-name specified.");
}
if ( hasCachedBook( fileName ) ) {
LOG.debug("Returning cached Book for fileName " + currentFile );
return currentBook;
}
closeCurrentBook();
this.anchors = new HashMap<>();
// read epub file
EpubReader epubReader = new EpubReader();
Book newBook = epubReader.readEpubLazy(fileName, "UTF-8");
this.currentBook = newBook;
this.currentFile = fileName;
return newBook;
}