public final class JkUtilsIO
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
JkUtilsIO.JkStreamGobbler
Runs a thread copying all data from the specified input stream to specified 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 deserializes 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.lang.String url,
java.nio.file.Path 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 <T> T |
deserialize(java.io.InputStream inputStream)
Deserializes the content of the specified input getOutputStream to a Java object.
|
static <T> T |
deserialize(java.io.InputStream inputStream,
java.lang.ClassLoader classLoader)
Deserializes the content of a given input file to a Java object loaded in
the specified classloader.
|
static <T> T |
deserialize(java.nio.file.Path file)
Deserializes the content of the specified file to a Java object.
|
static void |
flush(java.io.OutputStream outputStream) |
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 boolean |
isHttpOrHttps(java.net.URL url) |
static JkUtilsIO.JkStreamGobbler |
newStreamGobbler(java.lang.Process process,
java.io.InputStream is,
java.io.OutputStream... outputStreams)
Returns a thread that write each data read to the specified inputStream
to the specified output getOutputStream.
|
static java.io.OutputStream |
nopOutputStream()
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.
|
static java.net.URI |
toUri(java.lang.String uri) |
static java.net.URL |
toUrl(java.lang.String url) |
static java.net.URL |
toUrl(java.net.URI uri) |
static void |
write(java.io.OutputStream outputStream,
byte[] bytes) |
public static java.io.PrintStream nopPrintStream()
public static java.io.OutputStream nopOutputStream()
public static java.net.URL toUrl(java.lang.String url)
public static java.net.URL toUrl(java.net.URI uri)
public static boolean isHttpOrHttps(java.net.URL url)
public static java.net.URI toUri(java.lang.String uri)
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 copyUrlToFile(java.lang.String url, java.nio.file.Path file)
public static void copy(java.io.InputStream in, java.io.OutputStream out)
public static void write(java.io.OutputStream outputStream, byte[] bytes)
public static void flush(java.io.OutputStream outputStream)
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 <T> T deserialize(java.nio.file.Path file)
public static <T> T deserialize(java.io.InputStream inputStream)
public static <T> T 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.JkStreamGobbler newStreamGobbler(java.lang.Process process, java.io.InputStream is, java.io.OutputStream... outputStreams)