public class WWIO
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
DEFAULT_CHARACTER_ENCODING
The default character encoding used if none is specified.
|
static java.lang.String |
DELETE_ON_EXIT_PREFIX |
static java.lang.String |
ILLEGAL_FILE_PATH_PART_CHARACTERS |
static int |
MAX_FILE_PATH_LENGTH
The maximum number of characters allowed in a file path.
|
protected static java.util.Map<java.lang.String,java.lang.String> |
mimeTypeToSuffixMap |
protected static java.util.Map<java.lang.String,java.lang.String> |
suffixToMimeTypeMap |
Constructor and Description |
---|
WWIO() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
appendPathPart(java.lang.String firstPart,
java.lang.String secondPart) |
static java.lang.String |
byteBufferToString(java.nio.ByteBuffer buffer,
int length,
java.lang.String encoding)
Create a
String of limited size from a ByteBuffer . |
static java.lang.String |
byteBufferToString(java.nio.ByteBuffer buffer,
java.lang.String encoding)
Create a
String from a ByteBuffer . |
static void |
closeStream(java.lang.Object stream,
java.lang.String name)
Close a stream and catch any
IOException generated in the process. |
static java.net.Proxy |
configureProxy() |
static java.io.File |
convertURIToFile(java.net.URI uri)
Converts a specified URI as to a path in the local file system.
|
static java.io.File |
convertURLToFile(java.net.URL url)
Converts a specified URL as to a path in the local file system.
|
static void |
copyDirectory(java.io.File source,
java.io.File destination,
boolean copySubDirectories) |
static void |
copyFile(java.io.File source,
java.io.File destination) |
static boolean |
deflateBufferToFile(java.nio.ByteBuffer buffer,
java.io.File file) |
static void |
deleteDirectory(java.io.File file) |
static java.lang.String |
formPath(java.lang.String... pathParts) |
static java.io.BufferedInputStream |
getBufferedInputStream(java.io.InputStream is)
Returns a new
BufferedInputStream which wraps the specified InputStream. |
static java.io.File |
getFileForLocalAddress(java.lang.Object src)
Converts several types of addresses to a local file to a
File . |
static java.lang.String |
getFilename(java.lang.String filePath)
Returns the name of the file or directory denoted by the specified path.
|
static java.lang.Object |
getFileOrResourceAsStream(java.lang.String path,
java.lang.Class c) |
static java.io.InputStream |
getInputStreamFromByteBuffer(java.nio.ByteBuffer buffer)
Creates an
InputStream for the contents of a ByteBuffer . |
static java.io.InputStream |
getInputStreamFromString(java.lang.String string)
Creates an
InputStream for the contents of a String . |
static java.io.InputStream |
getInputStreamFromString(java.lang.String string,
java.lang.String encoding)
Creates an
InputStream for the contents of a String . |
static java.lang.String |
getParentFilePath(java.lang.String filePath)
Returns the file path's parent directory path, or null if the file path does not have a parent.
|
static java.lang.String |
getSourcePath(java.lang.Object src)
Returns the specified input source's abstract path, or null if the input source has no path.
|
static java.lang.String |
getSuffix(java.lang.String filePath) |
static java.nio.ByteBuffer |
inflateFileToBuffer(java.io.File file) |
static java.nio.ByteBuffer |
inflateStreamToBuffer(java.io.InputStream inputStream) |
static boolean |
isAncestorOf(java.io.File file,
java.io.File ancestor) |
static boolean |
isContentType(java.io.File file,
java.lang.String... mimeTypes)
Indicates whether a
File contains content of a specified mime type. |
static boolean |
isFileOutOfDate(java.net.URL url,
long expiryTime) |
static boolean |
isLocalJarAddress(java.net.URL jarUrl)
Determines whether a jar URL is a reference to a local jar file or an entry in a local jar file.
|
static java.lang.String[] |
listChildFilenames(java.io.File file,
java.io.FileFilter filter)
Returns an array of strings naming the files and directories in the directory denoted by the specified file, that
satisfy the specified filter.
|
static java.lang.String[] |
listDescendantFilenames(java.io.File file,
java.io.FileFilter filter)
Returns an array of relative file paths naming the files and directories in the directory tree rooted by the
specified file, that satisfy the specified filter.
|
static java.lang.String[] |
listDescendantFilenames(java.io.File file,
java.io.FileFilter filter,
boolean recurseAfterMatch)
Returns an array of relative file paths naming the files and directories in the directory tree rooted by the
specified file, that satisfy the specified filter.
|
protected static void |
listDescendantFilenames(java.io.File parent,
java.lang.String pathname,
java.io.FileFilter filter,
boolean recurseAfterMatch,
java.util.Collection<java.lang.String> matches) |
static java.lang.String[] |
makeCachePathForURL(java.net.URL url) |
static java.lang.String |
makeDataTypeForMimeType(java.lang.String mimeType)
Returns the data type constant corresponding to the specified mime type string.
|
static java.lang.String |
makeMimeTypeForSuffix(java.lang.String suffix)
Returns the mime type string corresponding to the specified file suffix string.
|
static boolean |
makeParentDirs(java.lang.String path)
Ensure that all directories leading the element at the end of a file path exist.
|
static java.lang.String |
makeSuffixForMimeType(java.lang.String mimeType)
Returns the file suffix string corresponding to the specified mime type string.
|
static java.io.File |
makeTempDir()
Create a directory in the computer's temp directory.
|
static java.net.URI |
makeURI(java.lang.Object path)
Creates a URI from an object.
|
static java.net.URL |
makeURL(java.lang.Object path)
Creates a URL from an object.
|
static java.net.URL |
makeURL(java.lang.Object path,
java.lang.String defaultProtocol)
Creates a URL from an object.
|
static java.net.URL |
makeURL(java.lang.String path)
Converts a string to a URL.
|
static java.nio.MappedByteBuffer |
mapFile(java.io.File file)
Maps the specified File's bytes directly into memory as a
MappedByteBuffer . |
static java.nio.MappedByteBuffer |
mapFile(java.io.File file,
java.nio.channels.FileChannel.MapMode mode)
Maps the specified File's bytes directly into memory as a
MappedByteBuffer according to the
specified mode. |
static java.io.InputStream |
openFileOrResourceStream(java.lang.String fileName,
java.lang.Class c)
Opens a file located via an absolute path or a path relative to the classpath.
|
static java.io.Reader |
openReader(java.lang.Object src)
Open a reader on an input source.
|
static java.io.InputStream |
openStream(java.lang.Object src)
Open an
InputStream from a general source. |
static java.nio.ByteBuffer |
readChannelToBuffer(java.nio.channels.ReadableByteChannel channel,
boolean allocateDirect)
Reads all the available bytes from the specified
ReadableByteChannel , returning the
bytes as a ByteBuffer with the current JVM byte order. |
static java.nio.ByteBuffer |
readChannelToBuffer(java.nio.channels.ReadableByteChannel channel,
java.nio.ByteBuffer buffer)
Reads the available bytes from the specified
ReadableByteChannel up to the number of
bytes remaining in the buffer. |
static java.lang.String |
readChannelToString(java.nio.channels.ReadableByteChannel channel,
java.lang.String encoding)
Reads all the available bytes from the specified
ReadableByteChannel , returning the
bytes as a String. |
static java.lang.String |
readCharacterStreamToString(java.io.Reader reader)
Reads all the character stream content from the specified
Reader , returning a the accumulated
content as a String . |
static java.nio.ByteBuffer |
readFileToBuffer(java.io.File file)
Reads all the bytes from the specified
File , returning the bytes as a non-direct ByteBuffer with
the current JVM byte order. |
static java.nio.ByteBuffer |
readFileToBuffer(java.io.File file,
boolean allocateDirect)
Reads all the bytes from the specified
File , returning the bytes as a ByteBuffer with the current
JVM byte order. |
static java.nio.ByteBuffer |
readGZipFileToBuffer(java.io.File gzFile) |
static java.nio.ByteBuffer |
readStreamToBuffer(java.io.InputStream inputStream)
Reads all the available bytes from the specified
InputStream , returning the bytes as a non-direct ByteBuffer with the current JVM byte order. |
static java.nio.ByteBuffer |
readStreamToBuffer(java.io.InputStream inputStream,
boolean allocateDirect)
Reads all the available bytes from the specified
InputStream , returning the bytes as a ByteBuffer
with the current JVM byte order. |
static java.lang.String |
readStreamToString(java.io.InputStream stream,
java.lang.String encoding)
Reads all the available bytes from the specified
InputStream , returning the bytes as a String. |
static java.lang.String |
readTextFile(java.io.File file)
Open and read a text file into
String . |
static java.nio.ByteBuffer |
readURLContentToBuffer(java.net.URL url)
Reads all the bytes from the specified
URL , returning the bytes as a non-direct ByteBuffer with
the current JVM byte order. |
static java.nio.ByteBuffer |
readURLContentToBuffer(java.net.URL url,
boolean allocateDirect)
Reads all the bytes from the specified
URL , returning the bytes as a ByteBuffer with the current
JVM byte order. |
static java.lang.String |
readURLContentToString(java.net.URL url,
java.lang.String encoding)
Reads all the bytes from the specified
, returning the bytes as a String. |
static java.nio.ByteBuffer |
readZipEntryToBuffer(java.io.File zipFile,
java.lang.String entryName) |
static java.lang.String |
replaceIllegalFileNameCharacters(java.lang.String s)
Replaces any illegal filename characters in a specified string with an underscore, "_".
|
static java.lang.String |
replaceSuffix(java.lang.String in,
java.lang.String newSuffix) |
static void |
reverseFloatArray(int pos,
int count,
float[] array) |
static boolean |
saveBuffer(java.nio.ByteBuffer buffer,
java.io.File file) |
static boolean |
saveBuffer(java.nio.ByteBuffer buffer,
java.io.File file,
boolean forceFilesystemWrite) |
static boolean |
saveBufferToGZipFile(java.nio.ByteBuffer buffer,
java.io.File file) |
static boolean |
saveBufferToStream(java.nio.ByteBuffer buffer,
java.io.OutputStream fos) |
static java.io.File |
saveBufferToTempFile(java.nio.ByteBuffer buffer,
java.lang.String suffix) |
static void |
skipBytes(java.io.InputStream is,
int numBytes)
Skip over a specified number of bytes in an input stream.
|
static java.nio.ByteBuffer |
stringToByteBuffer(java.lang.String string,
java.lang.String encoding)
Create a
ByteBuffer from a String . |
static java.lang.String |
stripLeadingSeparator(java.lang.String s) |
static java.lang.String |
stripLeadingZeros(java.lang.String s) |
static java.lang.String |
stripTrailingSeparator(java.lang.String s) |
static void |
writeTextFile(java.lang.String text,
java.io.File file)
Save a
String to a text file. |
protected static final java.lang.String DEFAULT_CHARACTER_ENCODING
public static final java.lang.String DELETE_ON_EXIT_PREFIX
public static final java.lang.String ILLEGAL_FILE_PATH_PART_CHARACTERS
public static final int MAX_FILE_PATH_LENGTH
protected static java.util.Map<java.lang.String,java.lang.String> mimeTypeToSuffixMap
protected static java.util.Map<java.lang.String,java.lang.String> suffixToMimeTypeMap
public static java.lang.String appendPathPart(java.lang.String firstPart, java.lang.String secondPart)
public static java.lang.String byteBufferToString(java.nio.ByteBuffer buffer, int length, java.lang.String encoding)
String
of limited size from a ByteBuffer
.buffer
- the byte buffer to convert.length
- the maximum number of characters to read from the buffer. Must be greater than 0.encoding
- the encoding do use. If null is specified then UTF-8 is used.java.lang.IllegalArgumentException
- if the buffer is null or the length is less than 1.java.nio.charset.IllegalCharsetNameException
- if the specified encoding name is illegal.java.nio.charset.UnsupportedCharsetException
- if no support for the named encoding is available.public static java.lang.String byteBufferToString(java.nio.ByteBuffer buffer, java.lang.String encoding)
String
from a ByteBuffer
.buffer
- the byte buffer to convert.encoding
- the encoding do use. If null is specified then UTF-8 is used.java.lang.IllegalArgumentException
- if the buffer is null.java.nio.charset.IllegalCharsetNameException
- if the specified encoding name is illegal.java.nio.charset.UnsupportedCharsetException
- if no support for the named encoding is available.public static void closeStream(java.lang.Object stream, java.lang.String name)
IOException
generated in the process. This supports any object that
implements the Closeable
interface.stream
- the stream to close. If null, this method does nothing.name
- the name of the stream to place in the log message if an exception is encountered.public static java.net.Proxy configureProxy()
public static java.io.File convertURIToFile(java.net.URI uri)
uri
- the URI to convert to a local file path.java.lang.IllegalArgumentException
- if the url is null.public static java.io.File convertURLToFile(java.net.URL url)
url
- the URL to convert to a local file path.java.lang.IllegalArgumentException
- if the url is null.public static void copyDirectory(java.io.File source, java.io.File destination, boolean copySubDirectories) throws java.io.IOException
java.io.IOException
public static void copyFile(java.io.File source, java.io.File destination) throws java.io.IOException
java.io.IOException
public static boolean deflateBufferToFile(java.nio.ByteBuffer buffer, java.io.File file) throws java.io.IOException
java.io.IOException
public static void deleteDirectory(java.io.File file) throws java.io.IOException
java.io.IOException
public static java.lang.String formPath(java.lang.String... pathParts)
public static java.io.BufferedInputStream getBufferedInputStream(java.io.InputStream is)
BufferedInputStream
which wraps the specified InputStream. If the specified
InputStream is already a BufferedInputStream, this returns the original InputStream cast to a
BufferedInputStream.is
- the InputStream to wrap with a new BufferedInputStream.public static java.io.File getFileForLocalAddress(java.lang.Object src)
File
. Returns null if the source cannot
be converted to a file. The source type may be one of the following: URL
URI
File
String
containing a valid URL description, a valid
URI description, or a valid path to a local file.src
- the source to convert to local file path.java.lang.IllegalArgumentException
- if the source is null or an empty string.public static java.lang.String getFilename(java.lang.String filePath)
filePath
- a file path String.java.lang.IllegalArgumentException
- if the file path is null.public static java.lang.Object getFileOrResourceAsStream(java.lang.String path, java.lang.Class c)
public static java.io.InputStream getInputStreamFromByteBuffer(java.nio.ByteBuffer buffer)
InputStream
for the contents of a ByteBuffer
. The method creates a copy of the
buffer's contents and passes a steam reference to that copy.buffer
- the buffer to create a stream for.InputStream
for the buffer's contents.java.lang.IllegalArgumentException
- if buffer
is null.public static java.io.InputStream getInputStreamFromString(java.lang.String string)
InputStream
for the contents of a String
. The method creates a copy of the string's
contents and passes a steam reference to that copy.string
- the string to create a stream for, encoded in UTF-8.InputStream
for the string's contents.java.lang.IllegalArgumentException
- if string
is null.public static java.io.InputStream getInputStreamFromString(java.lang.String string, java.lang.String encoding)
InputStream
for the contents of a String
. The method creates a copy of the string's
contents and passes a steam reference to that copy.string
- the string to create a stream for.encoding
- the character encoding of the string. UTF-8 is used if null.InputStream
for the string's contents.java.lang.IllegalArgumentException
- if string
is null.public static java.lang.String getParentFilePath(java.lang.String filePath)
filePath
- a file path String.java.lang.IllegalArgumentException
- if the file path is null.public static java.lang.String getSourcePath(java.lang.Object src)
String
File
URL
URI
src
- the input source of one of the above types.java.lang.IllegalArgumentException
- if the source is null.public static java.lang.String getSuffix(java.lang.String filePath)
public static java.nio.ByteBuffer inflateFileToBuffer(java.io.File file) throws java.io.IOException
java.io.IOException
public static java.nio.ByteBuffer inflateStreamToBuffer(java.io.InputStream inputStream) throws java.io.IOException
java.io.IOException
public static boolean isAncestorOf(java.io.File file, java.io.File ancestor)
public static boolean isContentType(java.io.File file, java.lang.String... mimeTypes)
File
contains content of a specified mime type.
Only the filename suffix is consulted to determine the file's content type.file
- the file to test.mimeTypes
- the mime types to test for.public static boolean isFileOutOfDate(java.net.URL url, long expiryTime)
public static boolean isLocalJarAddress(java.net.URL jarUrl)
JarURLConnection
for a description of jar URLs.jarUrl
- the jar URL, in the form jar:public static java.lang.String[] listChildFilenames(java.io.File file, java.io.FileFilter filter)
file
- the directory who's contents to list.filter
- a file filter.java.lang.IllegalArgumentException
- if the file is null.public static java.lang.String[] listDescendantFilenames(java.io.File file, java.io.FileFilter filter)
file
- the directory tree who's contents to list.filter
- a file filter.java.lang.IllegalArgumentException
- if the file is null.public static java.lang.String[] listDescendantFilenames(java.io.File file, java.io.FileFilter filter, boolean recurseAfterMatch)
recurseAfterMatch
is false, then
this ignores any directory branches beneath a matched file. This has the effect of listing the top matches in the
directory tree. The returned paths are relative to the specified file. If the filter is null, then all files and
directories are accepted. This returns null if the specified file is not a directory.file
- the directory tree who's contents to list.filter
- a file filter.recurseAfterMatch
- true to list the contents of directory branches beneath a match; false to ignore
branches beneath a match.java.lang.IllegalArgumentException
- if the file is null.protected static void listDescendantFilenames(java.io.File parent, java.lang.String pathname, java.io.FileFilter filter, boolean recurseAfterMatch, java.util.Collection<java.lang.String> matches)
public static java.lang.String[] makeCachePathForURL(java.net.URL url)
public static java.lang.String makeDataTypeForMimeType(java.lang.String mimeType)
Mime Type | Data Type |
---|---|
application/bil32 | AVKey.FLOAT32 |
application/bil16 | AVKey.INT16 |
application/bil | AVKey.INT16 |
image/bil | AVKey.INT16 |
mimeType
- the mime type who's data type is returned.java.lang.IllegalArgumentException
- if the mime type is null or malformed.public static java.lang.String makeMimeTypeForSuffix(java.lang.String suffix)
suffix
- the suffix who's mime type is returned.java.lang.IllegalArgumentException
- if the file suffix is null.public static boolean makeParentDirs(java.lang.String path)
path
- the path whose directories are vefified to exist or be created. The last element of the path is
ignored.java.lang.IllegalArgumentException
- if the path is null.public static java.lang.String makeSuffixForMimeType(java.lang.String mimeType)
mimeType
- the mime type who's suffix is returned.java.lang.IllegalArgumentException
- if the mime type is null or malformed.public static java.io.File makeTempDir() throws java.io.IOException
java.io.IOException
- if a directory could not be created.java.lang.SecurityException
- if a security manager exists and it does not allow directory creation.public static java.net.URI makeURI(java.lang.Object path)
path
- the object from which to create a URI, typically a string.makeURL(String)
,
makeURL(Object)
,
makeURL(Object, String)
public static java.net.URL makeURL(java.lang.Object path)
path
- the object from which to create a URL, typically a string.makeURL(String)
,
makeURL(Object, String)
public static java.net.URL makeURL(java.lang.Object path, java.lang.String defaultProtocol)
path
- the object from which to create a URL, typically a string.defaultProtocol
- if non-null, a protocol to use if the specified path does not yet include a protocol.makeURL(String)
,
makeURL(Object)
public static java.net.URL makeURL(java.lang.String path)
path
- the string to convert to a URL.makeURL(Object)
,
makeURL(Object, String)
public static java.nio.MappedByteBuffer mapFile(java.io.File file) throws java.io.IOException
MappedByteBuffer
. The file is mapped
in read-only mode; any attempt to modify the contents of the returned MappedByteBuffer causes a ReadOnlyBufferException
.file
- the file to map.java.io.IOException
- if the file cannot be mapped for any reason.public static java.nio.MappedByteBuffer mapFile(java.io.File file, java.nio.channels.FileChannel.MapMode mode) throws java.io.IOException
MappedByteBuffer
according to the
specified mode.
If the mode is FileChannel.MapMode.READ_ONLY
, the file is mapped in read-only mode, and
any attempt to modify the contents of the returned MappedByteBuffer causes a ReadOnlyBufferException
.
If the mode is FileChannel.MapMode.READ_WRITE
, the file is mapped in read-write mode.
Changing the contents of the returned MappedByteBuffer to be eventually propagated to the file. The specified
file must be avialable for both reading and writing.
If the mode is FileChannel.MapMode.PRIVATE
, the file is mapped in copy-on-write mode.
Changing the contents of the returned MappedByteBuffer causes private copies of portions of the buffer to be
created. The specified file must be avialable for both reading and writing.file
- the file to map.mode
- the mapping mode, one of FileChannel.MapMode.READ_ONLY
, FileChannel.MapMode.READ_WRITE
, or FileChannel.MapMode.PRIVATE
.java.io.IOException
- if the file cannot be mapped for any reason.public static java.io.InputStream openFileOrResourceStream(java.lang.String fileName, java.lang.Class c)
fileName
- the path of the file to open, either absolute or relative to the classpath.c
- the class that will be used to find a path relative to the classpath.InputStream
to the open filejava.lang.IllegalArgumentException
- if the file name is null.WWRuntimeException
- if an exception occurs or the file can't be found. The causing exception is
available via this exception's Throwable.initCause(Throwable)
method.public static java.io.Reader openReader(java.lang.Object src) throws java.io.IOException
Reader
InputStream
File
URL
String
src
- the input source of one of the above types.java.io.IOException
- if i/o or other errors occur trying to create the reader.public static java.io.InputStream openStream(java.lang.Object src) throws java.lang.Exception
InputStream
from a general source. The source type may be one of the following: InputStream
URL
URI
File
String
containing a valid URL description or a file or resource name
available on the classpath.src
- the input source of one of the above types.java.lang.IllegalArgumentException
- if the source is null, an empty string, or is not one of the above types.java.lang.Exception
- if the source cannot be opened for any reason.public static java.nio.ByteBuffer readChannelToBuffer(java.nio.channels.ReadableByteChannel channel, boolean allocateDirect) throws java.io.IOException
ReadableByteChannel
, returning the
bytes as a ByteBuffer
with the current JVM byte order. This returns a direct ByteBuffer if allocateDirect
is true, and returns a non-direct ByteBuffer otherwise. Direct buffers are backed by native memory, and may
reside outside of the normal garbage-collected heap. Non-direct buffers are backed by JVM heap memory.channel
- the channel to read.allocateDirect
- true to allocate and return a direct buffer, false to allocate and return a non-direct
buffer.java.lang.IllegalArgumentException
- if the channel is null.java.io.IOException
- if an I/O error occurs.public static java.nio.ByteBuffer readChannelToBuffer(java.nio.channels.ReadableByteChannel channel, java.nio.ByteBuffer buffer) throws java.io.IOException
ReadableByteChannel
up to the number of
bytes remaining in the buffer. Bytes read from the specified channel are copied to the specified ByteBuffer
. Upon returning the specified buffer's limit is set to the number of bytes read, and its position is
set to zero.channel
- the channel to read bytes from.buffer
- the buffer to receive the bytes.java.lang.IllegalArgumentException
- if the channel or the buffer is null.java.io.IOException
- if an I/O error occurs.public static java.lang.String readChannelToString(java.nio.channels.ReadableByteChannel channel, java.lang.String encoding) throws java.io.IOException
ReadableByteChannel
, returning the
bytes as a String. The bytes are interpreted according to the specified encoding, or UTF-8 if no encoding is
specified.channel
- the channel to read.encoding
- the encoding do use. If null is specified then UTF-8 is used.java.lang.IllegalArgumentException
- if the stream
is null.java.io.IOException
- if an I/O error occurs.public static java.lang.String readCharacterStreamToString(java.io.Reader reader) throws java.io.IOException
Reader
, returning a the accumulated
content as a String .reader
- the character stream to read.java.lang.IllegalArgumentException
- if the reader
is null.java.io.IOException
- if an I/O error occurs.public static java.nio.ByteBuffer readFileToBuffer(java.io.File file) throws java.io.IOException
File
, returning the bytes as a non-direct ByteBuffer
with
the current JVM byte order. Non-direct buffers are backed by JVM heap memory.file
- the file to read.java.lang.IllegalArgumentException
- if the file is null.java.io.IOException
- if an I/O error occurs.public static java.nio.ByteBuffer readFileToBuffer(java.io.File file, boolean allocateDirect) throws java.io.IOException
File
, returning the bytes as a ByteBuffer
with the current
JVM byte order. This returns a direct ByteBuffer if allocateDirect is true, and returns a non-direct ByteBuffer
otherwise. Direct buffers are backed by native memory, and may reside outside of the normal garbage-collected
heap. Non-direct buffers are backed by JVM heap memory.file
- the file to read.allocateDirect
- true to allocate and return a direct buffer, false to allocate and return a non-direct
buffer.java.lang.IllegalArgumentException
- if the file is null.java.io.IOException
- if an I/O error occurs.public static java.nio.ByteBuffer readGZipFileToBuffer(java.io.File gzFile) throws java.lang.IllegalArgumentException, java.io.IOException
java.lang.IllegalArgumentException
java.io.IOException
public static java.nio.ByteBuffer readStreamToBuffer(java.io.InputStream inputStream) throws java.io.IOException
InputStream
, returning the bytes as a non-direct ByteBuffer
with the current JVM byte order. Non-direct buffers are backed by JVM heap memory.inputStream
- the stream to read.java.lang.IllegalArgumentException
- if the stream is null.java.io.IOException
- if an I/O error occurs.public static java.nio.ByteBuffer readStreamToBuffer(java.io.InputStream inputStream, boolean allocateDirect) throws java.io.IOException
InputStream
, returning the bytes as a ByteBuffer
with the current JVM byte order. This returns a direct ByteBuffer if allocateDirect is true, and returns a
non-direct ByteBuffer otherwise. Direct buffers are backed by native memory, and may reside outside of the normal
garbage-collected heap. Non-direct buffers are backed by JVM heap memory.inputStream
- the stream to read.allocateDirect
- true to allocate and return a direct buffer, false to allocate and return a non-direct
buffer.java.lang.IllegalArgumentException
- if the stream is null.java.io.IOException
- if an I/O error occurs.public static java.lang.String readStreamToString(java.io.InputStream stream, java.lang.String encoding) throws java.io.IOException
InputStream
, returning the bytes as a String.
The bytes are interpreted according to the specified encoding, or UTF-8 if no encoding is specified.stream
- the stream to read.encoding
- the encoding do use. If null is specified then UTF-8 is used.java.lang.IllegalArgumentException
- if the stream
is null.java.io.IOException
- if an I/O error occurs.public static java.lang.String readTextFile(java.io.File file)
String
.file
- a File
reference to the file to open and read.String
containing the contents of the file.java.lang.IllegalArgumentException
- if the file is null.public static java.nio.ByteBuffer readURLContentToBuffer(java.net.URL url) throws java.io.IOException
URL
, returning the bytes as a non-direct ByteBuffer
with
the current JVM byte order. Non-direct buffers are backed by JVM heap memory.url
- the URL to read.java.lang.IllegalArgumentException
- if the URL is null.java.io.IOException
- if an I/O error occurs.public static java.nio.ByteBuffer readURLContentToBuffer(java.net.URL url, boolean allocateDirect) throws java.io.IOException
URL
, returning the bytes as a ByteBuffer
with the current
JVM byte order. This returns a direct ByteBuffer if allocateDirect is true, and returns a non-direct ByteBuffer
otherwise. Direct buffers are backed by native memory, and may resite outside of the normal garbage-collected
heap. Non-direct buffers are backed by JVM heap memory.url
- the URL to read.allocateDirect
- true to allocate and return a direct buffer, false to allocate and return a non-direct
buffer.java.lang.IllegalArgumentException
- if the URL is null.java.io.IOException
- if an I/O error occurs.public static java.lang.String readURLContentToString(java.net.URL url, java.lang.String encoding) throws java.io.IOException
URL
, returning the bytes as a String. The bytes are
interpreted according to the specified encoding, or UTF-8 if no encoding is specified.url
- the URL to read.encoding
- the encoding do use. If null
is specified then UTF-8 is used. decoded according to the specified
encoding.
java.lang.IllegalArgumentException
- if the url
is null.java.io.IOException
- if an I/O error occurs.java.nio.charset.IllegalCharsetNameException
- if the specified encoding name is illegal.java.nio.charset.UnsupportedCharsetException
- if no support for the named encoding is available.public static java.nio.ByteBuffer readZipEntryToBuffer(java.io.File zipFile, java.lang.String entryName) throws java.io.IOException
java.io.IOException
public static java.lang.String replaceIllegalFileNameCharacters(java.lang.String s)
s
- the string to examine.java.lang.IllegalArgumentException
- if the specified string is null.public static java.lang.String replaceSuffix(java.lang.String in, java.lang.String newSuffix)
public static void reverseFloatArray(int pos, int count, float[] array)
public static boolean saveBuffer(java.nio.ByteBuffer buffer, java.io.File file) throws java.io.IOException
java.io.IOException
public static boolean saveBuffer(java.nio.ByteBuffer buffer, java.io.File file, boolean forceFilesystemWrite) throws java.io.IOException
java.io.IOException
public static boolean saveBufferToGZipFile(java.nio.ByteBuffer buffer, java.io.File file) throws java.io.IOException
java.io.IOException
public static boolean saveBufferToStream(java.nio.ByteBuffer buffer, java.io.OutputStream fos) throws java.io.IOException
java.io.IOException
public static java.io.File saveBufferToTempFile(java.nio.ByteBuffer buffer, java.lang.String suffix) throws java.io.IOException
java.io.IOException
public static void skipBytes(java.io.InputStream is, int numBytes) throws java.io.IOException
is
- the input stream.numBytes
- the number of bytes to skip over.java.lang.IllegalArgumentException
- if the specified input stream is null.java.io.IOException
- is an exception occurs while skipping the bytes.public static java.nio.ByteBuffer stringToByteBuffer(java.lang.String string, java.lang.String encoding) throws java.io.UnsupportedEncodingException
ByteBuffer
from a String
.string
- the string to convert.encoding
- the encoding do use. If null is specified then UTF-8 is used.java.io.UnsupportedEncodingException
- if the specified encoding is not supportedpublic static java.lang.String stripLeadingSeparator(java.lang.String s)
public static java.lang.String stripLeadingZeros(java.lang.String s)
public static java.lang.String stripTrailingSeparator(java.lang.String s)
public static void writeTextFile(java.lang.String text, java.io.File file)
String
to a text file.text
- the String
to write to the file.file
- a File
reference to the file to create.java.lang.IllegalArgumentException
- if the text string or file is null.