public class FileRepresentation extends Representation
Disposition.setType(String) with a
Disposition.TYPE_ATTACHMENT value.UNKNOWN_SIZE| Constructor and Description |
|---|
FileRepresentation(java.io.File file,
MediaType mediaType)
Constructor that does not set an expiration date for
file |
FileRepresentation(java.io.File file,
MediaType mediaType,
int timeToLive)
Constructor.
|
FileRepresentation(java.lang.String path,
MediaType mediaType)
Constructor that does not set an expiration date for
path |
FileRepresentation(java.lang.String path,
MediaType mediaType,
int timeToLive)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
java.nio.channels.FileChannel |
getChannel()
Returns a readable byte channel.
|
java.io.File |
getFile()
Returns the file handle.
|
java.io.Reader |
getReader()
Returns a characters reader with the representation's content.
|
long |
getSize()
Returns the total size in bytes if known, UNKNOWN_SIZE (-1) otherwise.
|
java.io.FileInputStream |
getStream()
Returns a stream with the representation's content.
|
java.lang.String |
getText()
Note that this method relies on
getStream(). |
boolean |
isAutoDeleting()
Indicates if this file should be automatically deleted on release of the
representation.
|
void |
release()
Releases the file handle.
|
void |
setAutoDeleting(boolean autoDeleting)
Indicates if this file should be automatically deleted on release of the
representation.
|
void |
setFile(java.io.File file)
Sets the file handle.
|
void |
write(java.io.OutputStream outputStream)
Writes the representation to a byte stream.
|
void |
write(java.nio.channels.WritableByteChannel writableChannel)
Writes the representation to a byte channel.
|
void |
write(java.io.Writer writer)
Writes the representation to a characters writer.
|
append, exhaust, getAvailableSize, getDigest, getDisposition, getExpirationDate, getRange, hasKnownSize, isAvailable, isEmpty, isTransient, setAvailable, setDigest, setDisposition, setExpirationDate, setRange, setSize, setTransientgetModificationDate, getTag, setModificationDate, setTagcreateClientInfo, equals, getCharacterSet, getEncodings, getLanguages, getLocationRef, getMediaType, hashCode, includes, isCompatible, setCharacterSet, setEncodings, setLanguages, setLocationRef, setLocationRef, setMediaType, toStringpublic FileRepresentation(java.io.File file,
MediaType mediaType)
filefile - The represented file.mediaType - The representation's media type.FileRepresentation(File, MediaType, int)public FileRepresentation(java.io.File file,
MediaType mediaType,
int timeToLive)
file - The represented file.mediaType - The representation's media type.timeToLive - The time to live before it expires (in seconds).public FileRepresentation(java.lang.String path,
MediaType mediaType)
pathpath - The path name or file URI of the represented file (either in
system format or in 'file:///' format).mediaType - The representation's media type.FileRepresentation(String, MediaType, int)public FileRepresentation(java.lang.String path,
MediaType mediaType,
int timeToLive)
path - The path name or file URI of the represented file (either in
system format or in 'file:///' format).mediaType - The representation's media type.timeToLive - The time to live before it expires (in seconds).File(String)public java.nio.channels.FileChannel getChannel()
throws java.io.IOException
getChannel in class Representationjava.io.IOExceptionpublic java.io.File getFile()
public java.io.Reader getReader()
throws java.io.IOException
RepresentationgetReader in class Representationjava.io.IOExceptionpublic long getSize()
RepresentationRepresentation.getAvailableSize() method.getSize in class RepresentationRepresentation.isEmpty()public java.io.FileInputStream getStream()
throws java.io.IOException
RepresentationgetStream in class Representationjava.io.IOExceptionpublic java.lang.String getText()
throws java.io.IOException
getStream(). This stream is
closed once fully read.getText in class Representationjava.io.IOExceptionpublic boolean isAutoDeleting()
public void release()
release in class Representationpublic void setAutoDeleting(boolean autoDeleting)
autoDeleting - True if this file should be automatically deleted on release
of the representation.public void setFile(java.io.File file)
file - The file handle.public void write(java.io.OutputStream outputStream)
throws java.io.IOException
RepresentationOutputStream after writing to it as this will be handled by
the Restlet connectors automatically.write in class RepresentationoutputStream - The output stream.java.io.IOExceptionpublic void write(java.nio.channels.WritableByteChannel writableChannel)
throws java.io.IOException
write in class RepresentationwritableChannel - A writable byte channel.java.io.IOExceptionpublic void write(java.io.Writer writer)
throws java.io.IOException
RepresentationWriter after writing to it as this will be handled
by the Restlet connectors automatically.write in class Representationwriter - The characters writer.java.io.IOExceptionCopyright © 2005-2024 Restlet.