Package org.ametys.cms.data
Class Resource
- java.lang.Object
-
- org.ametys.cms.data.Resource
-
- Direct Known Subclasses:
NamedResource,RichText
public class Resource extends Object
Class representing a resource
-
-
Field Summary
Fields Modifier and Type Field Description protected byte[]_bufferBuffer for small-sized dataprotected String_encodingThe resource's encodingprotected ZonedDateTime_lastModificationDateThe resource's last modification dateprotected String_mimeTypeThe resource's mime typeprotected RepositoryData_repositoryDataThe resource's repository dataprotected File_tmpFileUnderlying tmp fileprivate static byte[]EMPTY_BYTE_ARRAYEmpty arrayprivate static intMAX_BUFFER_SIZEMax size for keeping temporary data in memory
-
Constructor Summary
Constructors Constructor Description Resource()Default constructorResource(RepositoryData repositoryData)Constructor to use when reading the resource from the repository
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcloseOutputStream(ByteArrayOutputStream outputStream)Closes the givenOutputStreamStringgetEncoding()Retrieves the encoding of the resource's dataInputStreamgetInputStream()Retrieve the resource's data If the data has already been read, the stream is reseted so it can be read again from the startZonedDateTimegetLastModificationDate()Retrieves the last modification date of the resource's datalonggetLength()Retrieves the length of the resource's dataStringgetMimeType()Retrieves the mime type of the resource's dataOutputStreamgetOutputStream()Retrieves an output stream that allows to modify the resource's datavoidsetEncoding(String encoding)Sets the encoding of the resource's datavoidsetInputStream(InputStream in)Sets the resource's datavoidsetLastModificationDate(ZonedDateTime lastModificationDate)Sets the last modification date of the resource's datavoidsetMimeType(String mimeType)Sets the mime type of the resource's data
-
-
-
Field Detail
-
EMPTY_BYTE_ARRAY
private static final byte[] EMPTY_BYTE_ARRAY
Empty array
-
MAX_BUFFER_SIZE
private static final int MAX_BUFFER_SIZE
Max size for keeping temporary data in memory- See Also:
- Constant Field Values
-
_lastModificationDate
protected ZonedDateTime _lastModificationDate
The resource's last modification date
-
_buffer
protected byte[] _buffer
Buffer for small-sized data
-
_repositoryData
protected RepositoryData _repositoryData
The resource's repository data
-
-
Constructor Detail
-
Resource
public Resource()
Default constructor
-
Resource
public Resource(RepositoryData repositoryData)
Constructor to use when reading the resource from the repository- Parameters:
repositoryData- the repository data containing the resource's data
-
-
Method Detail
-
getInputStream
public 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- Returns:
- the resource's data, or
nullif there is no data
-
getLength
public long getLength() throws AmetysRepositoryException
Retrieves the length of the resource's data- Returns:
- the length of the resource's data
- Throws:
AmetysRepositoryException- if an error occurs while reading the data in the repository
-
setInputStream
public void setInputStream(InputStream in) throws IOException
Sets the resource's data- Parameters:
in- the data to set- Throws:
IOException- if an error occurs while reading the input stream
-
getOutputStream
public OutputStream getOutputStream()
Retrieves an output stream that allows to modify the resource's data- Returns:
- the output stream
-
closeOutputStream
protected void closeOutputStream(ByteArrayOutputStream outputStream) throws IOException
Closes the givenOutputStream- Parameters:
outputStream- theOutputStreamto close- Throws:
IOException- if an error occurs while registering the stream
-
getMimeType
public String getMimeType()
Retrieves the mime type of the resource's data- Returns:
- the mime type of the resource's data
-
setMimeType
public void setMimeType(String mimeType)
Sets the mime type of the resource's data- Parameters:
mimeType- the mime type to set
-
getEncoding
public String getEncoding()
Retrieves the encoding of the resource's data- Returns:
- the encoding of the resource's data
-
setEncoding
public void setEncoding(String encoding)
Sets the encoding of the resource's data- Parameters:
encoding- the encoding to set
-
getLastModificationDate
public ZonedDateTime getLastModificationDate()
Retrieves the last modification date of the resource's data- Returns:
- the last modification date of the resource's data
-
setLastModificationDate
public void setLastModificationDate(ZonedDateTime lastModificationDate)
Sets the last modification date of the resource's data- Parameters:
lastModificationDate- the last modification date to set
-
-