Class Resource
java.lang.Object
nl.siegmann.epublib.domain.Resource
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
LazyResource
Represents a resource that is part of the epub.
A resource can be a html file, image, xml, etc.
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a resource with the given data at the specified href.Creates a Resource with the given data and MediaType.Resource(InputStream in, String href) Creates a resource with the data from the given InputStream at the specified href.Creates a resource with the data from the given Reader at the specified href.Creates an empty Resource with the given href.Creates a resource with the given id, data, mediatype at the specified href.Creates a resource with the given id, data, mediatype at the specified href. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Tells this resource to release its cached data.booleanChecks to see of the given resourceObject is a resource and whether its href is equal to this one.byte[]getData()The contents of the resource as a byte[]getHref()The location of the resource within the contents folder of the epub file.getId()The resources Id.The character encoding of the resource.Gets the contents of the Resource as an InputStream.This resource's mediaType.Gets the contents of the Resource as Reader.longgetSize()Returns the size of this resource in bytes.getTitle()If the title is found by scanning the underlying html document then it is cached here.inthashCode()Gets the hashCode of the Resource's href.voidsetData(byte[] data) Sets the data of the Resource.voidSets the Resource's href.voidSets the Resource's id: Make sure it is unique and a valid identifier.voidsetInputEncoding(String encoding) Sets the Resource's input character encoding.voidsetMediaType(MediaType mediaType) voidtoString()
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
id
-
title
-
href
-
originalHref
-
mediaType
-
inputEncoding
-
data
protected byte[] data
-
-
Constructor Details
-
Resource
Creates an empty Resource with the given href. Assumes that if the data is of a text type (html/css/etc) then the encoding will be UTF-8- Parameters:
href- The location of the resource within the epub. Example: "chapter1.html".
-
Resource
Creates a Resource with the given data and MediaType. The href will be automatically generated. Assumes that if the data is of a text type (html/css/etc) then the encoding will be UTF-8- Parameters:
data- The Resource's contentsmediaType- The MediaType of the Resource
-
Resource
Creates a resource with the given data at the specified href. The MediaType will be determined based on the href extension. Assumes that if the data is of a text type (html/css/etc) then the encoding will be UTF-8- Parameters:
data- The Resource's contentshref- The location of the resource within the epub. Example: "chapter1.html".- See Also:
-
Resource
Creates a resource with the data from the given Reader at the specified href. The MediaType will be determined based on the href extension.- Parameters:
in- The Resource's contentshref- The location of the resource within the epub. Example: "cover.jpg".- Throws:
IOException- See Also:
-
Resource
Creates a resource with the data from the given InputStream at the specified href. The MediaType will be determined based on the href extension.- Parameters:
in- The Resource's contentshref- The location of the resource within the epub. Example: "cover.jpg".- Throws:
IOException- See Also:
-
Resource
Creates a resource with the given id, data, mediatype at the specified href. Assumes that if the data is of a text type (html/css/etc) then the encoding will be UTF-8- Parameters:
id- The id of the Resource. Internal use only. Will be auto-generated if it has a null-value.data- The Resource's contentshref- The location of the resource within the epub. Example: "chapter1.html".mediaType- The resources MediaType
-
Resource
Creates a resource with the given id, data, mediatype at the specified href. If the data is of a text type (html/css/etc) then it will use the given inputEncoding.- Parameters:
id- The id of the Resource. Internal use only. Will be auto-generated if it has a null-value.data- The Resource's contentshref- The location of the resource within the epub. Example: "chapter1.html".mediaType- The resources MediaTypeinputEncoding- If the data is of a text type (html/css/etc) then it will use the given inputEncoding.
-
-
Method Details
-
getInputStream
Gets the contents of the Resource as an InputStream.- Returns:
- The contents of the Resource.
- Throws:
IOException
-
getData
The contents of the resource as a byte[]- Returns:
- The contents of the resource
- Throws:
IOException
-
close
public void close()Tells this resource to release its cached data. If this resource was not lazy-loaded, this is a no-op. -
setData
public void setData(byte[] data) Sets the data of the Resource. If the data is a of a different type then the original data then make sure to change the MediaType.- Parameters:
data-
-
getSize
public long getSize()Returns the size of this resource in bytes.- Returns:
- the size.
-
getTitle
If the title is found by scanning the underlying html document then it is cached here.- Returns:
- the title
-
setId
Sets the Resource's id: Make sure it is unique and a valid identifier.- Parameters:
id-
-
getId
The resources Id. Must be both unique within all the resources of this book and a valid identifier.- Returns:
- The resources Id.
-
getHref
The location of the resource within the contents folder of the epub file. Example:
images/cover.jpg
content/chapter1.xhtml- Returns:
- The location of the resource within the contents folder of the epub file.
-
setHref
-
getInputEncoding
The character encoding of the resource. Is allowed to be null for non-text resources like images.- Returns:
- The character encoding of the resource.
-
setInputEncoding
Sets the Resource's input character encoding.- Parameters:
encoding-
-
getReader
Gets the contents of the Resource as Reader. Does all sorts of smart things (courtesy of apache commons io XMLStreamREader) to handle encodings, byte order markers, etc.- Returns:
- the contents of the Resource as Reader.
- Throws:
IOException
-
hashCode
-
equals
-
getMediaType
-
setMediaType
-
setTitle
-
toString
-