public class StreamAdapter
extends java.io.InputStream
ByteBuffer look like an InputStream.| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
FILE_PROTOCOL
The string that indicates the file protocol.
|
static java.lang.String |
UTF8
The string that indicates the UTF8 character encoding.
|
| Constructor and Description |
|---|
StreamAdapter(java.nio.ByteBuffer buffer)
Creates a new instance of this class that wraps the specified buffer as
an
InputStream. |
| Modifier and Type | Method and Description |
|---|---|
int |
available() |
void |
close() |
static java.io.InputStream |
make(java.io.File file)
Returns an input stream on the specified file that is backed by a mapped
byte buffer, making it much faster than a normal
FileInputStream. |
static java.io.InputStream |
make(java.net.URL url)
Returns an input stream for the specified
URL. |
void |
mark(int readlimit) |
boolean |
markSupported() |
int |
read() |
void |
reset() |
static java.io.File |
toFile(java.net.URL url)
Transforms the specified
URL into a File object, if in
fact the URL points to a file. |
static java.net.URL |
toURL(java.io.File file)
Transforms a file into a URL
|
public static final java.lang.String FILE_PROTOCOL
public static final java.lang.String UTF8
public StreamAdapter(java.nio.ByteBuffer buffer)
InputStream.buffer - the buffer to be wrapped; may not be nulljava.lang.NullPointerException - if the specified buffer is nullpublic int available()
throws java.io.IOException
available in class java.io.InputStreamjava.io.IOExceptionpublic int read()
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionpublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.InputStreamjava.io.IOExceptionpublic void mark(int readlimit)
mark in class java.io.InputStreampublic void reset()
throws java.io.IOException
reset in class java.io.InputStreamjava.io.IOExceptionpublic boolean markSupported()
markSupported in class java.io.InputStreampublic static java.io.File toFile(java.net.URL url)
URL into a File object, if in
fact the URL points to a file. That is, if the URL uses
the file:// protocol and is in UTF8 encoding. If the
transformation cannot be done, this method returns null.url - the url to be converted to a file, may not be
nullnull if the
url does not correspond to a file.java.lang.NullPointerException - if the specified URL is nullpublic static java.net.URL toURL(java.io.File file)
file - the file to be transformedjava.lang.NullPointerException - if the specified file is nullpublic static java.io.InputStream make(java.net.URL url)
throws java.io.IOException
URL. This
implementation produces a mapped byte-buffer wrapped as a stream if the
specified URL points to a local file system resource.url - the url to make into an input streamjava.lang.NullPointerException - if the specified URL is nulljava.io.IOException - if there is an IO exception when creating the streampublic static java.io.InputStream make(java.io.File file)
throws java.io.IOException
FileInputStream.file - the file on which to open the streamjava.io.IOException - if there was a io error accessing the fileCopyright © 2011 Massachusetts Institute of Technology. All Rights Reserved.