public final class JkUtilsIO
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
JkUtilsIO.StreamGobbler
Runs a thread copying all data from the specified input stream to sepecified output streams.
|
Modifier and Type | Method and Description |
---|---|
static <T> T |
cloneBySerialization(java.lang.Object objectToClone,
java.lang.ClassLoader targetClassLoader)
Serializes an object to the current classloader and unserializes it in
the specified classloader.
|
static void |
closeifClosable(java.lang.Object closeable)
Closes the specified closeable object, ignoring any exceptions.
|
static void |
closeOrFail(java.io.Closeable... closeables)
Closes the specified closeable object, ignoring any exceptions.
|
static void |
closeQuietly(java.io.Closeable... closeables)
Closes the specified closeable object, ignoring any exceptions.
|
static void |
closeQuietly(java.util.zip.ZipFile... zipFiles)
Same as
ZipFile.close() but throwing only unchecked exceptions. |
static void |
copy(java.io.InputStream in,
java.io.OutputStream out)
Copies the content of the given input getOutputStream to a specified output
getOutputStream.
|
static java.nio.file.Path |
copyUrlContentToCacheFile(java.net.URL url,
java.io.PrintStream report,
java.nio.file.Path cacheDir)
Copies the content of an url in a cache file.
|
static void |
copyUrlToFile(java.net.URL url,
java.nio.file.Path file)
Copies the content of the given url to the specified file.
|
static java.lang.Object |
deserialize(java.io.InputStream inputStream)
Deserializes the content of the specified input getOutputStream to a Java object.
|
static java.lang.Object |
deserialize(java.io.InputStream inputStream,
java.lang.ClassLoader classLoader)
Deserialises the content of a given input file to a Java object loaded in
the specified classloader.
|
static java.lang.Object |
deserialize(java.nio.file.Path file)
Deserializes the content of the specified file to a Java object.
|
static java.io.FileInputStream |
inputStream(java.io.File file)
Same as
FileInputStream constructor but throwing unchecked
exceptions. |
static java.io.InputStream |
inputStream(java.net.URL file)
Same as
URL.openStream() but throwing only unchecked exceptions. |
static JkUtilsIO.StreamGobbler |
newStreamGobbler(java.io.InputStream is,
java.io.OutputStream... outputStreams)
Returns a thread that write each data read to the specified input
getOutputStream to the specified output getOutputStream.
|
static java.io.OutputStream |
nopOuputStream()
Creates a no-op outputStream.
|
static java.io.PrintStream |
nopPrintStream()
Creates a no-op print getOutputStream.
|
static java.io.FileOutputStream |
outputStream(java.io.File file,
boolean append)
Same as
FileOutputStream constructor but throwing unchecked
exceptions. |
static int |
read(java.io.InputStream inputStream)
Equivalent to
InputStream.read() but throwing only unchecked
exceptions. |
static java.lang.String |
read(java.net.URL url)
Returns the content of the given url as a string.
|
static java.util.List<java.lang.String> |
readAsLines(java.io.InputStream in)
Returns the content of the specified input getOutputStream, line by line.
|
static java.lang.String |
readAsString(java.io.InputStream in)
Returns the content of the given input getOutputStream as a single string.
|
static void |
serialize(java.lang.Object object,
java.io.OutputStream outputStream)
Serializes a given Java object to the specified output getOutputStream.
|
static void |
serialize(java.lang.Object object,
java.nio.file.Path file)
Serializes a given Java object to the specified file.
|
public static java.io.PrintStream nopPrintStream()
public static java.io.OutputStream nopOuputStream()
public static void closeQuietly(java.io.Closeable... closeables)
public static void closeifClosable(java.lang.Object closeable)
public static void closeOrFail(java.io.Closeable... closeables)
public static java.io.FileInputStream inputStream(java.io.File file)
FileInputStream
constructor but throwing unchecked
exceptions.public static java.io.FileOutputStream outputStream(java.io.File file, boolean append)
FileOutputStream
constructor but throwing unchecked
exceptions.public static java.io.InputStream inputStream(java.net.URL file)
URL.openStream()
but throwing only unchecked exceptions.public static int read(java.io.InputStream inputStream)
InputStream.read()
but throwing only unchecked
exceptions.public static java.util.List<java.lang.String> readAsLines(java.io.InputStream in)
public static java.lang.String read(java.net.URL url)
public static java.lang.String readAsString(java.io.InputStream in)
public static void closeQuietly(java.util.zip.ZipFile... zipFiles)
ZipFile.close()
but throwing only unchecked exceptions.public static java.nio.file.Path copyUrlContentToCacheFile(java.net.URL url, java.io.PrintStream report, java.nio.file.Path cacheDir)
public static void copyUrlToFile(java.net.URL url, java.nio.file.Path file)
public static void copy(java.io.InputStream in, java.io.OutputStream out)
public static void serialize(java.lang.Object object, java.nio.file.Path file)
public static void serialize(java.lang.Object object, java.io.OutputStream outputStream)
public static java.lang.Object deserialize(java.nio.file.Path file)
public static java.lang.Object deserialize(java.io.InputStream inputStream)
public static java.lang.Object deserialize(java.io.InputStream inputStream, java.lang.ClassLoader classLoader)
public static <T> T cloneBySerialization(java.lang.Object objectToClone, java.lang.ClassLoader targetClassLoader)
public static JkUtilsIO.StreamGobbler newStreamGobbler(java.io.InputStream is, java.io.OutputStream... outputStreams)