public final class BioUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static void |
copy(InputStream inputStream,
OutputStream outputStream)
Copies an input stream to an output stream.
|
static void |
copy(InputStream inputStream,
RandomAccessFile randomAccessFile)
Copies an input stream to a random access file.
|
static void |
copy(Reader reader,
Writer writer)
Copies characters from a reader to a writer.
|
static boolean |
delete(File file)
Deletes an individual file or an empty directory.
|
static boolean |
delete(File file,
boolean recursive)
Deletes an individual file or a directory.
|
static boolean |
delete(File file,
boolean recursive,
boolean garbageCollect)
Deletes an individual file or a directory.
|
static long |
exhaust(InputStream input)
Exhaust the content of the representation by reading it and silently
discarding anything read.
|
static long |
getAvailableSize(Representation representation)
Returns the size effectively available.
|
static Reader |
getReader(InputStream stream,
CharacterSet characterSet)
Returns a reader from an input stream and a character set.
|
static Reader |
getReader(WriterRepresentation representation)
Returns a reader from a writer representation.Internally, it uses a
writer thread and a pipe stream.
|
static InputStream |
getStream(Reader reader,
CharacterSet characterSet)
Returns an input stream based on a given character reader.
|
static InputStream |
getStream(Representation representation)
Returns an input stream based on the given representation's content and
its write(OutputStream) method.
|
static OutputStream |
getStream(Writer writer,
CharacterSet characterSet)
Returns an output stream based on a given writer.
|
static String |
getText(Representation representation)
Converts the representation to a string value.
|
static Writer |
getWriter(OutputStream outputStream,
CharacterSet characterSet)
Returns a writer to the given output stream, using the given character
set for encoding to bytes.
|
static byte[] |
toByteArray(char[] chars)
Converts a char array into a byte array using the default character set.
|
static byte[] |
toByteArray(char[] chars,
String charsetName)
Converts a char array into a byte array using the provided character set.
|
static char[] |
toCharArray(byte[] bytes)
Converts a byte array into a character array using the default character
set.
|
static char[] |
toCharArray(byte[] bytes,
String charsetName)
Converts a byte array into a character array using the default character
set.
|
static String |
toHexString(byte[] byteArray)
Converts a byte array into an hexadecimal string.
|
static String |
toString(InputStream inputStream)
Converts an input stream to a string.
As this method uses the InputstreamReader class, the default character set is used for decoding the input stream. |
static String |
toString(InputStream inputStream,
CharacterSet characterSet)
Converts an input stream to a string using the specified character set
for decoding the input stream.
|
static String |
toString(Reader reader)
Converts a reader to a string.
|
public static void copy(InputStream inputStream, OutputStream outputStream) throws IOException
inputStream - The input stream.outputStream - The output stream.IOExceptionpublic static void copy(InputStream inputStream, RandomAccessFile randomAccessFile) throws IOException
inputStream - The input stream.randomAccessFile - The random access file.IOExceptionpublic static void copy(Reader reader, Writer writer) throws IOException
reader - The reader.writer - The writer.IOExceptionpublic static boolean delete(File file)
file - The individual file or directory to delete.public static boolean delete(File file, boolean recursive)
file - The individual file or directory to delete.recursive - Indicates if directory with content should be deleted
recursively as well.public static boolean delete(File file, boolean recursive, boolean garbageCollect)
file - The individual file or directory to delete.recursive - Indicates if directory with content should be deleted
recursively as well.garbageCollect - Indicates if the garbage collector should be run.public static long exhaust(InputStream input) throws IOException
input - The input stream to exhaust.IOExceptionpublic static long getAvailableSize(Representation representation)
Representation.getSize() if no range is defined, otherwise it
returns the size of the range using Range.getSize().representation - The representation to evaluate.public static Reader getReader(InputStream stream, CharacterSet characterSet) throws UnsupportedEncodingException
stream - The input stream.characterSet - The character set. May be null.UnsupportedEncodingException - if a character set is given, but not supportedpublic static Reader getReader(WriterRepresentation representation) throws IOException
representation - The representation to read from.IOExceptionpublic static OutputStream getStream(Writer writer, CharacterSet characterSet)
writer - The writer.characterSet - The character set used to write on the output stream.public static InputStream getStream(Reader reader, CharacterSet characterSet)
reader - The character reader.characterSet - The stream character set.public static InputStream getStream(Representation representation)
representation - the representation to get the OutputStream
from.public static String getText(Representation representation) throws IOException
representation - The representation to convert.IOExceptionpublic static Writer getWriter(OutputStream outputStream, CharacterSet characterSet)
outputStream - The target output stream.characterSet - The character set for encoding.public static byte[] toByteArray(char[] chars)
chars - The source characters.public static byte[] toByteArray(char[] chars,
String charsetName)
chars - The source characters.charsetName - The character set to use.public static char[] toCharArray(byte[] bytes)
bytes - The source bytes.public static char[] toCharArray(byte[] bytes,
String charsetName)
bytes - The source bytes.charsetName - The character set to use.public static String toHexString(byte[] byteArray)
byteArray - The byte array to convert.public static String toString(InputStream inputStream)
inputStream - The input stream.InputStreamReader,
toString(InputStream, CharacterSet)public static String toString(InputStream inputStream, CharacterSet characterSet)
inputStream - The input stream.characterSet - The character setInputStreamReaderpublic static String toString(Reader reader)
reader - The characters reader.InputStreamReaderCopyright © 2005–2015. All rights reserved.