|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.tenduke.io.IOUtils
public final class IOUtils
Static utility methods for IO-related functionality.
| Field Summary | |
|---|---|
static int |
DEFAULT_BUFFER_SIZE
Default buffer size to use for reads and writes. |
| Method Summary | |
|---|---|
static long |
copy(java.io.File input,
java.io.OutputStream output)
Copy file content from input file to output stream. |
static long |
copy(java.io.InputStream input,
java.io.OutputStream output)
Copy bytes from input file to output writer. |
static long |
copy(java.io.InputStream input,
java.io.OutputStream output,
int bufferSize)
Copy bytes from input file to output writer. |
static long |
copy(java.lang.String filePath,
java.io.OutputStream output)
Copy a file's content to output stream. |
static long |
fileToWriter(java.io.File input,
java.io.Writer output)
Copy bytes from input to output assuming UTF-8 character set. |
static long |
fileToWriter(java.io.File input,
java.io.Writer output,
int bufferSize)
Copy characters from input to output, assuming UTF-8 character set. |
static long |
fileToWriter(java.io.File input,
java.io.Writer output,
java.lang.String charsetName)
Copy bytes from input to output. |
static long |
fileToWriter(java.io.File input,
java.io.Writer output,
java.lang.String charsetName,
int bufferSize)
Copy characters from input to output. |
static java.nio.ByteBuffer |
getByteBufferFromString(java.lang.String message,
java.lang.String encoding)
Converts a string to ByteBuffer using the specified encoding. |
static java.io.InputStream |
getInputStream(java.net.URI uri)
Gets an input stream associated with the given URI. |
static java.io.InputStream |
getInputStreamSafe(java.net.URI uri)
|
static java.io.OutputStream |
getOutputStream(java.net.URI uri)
Gets an output stream associated with the given URI. |
static java.io.OutputStream |
getOutputStreamSafe(java.net.URI uri)
|
static boolean |
isSupportedScheme(java.net.URI uri)
Checks if the given URI has supported scheme, which are documented in BuiltInScheme enumeration. |
static java.util.Date |
lastModified(java.net.URI uri)
Date when content pointed by URI was last modified. |
static java.lang.String |
readerToString(java.io.Reader reader)
Read all contents returned by a Reader to String. |
static java.lang.String |
readTextStream(java.io.InputStream inputStream)
Reads text from input stream using UTF-8 character set. |
static java.net.URI |
resolveRelativeUri(java.lang.String base,
java.lang.String relative)
Resolves a URI relative to a base URI. |
static java.net.URI |
resolveRelativeUri(java.net.URI base,
java.net.URI relative)
Resolves a URI relative to a base URI. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int DEFAULT_BUFFER_SIZE
| Method Detail |
|---|
public static long copy(java.io.File input,
java.io.OutputStream output)
throws java.io.IOException
input - The input file to copy.output - the output writer to copy to.
java.io.IOException - for any IO errors while copying input to output.
public static long copy(java.io.InputStream input,
java.io.OutputStream output)
throws java.io.IOException
input - The input file to copy.output - the output writer to copy to.
java.io.IOException - for any IO errors while copying input to output.
public static long copy(java.io.InputStream input,
java.io.OutputStream output,
int bufferSize)
throws java.io.IOException
input - The input file to copy.output - the output writer to copy to.bufferSize - size of buffer to use for copy operation.
java.io.IOException - for any IO errors while copying input to output.
public static long copy(java.lang.String filePath,
java.io.OutputStream output)
throws java.io.IOException
filePath - The path to the file to copy into output.output - The output stream to copy to.
java.io.IOException - for error opening or reading file or writing output.
public static long fileToWriter(java.io.File input,
java.io.Writer output)
throws java.io.UnsupportedEncodingException
input - The input file to copy.output - the output writer to copy to.
java.io.UnsupportedEncodingException - if given character set is not supported.
public static long fileToWriter(java.io.File input,
java.io.Writer output,
int bufferSize)
throws java.io.UnsupportedEncodingException
input - The input file to copy.output - the output writer to copy to.bufferSize - Size of read buffer.
java.io.UnsupportedEncodingException - if given character set is not supported.
public static long fileToWriter(java.io.File input,
java.io.Writer output,
java.lang.String charsetName)
throws java.io.UnsupportedEncodingException
input - The input file to copy.output - the output writer to copy to.charsetName - Character set to use.
java.io.UnsupportedEncodingException - if given character set is not supported.
public static long fileToWriter(java.io.File input,
java.io.Writer output,
java.lang.String charsetName,
int bufferSize)
throws java.io.UnsupportedEncodingException
input - The input file to copy.output - the output writer to copy to.charsetName - Character set to use.bufferSize - Size of read buffer.
java.io.UnsupportedEncodingException - if given character set is not supported.
public static java.nio.ByteBuffer getByteBufferFromString(java.lang.String message,
java.lang.String encoding)
throws java.io.UnsupportedEncodingException
message - string to converted to byte bufferencoding - character encoding
java.io.UnsupportedEncodingException - if requested encoding is not available.
public static java.io.InputStream getInputStream(java.net.URI uri)
throws java.io.IOException
Gets an input stream associated with the given URI. It is client's responsibility to close the stream.
If the uri has no scheme defined, or if the scheme is empty, the file scheme is assumed. The
uri passed to the corresponding scheme handler is not modified to contain the scheme, however.
uri - URI for which the input stream is opened
java.io.IOException - If errors occurred while trying to open the stream
exist or it is not readypublic static java.io.InputStream getInputStreamSafe(java.net.URI uri)
public static java.io.OutputStream getOutputStream(java.net.URI uri)
throws java.io.IOException
Gets an output stream associated with the given URI. It is client's responsibility to close the stream.
If the uri has no scheme defined, or if the scheme is empty, the file scheme is assumed. The
uri passed to the corresponding scheme handler is not modified to contain the scheme, however.
uri - URI for which the output stream is opened
java.io.IOException - If errors occurred while trying to open the stream
exist or it is not readypublic static java.io.OutputStream getOutputStreamSafe(java.net.URI uri)
public static boolean isSupportedScheme(java.net.URI uri)
BuiltInScheme enumeration.
uri - URI
true for supported schemes, false otherwise or if a scheme does not exist in the given
uripublic static java.util.Date lastModified(java.net.URI uri)
uri - URI for which last modifed date is retrieved
null if the scheme handler was not found or null was returned from the scheme handler
public static java.lang.String readerToString(java.io.Reader reader)
throws java.io.IOException
reader - Reader from which to read.
java.io.IOException - Thrown if I/O error occurs.public static java.lang.String readTextStream(java.io.InputStream inputStream)
inputStream - Input stream
inputStream until end
public static java.net.URI resolveRelativeUri(java.lang.String base,
java.lang.String relative)
throws java.net.URISyntaxException
Resolves a URI relative to a base URI.
base - Base URI.relative - URI relative to the base URI.
java.net.URISyntaxException - Throw if one of the URIs given as parameters is invalid.
public static java.net.URI resolveRelativeUri(java.net.URI base,
java.net.URI relative)
Resolves a URI relative to a base URI.
This method uses the resolve(URI uri) method from Java URI class except that the root URI scheme
is ignored when doing the resolving. This allows using scheme and relative path in the base URI, e.g.,
resolving a URI conf.xml against root URI file:conf/ resolves to file:conf/conf.xml.
By URI standard the file:conf/ is opaque and thus conf.xml would be the resolving result if the
scheme was not ignored.
Using an absolute URI, i.e. URI with scheme, in relative returns the original relative.
base - Base URI.relative - URI relative to the base URI.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||