public abstract class AttachmentTO extends AbstractTransferObject implements Serializable
AttachmentTO
encapsulates the logic to access an attachment by streams. The streams
source can be either a file or a stream which is defined by the subclasses.
The encapsulation is necessary to assure the closing of the input streams as they got accessed.
Use the write methods to write an attachment either to a file or to another stream.Constructor and Description |
---|
AttachmentTO(AttachmentStatus status) |
Modifier and Type | Method and Description |
---|---|
protected void |
close(InputStream inputStream)
Close the stream
|
long |
getContentLength()
Get the content length.
|
ContentMetadata |
getMetadata() |
Long |
getNoteId() |
List<StringPropertyTO> |
getProperties() |
AttachmentStatus |
getStatus()
The status of the attachment to be used
|
Date |
getUploadDate() |
Long |
getUploaderId() |
protected abstract InputStream |
open()
Open the inputstream
|
void |
sendInResponse(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
String characterEncoding,
boolean dipositionTypeAsAttachment) |
void |
setContentLength(long contentLength)
Set the content length, that will set it on the metadata, if not null.
|
void |
setMetadata(ContentMetadata metadata)
Sets the metadata, it will also update metadata.getContentSize if the content size might be
known and the metadata content length is not set
|
void |
setNoteId(Long noteId)
NoteId is ignored on creating a note and associating it.
|
void |
setProperties(List<StringPropertyTO> properties) |
void |
setStatus(AttachmentStatus status) |
void |
setUploadDate(Date uploadDate) |
void |
setUploaderId(Long uploaderId) |
void |
setVirusScanner(VirusScanner scanner) |
String |
toString() |
void |
write(File file)
Open the stream and write its content to the file.
|
void |
write(File file,
long maxLength)
Open the stream and write at most maxLength bytes of the content to the file.
|
void |
write(OutputStream outStream)
Write the attachment to the output stream.
|
void |
write(OutputStream outStream,
long maxLength)
Write the attachment to the output stream.
|
copy
public AttachmentTO(AttachmentStatus status)
status
- set the status, can be nullprotected void close(InputStream inputStream) throws IOException
inputStream
- the input streamIOException
- in case of an io errorpublic long getContentLength()
public ContentMetadata getMetadata()
public Long getNoteId()
public List<StringPropertyTO> getProperties()
public AttachmentStatus getStatus()
The status of the attachment to be used
public Date getUploadDate()
public Long getUploaderId()
protected abstract InputStream open() throws IOException
IOException
- in case of an io errorpublic void sendInResponse(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String characterEncoding, boolean dipositionTypeAsAttachment) throws IOException
IOException
public void setContentLength(long contentLength)
contentLength
- the content lengthpublic void setMetadata(ContentMetadata metadata)
metadata
- the metadata to be setpublic void setNoteId(Long noteId)
NoteManagement
to connect attachments with notes.noteId
- id of the note the attachment is associated with. null if no note connected.public void setProperties(List<StringPropertyTO> properties)
public void setStatus(AttachmentStatus status)
status
- set the attachment statuspublic void setUploadDate(Date uploadDate)
uploadDate
- The date the attachment was uploaded.public void setUploaderId(Long uploaderId)
uploaderId
- Method to set the uploaders id.public void setVirusScanner(VirusScanner scanner)
scanner
- the virus scanner to be used then writingpublic void write(File file) throws IOException
#metadata#setContentLength(long)
) if metadata is not null.file
- the file to write toIOException
- in case of an errorpublic void write(File file, long maxLength) throws IOException
#metadata#setContentLength(long)
) if metadata is not
null.file
- the file to write tomaxLength
- See IOHelper.write(InputStream, OutputStream, long)
for more information.IOException
- in case of an errorpublic void write(OutputStream outStream) throws IOException
outStream
- the output streamIOException
- in case of an errorpublic void write(OutputStream outStream, long maxLength) throws IOException
outStream
- the output streammaxLength
- See IOHelper.write(InputStream, OutputStream, long)
for more information.IOException
- in case of an errorCopyright © 2019 Communote team. All rights reserved.