EpubReader
EpubReader is the modern Fluent API entry point for the EPUBime library, providing a chained method approach to configure and parse EPUB files.
Class Definition
public class EpubReaderConstructors
This class cannot be instantiated directly and must be created using static factory methods.
Static Methods
fromFile(File epubFile)
Creates an EpubReader instance with default configuration.
Parameters:
epubFile: The EPUB file to parse
Returns:
EpubReader: A new EpubReader instance
Exceptions:
IllegalArgumentException: If epubFile is null
fromFile(String filePath)
Creates an EpubReader instance with default configuration from a file path.
Parameters:
filePath: Path to the EPUB file
Returns:
EpubReader: A new EpubReader instance
Exceptions:
IllegalArgumentException: If filePath is null
fromFile(File epubFile, EpubReaderConfig config)
Creates an EpubReader instance with custom configuration.
Parameters:
epubFile: The EPUB file to parseconfig: Configuration object
Returns:
EpubReader: A new EpubReader instance
Exceptions:
IllegalArgumentException: If epubFile or config is null
Instance Methods
parse()
Parses the EPUB file and returns an EpubBook object.
Returns:
EpubBook: The parsed EPUB book object
Exceptions:
BaseEpubException: Exceptions occurring during parsingIOException: I/O operation failuresEpubPathValidationException: Path validation failures
parseMetadata()
Parses only the metadata of the EPUB file.
Returns:
Metadata: EPUB metadata
Exceptions:
BaseEpubException: Exceptions occurring during parsingIOException: I/O operation failuresEpubPathValidationException: Path validation failures
parseTableOfContents()
Parses only the table of contents of the EPUB file.
Returns:
List<EpubChapter>: List of chapters
Exceptions:
BaseEpubException: Exceptions occurring during parsingIOException: I/O operation failuresEpubPathValidationException: Path validation failures
streamChapters(BiConsumer<EpubChapter, InputStream> processor)
Processes chapter content in a streaming manner without loading the entire content into memory.
Parameters:
processor: Consumer function to process each chapter and its content stream
Exceptions:
BaseEpubException: Exceptions occurring during processingIOException: I/O operation failuresEpubPathValidationException: Path validation failures
streamChapter(String chapterId, Consumer<InputStream> processor)
Processes the content of a specific chapter in a streaming manner.
Parameters:
chapterId: The ID of the chapter to processprocessor: Consumer function to process the chapter content stream
Exceptions:
BaseEpubException: Exceptions occurring during processingEpubPathValidationException: Path validation failuresIOException: I/O operation failures
processResources(Function<EpubResource, Void> processor)
Processes all resource files.
Parameters:
processor: Function to process each resource
Exceptions:
BaseEpubException: Exceptions occurring during processingIOException: I/O operation failuresEpubPathValidationException: Path validation failures
getResource(String resourceId)
Gets a specific resource by resource ID.
Parameters:
resourceId: The resource ID
Returns:
EpubResource: The resource object, or null if not found
Exceptions:
BaseEpubException: Exceptions occurring during parsingIOException: I/O operation failuresEpubPathValidationException: Path validation failures
getCover()
Gets the cover resource of the EPUB file.
Returns:
EpubResource: The cover resource, or null if not found
Exceptions:
BaseEpubException: Exceptions occurring during parsingIOException: I/O operation failuresEpubPathValidationException: Path validation failures
isValid()
Checks if the EPUB file is valid.
Returns:
boolean: True if the file is valid, false otherwise
getInfo()
Gets basic information about the EPUB file without full parsing.
Returns:
EpubInfo: Basic information about the EPUB file
Exceptions:
BaseEpubException: Exceptions occurring during parsingIOException: I/O operation failuresEpubPathValidationException: Path validation failures
Inner Classes
EpubInfo
Basic information class for EPUB files.
Constructor
public EpubInfo(String title, String author, String language, int chapterCount, long fileSize)Methods
getTitle(): Gets the titlegetAuthor(): Gets the authorgetLanguage(): Gets the languagegetChapterCount(): Gets the number of chaptersgetFileSize(): Gets the file sizetoString(): Returns a formatted string representation
Usage Examples
// Basic usage
EpubBook book = EpubReader.fromFile(new File("book.epub")).parse();
// Using custom configuration
EpubReaderConfig config = new EpubReaderConfig()
.withCache(true)
.withLazyLoading(false)
.withParallelProcessing(true);
EpubBook book = EpubReader.fromFile(new File("book.epub"), config).parse();
// Streaming chapter processing
EpubReader.fromFile(new File("book.epub"))
.streamChapters((chapter, inputStream) -> {
System.out.println("Processing chapter: " + chapter.getTitle());
// Process content stream
});
// Getting basic information
EpubReader.EpubInfo info = EpubReader.fromFile(new File("book.epub")).getInfo();
System.out.println(info);