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, getRegistration, hasKnownSize, isAvailable, isEmpty, isSelectable, isTransient, setAvailable, setDigest, setDisposition, setExpirationDate, setListener, setRange, setSize, setTransient
getModificationDate, getTag, setModificationDate, setTag
createClientInfo, equals, getCharacterSet, getEncodings, getLanguages, getLocationRef, getMediaType, hashCode, includes, isCompatible, setCharacterSet, setEncodings, setLanguages, setLocationRef, setLocationRef, setMediaType, toString
public FileRepresentation(java.io.File file, MediaType mediaType)
file
file
- 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)
path
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.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 Representation
java.io.IOException
public java.io.File getFile()
public java.io.Reader getReader() throws java.io.IOException
Representation
getReader
in class Representation
java.io.IOException
public long getSize()
Representation
Representation.getAvailableSize()
method.getSize
in class Representation
Representation.isEmpty()
public java.io.FileInputStream getStream() throws java.io.IOException
Representation
getStream
in class Representation
java.io.IOException
public java.lang.String getText() throws java.io.IOException
getStream()
. This stream is
closed once fully read.getText
in class Representation
java.io.IOException
public boolean isAutoDeleting()
public void release()
release
in class Representation
public 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
Representation
OutputStream
after writing to it as this will be handled by
the Restlet connectors automatically.write
in class Representation
outputStream
- The output stream.java.io.IOException
public void write(java.nio.channels.WritableByteChannel writableChannel) throws java.io.IOException
write
in class Representation
writableChannel
- A writable byte channel.java.io.IOException
public void write(java.io.Writer writer) throws java.io.IOException
Representation
Writer
after writing to it as this will be handled
by the Restlet connectors automatically.write
in class Representation
writer
- The characters writer.java.io.IOException
Copyright © 2005-2024 Restlet.