E - public interface Resource<E>
| 限定符和类型 | 方法和说明 |
|---|---|
long |
contentLength()
Determine the content length for this resource.
|
boolean |
exists()
Determine whether this resource actually exists in physical form.
|
InputStream |
getInputStream()
Return an
InputStream for the content of an underlying resource. |
E |
getRealResource() |
boolean |
isReadable()
Indicate whether non-empty contents of this resource can be read via
getInputStream(). |
ReadableByteChannel |
readableChannel()
Return a
ReadableByteChannel. |
E getRealResource()
InputStream getInputStream() throws IOException
InputStream for the content of an underlying resource.
It is expected that each call creates a fresh stream.
This requirement is particularly important when you consider an API such
as JavaMail, which needs to be able to read the stream multiple times when
creating mail attachments. For such a use case, it is required
that each getInputStream() call returns a fresh stream.
null)FileNotFoundException - if the underlying resource doesn't existIOException - if the content stream could not be openedboolean exists()
This method performs a definitive existence check, whereas the
existence of a Resource handle only guarantees a valid
descriptor handle.
boolean isReadable()
getInputStream().
Will be true for typical resource descriptors that exist
since it strictly implies exists() semantics as of 5.1.
Note that actual content reading may still fail when attempted.
However, a value of false is a definitive indication
that the resource content cannot be read.
getInputStream(),
exists()ReadableByteChannel readableChannel() throws IOException
ReadableByteChannel.
It is expected that each call creates a fresh channel.
The default implementation returns Channels.newChannel(InputStream)
with the result of getInputStream().
null)FileNotFoundException - if the underlying resource doesn't existIOException - if the content channel could not be openedgetInputStream()long contentLength()
IOException - if the resource cannot be resolved
(in the file system or as some other known physical resource type)Copyright © 2020. All rights reserved.