public class Resource extends Object
Modifier and Type | Field and Description |
---|---|
protected byte[] |
_buffer
Buffer for small-sized data
|
protected String |
_encoding
The resource's encoding
|
protected ZonedDateTime |
_lastModificationDate
The resource's last modification date
|
protected String |
_mimeType
The resource's mime type
|
protected RepositoryData |
_repositoryData
The resource's repository data
|
protected File |
_tmpFile
Underlying tmp file
|
private static byte[] |
EMPTY_BYTE_ARRAY
Empty array
|
private static int |
MAX_BUFFER_SIZE
Max size for keeping temporary data in memory
|
Constructor and Description |
---|
Resource()
Default constructor
|
Resource(RepositoryData repositoryData)
Constructor to use when reading the resource from the repository
|
Modifier and Type | Method and Description |
---|---|
protected void |
closeOutputStream(ByteArrayOutputStream outputStream)
Closes the given
OutputStream |
String |
getEncoding()
Retrieves the encoding of the resource's data
|
InputStream |
getInputStream()
Retrieve the resource's data
If the data has already been read, the stream is reseted so it can be read again from the start
|
ZonedDateTime |
getLastModificationDate()
Retrieves the last modification date of the resource's data
|
long |
getLength()
Retrieves the length of the resource's data
|
String |
getMimeType()
Retrieves the mime type of the resource's data
|
OutputStream |
getOutputStream()
Retrieves an output stream that allows to modify the resource's data
|
void |
setEncoding(String encoding)
Sets the encoding of the resource's data
|
void |
setInputStream(InputStream in)
Sets the resource's data
|
void |
setLastModificationDate(ZonedDateTime lastModificationDate)
Sets the last modification date of the resource's data
|
void |
setMimeType(String mimeType)
Sets the mime type of the resource's data
|
private static final byte[] EMPTY_BYTE_ARRAY
private static final int MAX_BUFFER_SIZE
protected ZonedDateTime _lastModificationDate
protected byte[] _buffer
protected RepositoryData _repositoryData
public Resource()
public Resource(RepositoryData repositoryData)
repositoryData
- the repository data containing the resource's datapublic InputStream getInputStream() throws AmetysRepositoryException
null
if there is no dataAmetysRepositoryException
- if an error occurs while reading the data in the repositorypublic long getLength() throws AmetysRepositoryException
AmetysRepositoryException
- if an error occurs while reading the data in the repositorypublic void setInputStream(InputStream in) throws IOException
in
- the data to setIOException
- if an error occurs while reading the input streampublic OutputStream getOutputStream()
protected void closeOutputStream(ByteArrayOutputStream outputStream) throws IOException
OutputStream
outputStream
- the OutputStream
to closeIOException
- if an error occurs while registering the streampublic String getMimeType()
public void setMimeType(String mimeType)
mimeType
- the mime type to setpublic String getEncoding()
public void setEncoding(String encoding)
encoding
- the encoding to setpublic ZonedDateTime getLastModificationDate()
public void setLastModificationDate(ZonedDateTime lastModificationDate)
lastModificationDate
- the last modification date to set