public class Resource extends Object implements Serializable
Modifier and Type | Field and Description |
---|---|
protected byte[] |
data |
protected String |
originalHref |
Constructor and Description |
---|
Resource(byte[] data,
MediaType mediaType)
Creates a Resource with the given data and MediaType.
|
Resource(byte[] data,
String href)
Creates a resource with the given data at the specified href.
|
Resource(InputStream in,
String href)
Creates a resource with the data from the given InputStream at the specified href.
|
Resource(Reader in,
String href)
Creates a resource with the data from the given Reader at the specified href.
|
Resource(String href)
Creates an empty Resource with the given href.
|
Resource(String id,
byte[] data,
String href,
MediaType mediaType)
Creates a resource with the given id, data, mediatype at the specified href.
|
Resource(String id,
byte[] data,
String href,
MediaType mediaType,
String inputEncoding)
Creates a resource with the given id, data, mediatype at the specified href.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Tells this resource to release its cached data.
|
boolean |
equals(Object resourceObject)
Checks 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[]
|
String |
getHref()
The location of the resource within the contents folder of the epub file.
|
String |
getId()
The resources Id.
|
String |
getInputEncoding()
The character encoding of the resource.
|
InputStream |
getInputStream()
Gets the contents of the Resource as an InputStream.
|
MediaType |
getMediaType()
This resource's mediaType.
|
Reader |
getReader()
Gets the contents of the Resource as Reader.
|
long |
getSize()
Returns the size of this resource in bytes.
|
String |
getTitle()
If the title is found by scanning the underlying html document then it is cached here.
|
int |
hashCode()
Gets the hashCode of the Resource's href.
|
void |
setData(byte[] data)
Sets the data of the Resource.
|
void |
setHref(String href)
Sets the Resource's href.
|
void |
setId(String id)
Sets the Resource's id: Make sure it is unique and a valid identifier.
|
void |
setInputEncoding(String encoding)
Sets the Resource's input character encoding.
|
void |
setMediaType(MediaType mediaType) |
void |
setTitle(String title) |
String |
toString() |
protected String originalHref
protected byte[] data
public Resource(String href)
href
- The location of the resource within the epub. Example: "chapter1.html".public Resource(byte[] data, MediaType mediaType)
data
- The Resource's contentsmediaType
- The MediaType of the Resourcepublic Resource(byte[] data, String href)
data
- The Resource's contentshref
- The location of the resource within the epub. Example: "chapter1.html".MediatypeService.determineMediaType(String)
public Resource(Reader in, String href) throws IOException
in
- The Resource's contentshref
- The location of the resource within the epub. Example: "cover.jpg".IOException
MediatypeService.determineMediaType(String)
public Resource(InputStream in, String href) throws IOException
in
- The Resource's contentshref
- The location of the resource within the epub. Example: "cover.jpg".IOException
Assumes that if the data is of a text type (html/css/etc) then the encoding will be UTF-8
It is recommended to us the {@link #Resource(Reader, String)} method for creating textual
(html/css/etc) resources to prevent encoding problems.
Use this method only for binary Resources like images, fonts, etc.
public Resource(String id, byte[] data, String href, MediaType mediaType)
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 MediaTypepublic Resource(String id, byte[] data, String href, MediaType mediaType, String inputEncoding)
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.public InputStream getInputStream() throws IOException
IOException
public byte[] getData() throws IOException
IOException
public void close()
public void setData(byte[] data)
data
- public long getSize()
public String getTitle()
public void setId(String id)
id
- public String getId()
public String getHref()
public void setHref(String href)
href
- public String getInputEncoding()
public void setInputEncoding(String encoding)
encoding
- public Reader getReader() throws IOException
IOException
public int hashCode()
public boolean equals(Object resourceObject)
public MediaType getMediaType()
public void setMediaType(MediaType mediaType)
public void setTitle(String title)
Copyright © 2009–2017. All rights reserved.