EpubResource
EpubResource class represents a resource file in an EPUB book, such as images, CSS, fonts, etc.
Constructor
public EpubResource()Creates a new EpubResource instance.
public EpubResource(String href, String mediaType)Creates a new EpubResource instance.
Parameters:
href: Resource's href attributemediaType: Resource's media type
public EpubResource(String id, String href, String mediaType, byte[] data)Creates a new EpubResource instance.
Parameters:
id: Resource IDhref: Resource's href attributemediaType: Resource's media typedata: Resource data
Main Methods
getId()
public String getId()Gets resource ID.
Returns:
String: Resource ID
setId()
public void setId(String id)Sets resource ID.
Parameters:
id: Resource ID
getHref()
public String getHref()Gets resource's href attribute.
Returns:
String: Resource's href attribute
setHref()
public void setHref(String href)Sets resource's href attribute.
Parameters:
href: Resource's href attribute
getMediaType()
public String getMediaType()Gets resource's media type.
Returns:
String: Resource's media type (e.g., "image/jpeg", "text/css")
setMediaType()
public void setMediaType(String mediaType)Sets resource's media type.
Parameters:
mediaType: Resource's media type
getData()
public byte[] getData()Gets resource data.
Returns:
byte[]: Resource data
setData()
public void setData(byte[] data)Sets resource data.
Parameters:
data: Resource data
getFileName()
public String getFileName()Gets resource filename (extracted from href).
Returns:
String: Resource filename
getExtension()
public String getExtension()Gets resource file extension.
Returns:
String: Resource file extension (e.g., "jpg", "css")
getSize()
public long getSize()Gets resource size (in bytes).
Returns:
long: Resource size
isImage()
public boolean isImage()Checks if resource is an image.
Returns:
boolean: Returns true if resource is an image, otherwise false
isStylesheet()
public boolean isStylesheet()Checks if resource is a stylesheet.
Returns:
boolean: Returns true if resource is a stylesheet, otherwise false
isScript()
public boolean isScript()Checks if resource is a script file.
Returns:
boolean: Returns true if resource is a script file, otherwise false
isFont()
public boolean isFont()Checks if resource is a font file.
Returns:
boolean: Returns true if resource is a font file, otherwise false
isAudio()
public boolean isAudio()Checks if resource is an audio file.
Returns:
boolean: Returns true if resource is an audio file, otherwise false
isVideo()
public boolean isVideo()Checks if resource is a video file.
Returns:
boolean: Returns true if resource is a video file, otherwise false
saveToFile()
public void saveToFile(String filePath) throws EpubResourceExceptionSaves resource to file.
Parameters:
filePath: Target file path
Throws:
EpubResourceException: Error occurred during saving
saveToDirectory()
public void saveToDirectory(String directoryPath) throws EpubResourceExceptionSaves resource to specified directory.
Parameters:
directoryPath: Target directory path
Throws:
EpubResourceException: Error occurred during saving
toInputStream()
public InputStream toInputStream()Converts resource data to input stream.
Returns:
InputStream: Input stream of resource data
toBufferedImage()
public BufferedImage toBufferedImage() throws EpubResourceExceptionConverts image resource to BufferedImage object.
Returns:
BufferedImage: BufferedImage object of image
Throws:
EpubResourceException: Error occurred during conversion (if resource is not valid image)
toCSSDocument()
public String toCSSDocument() throws EpubResourceExceptionConverts CSS resource to string.
Returns:
String: CSS content string
Throws:
EpubResourceException: If resource is not CSS file
getMimeType()
public String getMimeType()Gets resource's MIME type.
Returns:
String: MIME type
isBinary()
public boolean isBinary()Checks if resource is a binary file.
Returns:
boolean: Returns true if resource is a binary file, otherwise false
getTextContent()
public String getTextContent() throws EpubResourceExceptionGets text resource content.
Returns:
String: Text content
Throws:
EpubResourceException: If resource is not text file or reading fails
updateContent()
public void updateContent(String newContent) throws EpubResourceExceptionUpdates text resource content.
Parameters:
newContent: New text content
Throws:
EpubResourceException: If resource is not text file or update fails
getAbsolutePath()
public String getAbsolutePath()Gets resource's absolute path.
Returns:
String: Resource's absolute path
getRelativePath()
public String getRelativePath(String basePath)Gets resource's relative path to specified base path.
Parameters:
basePath: Base path
Returns:
String: Relative path
isValid()
public boolean isValid()Checks if resource is valid (has valid href and media type).
Returns:
boolean: Returns true if resource is valid, otherwise false
toString()
public String toString()Returns string representation of resource.
Returns:
String: String representation of resource