Package aQute.lib.io
Class IO
- java.lang.Object
-
- aQute.lib.io.IO
-
public class IO extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static java.io.File
home
static java.io.File
JAVA_HOME
static java.io.OutputStream
nullStream
static java.io.Writer
nullWriter
static java.io.File
work
-
Constructor Summary
Constructors Constructor Description IO()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
absolutePath(java.io.File file)
static java.lang.String
absolutePath(java.nio.file.Path path)
static java.io.Writer
appendableToWriter(java.lang.Appendable appendable)
static java.lang.Throwable
close(java.io.Closeable in)
static java.lang.Throwable
close(java.lang.AutoCloseable in)
static boolean
closeAll(java.lang.Object... toBeClosed)
Will iterate over the given toBeClose and silently close any object that implements AutoCloseable.static java.lang.String
collect(java.io.File file)
static java.lang.String
collect(java.io.File file, java.lang.String encoding)
static java.lang.String
collect(java.io.File file, java.nio.charset.Charset encoding)
static java.lang.String
collect(java.io.InputStream in)
static java.lang.String
collect(java.io.InputStream in, java.lang.String encoding)
static java.lang.String
collect(java.io.InputStream in, java.nio.charset.Charset encoding)
static java.lang.String
collect(java.io.Reader r)
static java.lang.String
collect(java.lang.String path)
static java.lang.String
collect(java.net.URL url)
static java.lang.String
collect(java.net.URL url, java.lang.String encoding)
static java.lang.String
collect(java.net.URL url, java.nio.charset.Charset encoding)
static java.lang.String
collect(java.nio.ByteBuffer bb, java.nio.charset.Charset encoding)
static java.lang.String
collect(java.nio.file.Path path)
static java.lang.String
collect(java.nio.file.Path path, java.nio.charset.Charset encoding)
static java.io.File
copy(byte[] data, java.io.File file)
static java.io.OutputStream
copy(byte[] data, java.io.OutputStream out)
static java.io.Writer
copy(byte[] data, java.io.Writer w)
static java.nio.file.Path
copy(byte[] data, java.nio.file.Path path)
static java.io.File
copy(java.io.File src, java.io.File tgt)
static java.io.OutputStream
copy(java.io.File file, java.io.OutputStream out)
static java.security.MessageDigest
copy(java.io.File file, java.security.MessageDigest md)
static byte[]
copy(java.io.InputStream in, byte[] data)
static byte[]
copy(java.io.InputStream in, byte[] data, int off, int len)
static ByteBufferOutputStream
copy(java.io.InputStream in, ByteBufferOutputStream out)
static java.io.DataOutput
copy(java.io.InputStream in, java.io.DataOutput out)
static java.io.File
copy(java.io.InputStream in, java.io.File file)
static java.io.OutputStream
copy(java.io.InputStream in, java.io.OutputStream out)
static java.io.OutputStream
copy(java.io.InputStream in, java.io.OutputStream out, int limit)
static java.io.Writer
copy(java.io.InputStream in, java.io.Writer w)
static java.io.Writer
copy(java.io.InputStream in, java.io.Writer w, java.lang.String charset)
static java.io.Writer
copy(java.io.InputStream in, java.io.Writer w, java.nio.charset.Charset charset)
static java.net.URL
copy(java.io.InputStream in, java.net.URL url)
static java.net.URL
copy(java.io.InputStream in, java.net.URL url, java.lang.String method)
static java.nio.ByteBuffer
copy(java.io.InputStream in, java.nio.ByteBuffer bb)
static java.nio.channels.WritableByteChannel
copy(java.io.InputStream in, java.nio.channels.WritableByteChannel out)
static java.nio.file.Path
copy(java.io.InputStream in, java.nio.file.Path path)
static java.security.MessageDigest
copy(java.io.InputStream in, java.security.MessageDigest md)
static java.io.OutputStream
copy(java.io.Reader r, java.io.OutputStream out)
static java.io.OutputStream
copy(java.io.Reader r, java.io.OutputStream out, java.lang.String charset)
static java.io.OutputStream
copy(java.io.Reader r, java.io.OutputStream out, java.nio.charset.Charset charset)
static java.io.Writer
copy(java.io.Reader r, java.io.Writer w)
static java.io.File
copy(java.net.URLConnection conn, java.io.File file)
static java.security.MessageDigest
copy(java.net.URLConnection conn, java.security.MessageDigest md)
static java.io.File
copy(java.net.URL url, java.io.File file)
static java.security.MessageDigest
copy(java.net.URL url, java.security.MessageDigest md)
static java.io.DataOutput
copy(java.nio.ByteBuffer bb, java.io.DataOutput out)
static java.io.OutputStream
copy(java.nio.ByteBuffer bb, java.io.OutputStream out)
static java.io.OutputStream
copy(java.nio.channels.ReadableByteChannel in, java.io.OutputStream out)
static java.nio.channels.WritableByteChannel
copy(java.nio.channels.ReadableByteChannel in, java.nio.channels.WritableByteChannel out)
static java.security.MessageDigest
copy(java.nio.channels.ReadableByteChannel in, java.security.MessageDigest md)
static java.io.OutputStream
copy(java.nio.file.Path path, java.io.OutputStream out)
static java.nio.file.Path
copy(java.nio.file.Path src, java.nio.file.Path tgt)
static java.security.MessageDigest
copy(java.nio.file.Path path, java.security.MessageDigest md)
static java.io.OutputStream
copy(java.util.Collection<?> c, java.io.OutputStream out)
static boolean
createSymbolicLink(java.io.File link, java.io.File target)
static boolean
createSymbolicLink(java.nio.file.Path link, java.nio.file.Path target)
static boolean
createSymbolicLinkOrCopy(java.io.File link, java.io.File target)
Creates a symbolic link fromlink
to thetarget
, or copiestarget
tolink
if running on Windows.static boolean
createSymbolicLinkOrCopy(java.nio.file.Path link, java.nio.file.Path target)
Creates a symbolic link fromlink
to thetarget
, or copiestarget
tolink
if running on Windows.static java.io.File
createTempFile(java.io.File directory, java.lang.String pattern, java.lang.String suffix)
Create a temporary file.static java.nio.CharBuffer
decode(java.nio.ByteBuffer bb, java.nio.charset.Charset encoding)
static void
delete(java.io.File file)
Deletes the specified file.static void
delete(java.nio.file.Path path)
Deletes the specified path.static void
deleteContent(java.io.File dir)
Deletes the specified content of the given directory.static void
deleteWithException(java.io.File file)
Deletes the specified file.static void
deleteWithException(java.nio.file.Path path)
Deletes the specified path.static long
drain(java.io.InputStream in)
static java.nio.ByteBuffer
encode(java.lang.String s, java.nio.charset.Charset encoding)
static java.nio.ByteBuffer
encode(java.nio.CharBuffer cb, java.nio.charset.Charset encoding)
static java.text.Collator
fileCollator()
static <FILE> java.util.Comparator<FILE>
fileComparator(java.util.function.Function<? super FILE,? extends java.lang.String> keyExtractor)
static java.io.File
getBasedFile(java.io.File base, java.lang.String file)
static java.nio.file.Path
getBasedPath(java.nio.file.Path base, java.lang.String file)
static java.lang.String
getExtension(java.lang.String fileName, java.lang.String deflt)
static java.io.File
getFile(java.io.File base, java.lang.String file)
static java.io.File
getFile(java.lang.String file)
static java.lang.String
getJavaExecutablePath(java.lang.String name)
static java.nio.file.Path
getPath(java.lang.String file)
static java.nio.file.Path
getPath(java.nio.file.Path base, java.lang.String file)
static void
initialize(java.io.File dir)
Deletes and creates directoriesstatic boolean
isSymbolicLink(java.io.File link)
static boolean
isSymbolicLink(java.nio.file.Path link)
static boolean
isWindows()
static java.util.List<java.lang.String>
list(java.io.File dir)
static java.util.List<java.lang.String>
list(java.io.File dir, java.util.function.BiPredicate<? super java.io.File,? super java.lang.String> filter)
static java.util.List<java.lang.String>
list(java.nio.file.Path dir)
static java.util.List<java.lang.String>
list(java.nio.file.Path dir, java.util.function.BiPredicate<? super java.nio.file.Path,? super java.lang.String> filter)
static java.util.List<java.lang.String>
list(java.nio.file.Path dir, java.util.function.Predicate<? super java.nio.file.Path> filter)
static java.util.List<java.io.File>
listFiles(java.io.File dir)
static java.util.List<java.io.File>
listFiles(java.io.File dir, java.util.function.BiPredicate<? super java.io.File,? super java.lang.String> filter)
static java.util.List<java.nio.file.Path>
listPaths(java.nio.file.Path dir)
static java.util.List<java.nio.file.Path>
listPaths(java.nio.file.Path dir, java.util.function.BiPredicate<? super java.nio.file.Path,? super java.lang.String> filter)
static java.util.List<java.nio.file.Path>
listPaths(java.nio.file.Path dir, java.util.function.Predicate<? super java.nio.file.Path> filter)
static java.util.stream.Stream<java.lang.String>
listStream(java.io.File dir)
static java.util.stream.Stream<java.lang.String>
listStream(java.io.File dir, java.util.function.BiPredicate<? super java.io.File,? super java.lang.String> filter)
static java.util.stream.Stream<java.lang.String>
listStream(java.nio.file.Path dir)
static java.util.stream.Stream<java.lang.String>
listStream(java.nio.file.Path dir, java.util.function.BiPredicate<? super java.nio.file.Path,? super java.lang.String> filter)
static java.util.stream.Stream<java.lang.String>
listStream(java.nio.file.Path dir, java.util.function.Predicate<? super java.nio.file.Path> filter)
static java.io.File
mkdirs(java.io.File dir)
static java.nio.file.Path
mkdirs(java.nio.file.Path dir)
static java.lang.String
normalizePath(java.io.File file)
static java.lang.String
normalizePath(java.lang.String path)
static java.lang.String
normalizePath(java.nio.file.Path path)
static java.io.OutputStream
outputStream(java.io.File file)
static java.io.OutputStream
outputStream(java.nio.file.Path path)
static byte[]
read(java.io.File file)
static byte[]
read(java.io.InputStream in)
static byte[]
read(java.net.URL url)
static byte[]
read(java.nio.ByteBuffer bb)
static java.nio.ByteBuffer
read(java.nio.file.Path path)
static java.nio.channels.FileChannel
readChannel(java.nio.file.Path path)
static java.io.BufferedReader
reader(java.io.File file)
static java.io.BufferedReader
reader(java.io.File file, java.lang.String encoding)
static java.io.BufferedReader
reader(java.io.File file, java.nio.charset.Charset encoding)
static java.io.BufferedReader
reader(java.io.InputStream in)
static java.io.BufferedReader
reader(java.io.InputStream in, java.lang.String encoding)
static java.io.BufferedReader
reader(java.io.InputStream in, java.nio.charset.Charset encoding)
static java.io.BufferedReader
reader(java.lang.String s)
static java.io.BufferedReader
reader(java.nio.ByteBuffer bb, java.nio.charset.Charset encoding)
static java.io.BufferedReader
reader(java.nio.channels.ReadableByteChannel in, java.nio.charset.Charset encoding)
static java.io.BufferedReader
reader(java.nio.CharBuffer cb)
static java.io.BufferedReader
reader(java.nio.file.Path path, java.nio.charset.Charset encoding)
static java.lang.String
readUTF(java.io.DataInput in)
static java.io.File
rename(java.io.File from, java.io.File to)
Renamesfrom
toto
replacing the target file if necessary.static java.nio.file.Path
rename(java.nio.file.Path from, java.nio.file.Path to)
Renamesfrom
toto
replacing the target file if necessary.static void
store(ConsumerWithException<java.io.OutputStream> store, java.io.File target)
Store output in a file but ensure that the content is updated atomically.static void
store(java.lang.Object o, java.io.File file)
static void
store(java.lang.Object o, java.io.File file, java.lang.String encoding)
static void
store(java.lang.Object o, java.io.OutputStream out)
static void
store(java.lang.Object o, java.io.OutputStream out, java.lang.String encoding)
static void
store(java.lang.Object o, java.io.OutputStream out, java.nio.charset.Charset encoding)
static void
store(java.lang.Object o, java.io.Writer w)
static void
store(java.lang.Object o, java.nio.file.Path path, java.nio.charset.Charset encoding)
static java.io.InputStream
stream(byte[] data)
static java.io.InputStream
stream(java.io.File file)
static java.io.InputStream
stream(java.lang.String s)
static java.io.InputStream
stream(java.lang.String s, java.lang.String encoding)
static java.io.InputStream
stream(java.lang.String s, java.nio.charset.Charset encoding)
static java.io.InputStream
stream(java.net.URL url)
static java.io.InputStream
stream(java.nio.ByteBuffer bb)
static java.io.InputStream
stream(java.nio.file.Path path)
static java.lang.String
toSafeFileName(java.lang.String string)
static java.net.URL
toURL(java.lang.String s, java.io.File base)
static java.util.Collection<java.io.File>
tree(java.io.File current)
static java.util.Collection<java.io.File>
tree(java.io.File current, java.lang.String glob)
static void
write(byte[] data, java.io.File file)
static void
write(byte[] data, java.io.OutputStream out)
static java.nio.channels.FileChannel
writeChannel(java.nio.file.Path path)
static java.io.PrintWriter
writer(java.io.File file)
static java.io.PrintWriter
writer(java.io.File file, java.lang.String encoding)
static java.io.PrintWriter
writer(java.io.File file, java.nio.charset.Charset encoding)
static java.io.PrintWriter
writer(java.io.OutputStream out)
static java.io.PrintWriter
writer(java.io.OutputStream out, java.lang.String encoding)
static java.io.PrintWriter
writer(java.io.OutputStream out, java.nio.charset.Charset encoding)
static java.io.PrintWriter
writer(java.nio.channels.WritableByteChannel out, java.nio.charset.Charset encoding)
static java.io.PrintWriter
writer(java.nio.file.Path path)
static java.io.PrintWriter
writer(java.nio.file.Path path, java.nio.charset.Charset encoding)
-
-
-
Method Detail
-
getExtension
public static java.lang.String getExtension(java.lang.String fileName, java.lang.String deflt)
-
tree
public static java.util.Collection<java.io.File> tree(java.io.File current)
-
tree
public static java.util.Collection<java.io.File> tree(java.io.File current, java.lang.String glob)
-
fileCollator
public static java.text.Collator fileCollator()
-
fileComparator
public static <FILE> java.util.Comparator<FILE> fileComparator(java.util.function.Function<? super FILE,? extends java.lang.String> keyExtractor)
-
listStream
public static java.util.stream.Stream<java.lang.String> listStream(java.io.File dir, java.util.function.BiPredicate<? super java.io.File,? super java.lang.String> filter)
-
listStream
public static java.util.stream.Stream<java.lang.String> listStream(java.io.File dir)
-
list
public static java.util.List<java.lang.String> list(java.io.File dir, java.util.function.BiPredicate<? super java.io.File,? super java.lang.String> filter)
-
list
public static java.util.List<java.lang.String> list(java.io.File dir)
-
listFiles
public static java.util.List<java.io.File> listFiles(java.io.File dir, java.util.function.BiPredicate<? super java.io.File,? super java.lang.String> filter)
-
listFiles
public static java.util.List<java.io.File> listFiles(java.io.File dir)
-
listStream
public static java.util.stream.Stream<java.lang.String> listStream(java.nio.file.Path dir, java.util.function.Predicate<? super java.nio.file.Path> filter)
-
listStream
public static java.util.stream.Stream<java.lang.String> listStream(java.nio.file.Path dir, java.util.function.BiPredicate<? super java.nio.file.Path,? super java.lang.String> filter)
-
listStream
public static java.util.stream.Stream<java.lang.String> listStream(java.nio.file.Path dir)
-
list
public static java.util.List<java.lang.String> list(java.nio.file.Path dir, java.util.function.Predicate<? super java.nio.file.Path> filter)
-
list
public static java.util.List<java.lang.String> list(java.nio.file.Path dir, java.util.function.BiPredicate<? super java.nio.file.Path,? super java.lang.String> filter)
-
list
public static java.util.List<java.lang.String> list(java.nio.file.Path dir)
-
listPaths
public static java.util.List<java.nio.file.Path> listPaths(java.nio.file.Path dir, java.util.function.Predicate<? super java.nio.file.Path> filter)
-
listPaths
public static java.util.List<java.nio.file.Path> listPaths(java.nio.file.Path dir, java.util.function.BiPredicate<? super java.nio.file.Path,? super java.lang.String> filter)
-
listPaths
public static java.util.List<java.nio.file.Path> listPaths(java.nio.file.Path dir)
-
copy
public static java.io.File copy(byte[] data, java.io.File file) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static java.nio.file.Path copy(byte[] data, java.nio.file.Path path) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static java.io.Writer copy(byte[] data, java.io.Writer w) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static java.io.OutputStream copy(byte[] data, java.io.OutputStream out) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static java.io.Writer copy(java.io.Reader r, java.io.Writer w) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static java.io.OutputStream copy(java.io.Reader r, java.io.OutputStream out) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static java.io.OutputStream copy(java.io.Reader r, java.io.OutputStream out, java.lang.String charset) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static java.io.OutputStream copy(java.io.Reader r, java.io.OutputStream out, java.nio.charset.Charset charset) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static java.io.Writer copy(java.io.InputStream in, java.io.Writer w) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static java.io.Writer copy(java.io.InputStream in, java.io.Writer w, java.lang.String charset) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static java.io.Writer copy(java.io.InputStream in, java.io.Writer w, java.nio.charset.Charset charset) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static java.io.OutputStream copy(java.io.InputStream in, java.io.OutputStream out) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static java.io.OutputStream copy(java.io.InputStream in, java.io.OutputStream out, int limit) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static ByteBufferOutputStream copy(java.io.InputStream in, ByteBufferOutputStream out) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static java.io.DataOutput copy(java.io.InputStream in, java.io.DataOutput out) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static java.nio.channels.WritableByteChannel copy(java.nio.channels.ReadableByteChannel in, java.nio.channels.WritableByteChannel out) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static java.nio.ByteBuffer copy(java.io.InputStream in, java.nio.ByteBuffer bb) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static byte[] copy(java.io.InputStream in, byte[] data) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static byte[] copy(java.io.InputStream in, byte[] data, int off, int len) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static java.io.OutputStream copy(java.nio.ByteBuffer bb, java.io.OutputStream out) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static java.io.DataOutput copy(java.nio.ByteBuffer bb, java.io.DataOutput out) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static java.security.MessageDigest copy(java.net.URL url, java.security.MessageDigest md) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static java.security.MessageDigest copy(java.io.File file, java.security.MessageDigest md) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static java.security.MessageDigest copy(java.nio.file.Path path, java.security.MessageDigest md) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static java.security.MessageDigest copy(java.net.URLConnection conn, java.security.MessageDigest md) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static java.security.MessageDigest copy(java.io.InputStream in, java.security.MessageDigest md) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static java.security.MessageDigest copy(java.nio.channels.ReadableByteChannel in, java.security.MessageDigest md) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static java.io.File copy(java.net.URL url, java.io.File file) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static java.io.File copy(java.net.URLConnection conn, java.io.File file) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static java.net.URL copy(java.io.InputStream in, java.net.URL url) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static java.net.URL copy(java.io.InputStream in, java.net.URL url, java.lang.String method) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static java.io.File copy(java.io.File src, java.io.File tgt) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static java.nio.file.Path copy(java.nio.file.Path src, java.nio.file.Path tgt) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static java.io.File copy(java.io.InputStream in, java.io.File file) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static java.nio.file.Path copy(java.io.InputStream in, java.nio.file.Path path) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static java.io.OutputStream copy(java.io.File file, java.io.OutputStream out) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static java.io.OutputStream copy(java.nio.file.Path path, java.io.OutputStream out) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static java.nio.channels.WritableByteChannel copy(java.io.InputStream in, java.nio.channels.WritableByteChannel out) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static java.io.OutputStream copy(java.nio.channels.ReadableByteChannel in, java.io.OutputStream out) throws java.io.IOException
- Throws:
java.io.IOException
-
read
public static byte[] read(java.io.File file) throws java.io.IOException
- Throws:
java.io.IOException
-
read
public static java.nio.ByteBuffer read(java.nio.file.Path path) throws java.io.IOException
- Throws:
java.io.IOException
-
read
public static byte[] read(java.nio.ByteBuffer bb)
-
read
public static byte[] read(java.net.URL url) throws java.io.IOException
- Throws:
java.io.IOException
-
read
public static byte[] read(java.io.InputStream in) throws java.io.IOException
- Throws:
java.io.IOException
-
write
public static void write(byte[] data, java.io.OutputStream out) throws java.io.IOException
- Throws:
java.io.IOException
-
write
public static void write(byte[] data, java.io.File file) throws java.io.IOException
- Throws:
java.io.IOException
-
collect
public static java.lang.String collect(java.io.File file) throws java.io.IOException
- Throws:
java.io.IOException
-
collect
public static java.lang.String collect(java.io.File file, java.lang.String encoding) throws java.io.IOException
- Throws:
java.io.IOException
-
collect
public static java.lang.String collect(java.io.File file, java.nio.charset.Charset encoding) throws java.io.IOException
- Throws:
java.io.IOException
-
collect
public static java.lang.String collect(java.nio.file.Path path) throws java.io.IOException
- Throws:
java.io.IOException
-
collect
public static java.lang.String collect(java.nio.file.Path path, java.nio.charset.Charset encoding) throws java.io.IOException
- Throws:
java.io.IOException
-
collect
public static java.lang.String collect(java.nio.ByteBuffer bb, java.nio.charset.Charset encoding)
-
collect
public static java.lang.String collect(java.net.URL url, java.lang.String encoding) throws java.io.IOException
- Throws:
java.io.IOException
-
collect
public static java.lang.String collect(java.net.URL url, java.nio.charset.Charset encoding) throws java.io.IOException
- Throws:
java.io.IOException
-
collect
public static java.lang.String collect(java.net.URL url) throws java.io.IOException
- Throws:
java.io.IOException
-
collect
public static java.lang.String collect(java.lang.String path) throws java.io.IOException
- Throws:
java.io.IOException
-
collect
public static java.lang.String collect(java.io.InputStream in) throws java.io.IOException
- Throws:
java.io.IOException
-
collect
public static java.lang.String collect(java.io.InputStream in, java.lang.String encoding) throws java.io.IOException
- Throws:
java.io.IOException
-
collect
public static java.lang.String collect(java.io.InputStream in, java.nio.charset.Charset encoding) throws java.io.IOException
- Throws:
java.io.IOException
-
collect
public static java.lang.String collect(java.io.Reader r) throws java.io.IOException
- Throws:
java.io.IOException
-
createTempFile
public static java.io.File createTempFile(java.io.File directory, java.lang.String pattern, java.lang.String suffix) throws java.lang.IllegalArgumentException, java.io.IOException
Create a temporary file.- Parameters:
directory
- the directory in which to create the file. Can be null, in which case the system TMP directory is usedpattern
- the filename prefix pattern. Must be at least 3 characters longsuffix
- the filename suffix. Can be null, in which case (system) default suffix is used- Returns:
- temp file
- Throws:
java.lang.IllegalArgumentException
- when pattern is null or too shortjava.io.IOException
- when the specified (non-null) directory is not a directory
-
absolutePath
public static java.lang.String absolutePath(java.io.File file)
-
absolutePath
public static java.lang.String absolutePath(java.nio.file.Path path)
-
normalizePath
public static java.lang.String normalizePath(java.nio.file.Path path)
-
normalizePath
public static java.lang.String normalizePath(java.io.File file)
-
normalizePath
public static java.lang.String normalizePath(java.lang.String path)
-
getFile
public static java.io.File getFile(java.lang.String file)
-
getFile
public static java.io.File getFile(java.io.File base, java.lang.String file)
-
getBasedFile
public static java.io.File getBasedFile(java.io.File base, java.lang.String file) throws java.io.IOException
- Throws:
java.io.IOException
-
getPath
public static java.nio.file.Path getPath(java.lang.String file)
-
getPath
public static java.nio.file.Path getPath(java.nio.file.Path base, java.lang.String file)
-
getBasedPath
public static java.nio.file.Path getBasedPath(java.nio.file.Path base, java.lang.String file) throws java.io.IOException
- Throws:
java.io.IOException
-
delete
public static void delete(java.io.File file)
Deletes the specified file. Folders are recursively deleted.
If file(s) cannot be deleted, no feedback is provided (fail silently).- Parameters:
file
- file to be deleted
-
deleteContent
public static void deleteContent(java.io.File dir)
Deletes the specified content of the given directory. Folders are recursively deleted. This method will not delete the given dir, this can be useful in Eclipse or other systems that detect delete-create
If file(s) cannot be deleted, no feedback is provided (fail silently).- Parameters:
dir
- of whose contents are to be deleted
-
delete
public static void delete(java.nio.file.Path path)
Deletes the specified path. Folders are recursively deleted.
If file(s) cannot be deleted, no feedback is provided (fail silently).- Parameters:
path
- path to be deleted
-
initialize
public static void initialize(java.io.File dir)
Deletes and creates directories
-
deleteWithException
public static void deleteWithException(java.io.File file) throws java.io.IOException
Deletes the specified file. Folders are recursively deleted.
Throws exception if any of the files could not be deleted.- Parameters:
file
- file to be deleted- Throws:
java.io.IOException
- if the file (or contents of a folder) could not be deleted
-
deleteWithException
public static void deleteWithException(java.nio.file.Path path) throws java.io.IOException
Deletes the specified path. Folders are recursively deleted.
Throws exception if any of the files could not be deleted.- Parameters:
path
- path to be deleted- Throws:
java.io.IOException
- if the path (or contents of a folder) could not be deleted
-
rename
public static java.io.File rename(java.io.File from, java.io.File to) throws java.io.IOException
Renamesfrom
toto
replacing the target file if necessary.- Parameters:
from
- source fileto
- destination file- Throws:
java.io.IOException
- if the rename operation fails
-
rename
public static java.nio.file.Path rename(java.nio.file.Path from, java.nio.file.Path to) throws java.io.IOException
Renamesfrom
toto
replacing the target file if necessary.- Parameters:
from
- source pathto
- destination path- Throws:
java.io.IOException
- if the rename operation fails
-
mkdirs
public static java.io.File mkdirs(java.io.File dir) throws java.io.IOException
- Throws:
java.io.IOException
-
mkdirs
public static java.nio.file.Path mkdirs(java.nio.file.Path dir) throws java.io.IOException
- Throws:
java.io.IOException
-
drain
public static long drain(java.io.InputStream in) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public static java.io.OutputStream copy(java.util.Collection<?> c, java.io.OutputStream out) throws java.io.IOException
- Throws:
java.io.IOException
-
close
public static java.lang.Throwable close(java.lang.AutoCloseable in)
-
close
public static java.lang.Throwable close(java.io.Closeable in)
-
closeAll
public static boolean closeAll(java.lang.Object... toBeClosed)
Will iterate over the given toBeClose and silently close any object that implements AutoCloseable.- Parameters:
toBeClosed
- any iterable- Returns:
- true if an exception was thrown during closing
-
toURL
public static java.net.URL toURL(java.lang.String s, java.io.File base) throws java.net.MalformedURLException
- Throws:
java.net.MalformedURLException
-
store
public static void store(java.lang.Object o, java.io.File file) throws java.io.IOException
- Throws:
java.io.IOException
-
store
public static void store(java.lang.Object o, java.io.File file, java.lang.String encoding) throws java.io.IOException
- Throws:
java.io.IOException
-
store
public static void store(java.lang.Object o, java.nio.file.Path path, java.nio.charset.Charset encoding) throws java.io.IOException
- Throws:
java.io.IOException
-
store
public static void store(java.lang.Object o, java.io.OutputStream out) throws java.io.IOException
- Throws:
java.io.IOException
-
store
public static void store(java.lang.Object o, java.io.OutputStream out, java.lang.String encoding) throws java.io.IOException
- Throws:
java.io.IOException
-
store
public static void store(java.lang.Object o, java.io.OutputStream out, java.nio.charset.Charset encoding) throws java.io.IOException
- Throws:
java.io.IOException
-
store
public static void store(java.lang.Object o, java.io.Writer w) throws java.io.IOException
- Throws:
java.io.IOException
-
store
public static void store(ConsumerWithException<java.io.OutputStream> store, java.io.File target) throws java.lang.Exception
Store output in a file but ensure that the content is updated atomically. To ensure this, the file is first copied to a temporary file in the same directory as the target. It is then renamed which will first attempt an atomic move but will always replace.- Parameters:
store
- the function provide the outputtarget
- the file to store it, parent directories will be created if necessary- Throws:
java.lang.Exception
-
stream
public static java.io.InputStream stream(byte[] data)
-
stream
public static java.io.InputStream stream(java.nio.ByteBuffer bb)
-
stream
public static java.io.InputStream stream(java.lang.String s)
-
stream
public static java.io.InputStream stream(java.lang.String s, java.lang.String encoding)
-
stream
public static java.io.InputStream stream(java.lang.String s, java.nio.charset.Charset encoding)
-
stream
public static java.io.InputStream stream(java.io.File file) throws java.io.IOException
- Throws:
java.io.IOException
-
stream
public static java.io.InputStream stream(java.nio.file.Path path) throws java.io.IOException
- Throws:
java.io.IOException
-
stream
public static java.io.InputStream stream(java.net.URL url) throws java.io.IOException
- Throws:
java.io.IOException
-
readChannel
public static java.nio.channels.FileChannel readChannel(java.nio.file.Path path) throws java.io.IOException
- Throws:
java.io.IOException
-
outputStream
public static java.io.OutputStream outputStream(java.io.File file) throws java.io.IOException
- Throws:
java.io.IOException
-
outputStream
public static java.io.OutputStream outputStream(java.nio.file.Path path) throws java.io.IOException
- Throws:
java.io.IOException
-
writeChannel
public static java.nio.channels.FileChannel writeChannel(java.nio.file.Path path) throws java.io.IOException
- Throws:
java.io.IOException
-
decode
public static java.nio.CharBuffer decode(java.nio.ByteBuffer bb, java.nio.charset.Charset encoding)
-
encode
public static java.nio.ByteBuffer encode(java.nio.CharBuffer cb, java.nio.charset.Charset encoding)
-
encode
public static java.nio.ByteBuffer encode(java.lang.String s, java.nio.charset.Charset encoding)
-
reader
public static java.io.BufferedReader reader(java.lang.String s)
-
reader
public static java.io.BufferedReader reader(java.io.File file) throws java.io.IOException
- Throws:
java.io.IOException
-
reader
public static java.io.BufferedReader reader(java.io.File file, java.lang.String encoding) throws java.io.IOException
- Throws:
java.io.IOException
-
reader
public static java.io.BufferedReader reader(java.io.File file, java.nio.charset.Charset encoding) throws java.io.IOException
- Throws:
java.io.IOException
-
reader
public static java.io.BufferedReader reader(java.nio.file.Path path, java.nio.charset.Charset encoding) throws java.io.IOException
- Throws:
java.io.IOException
-
reader
public static java.io.BufferedReader reader(java.nio.ByteBuffer bb, java.nio.charset.Charset encoding)
-
reader
public static java.io.BufferedReader reader(java.nio.CharBuffer cb)
-
reader
public static java.io.BufferedReader reader(java.nio.channels.ReadableByteChannel in, java.nio.charset.Charset encoding)
-
reader
public static java.io.BufferedReader reader(java.io.InputStream in)
-
reader
public static java.io.BufferedReader reader(java.io.InputStream in, java.lang.String encoding)
-
reader
public static java.io.BufferedReader reader(java.io.InputStream in, java.nio.charset.Charset encoding)
-
writer
public static java.io.PrintWriter writer(java.io.File file) throws java.io.IOException
- Throws:
java.io.IOException
-
writer
public static java.io.PrintWriter writer(java.io.File file, java.lang.String encoding) throws java.io.IOException
- Throws:
java.io.IOException
-
writer
public static java.io.PrintWriter writer(java.io.File file, java.nio.charset.Charset encoding) throws java.io.IOException
- Throws:
java.io.IOException
-
writer
public static java.io.PrintWriter writer(java.nio.file.Path path) throws java.io.IOException
- Throws:
java.io.IOException
-
writer
public static java.io.PrintWriter writer(java.nio.file.Path path, java.nio.charset.Charset encoding) throws java.io.IOException
- Throws:
java.io.IOException
-
writer
public static java.io.PrintWriter writer(java.nio.channels.WritableByteChannel out, java.nio.charset.Charset encoding)
-
writer
public static java.io.PrintWriter writer(java.io.OutputStream out)
-
writer
public static java.io.PrintWriter writer(java.io.OutputStream out, java.lang.String encoding)
-
writer
public static java.io.PrintWriter writer(java.io.OutputStream out, java.nio.charset.Charset encoding)
-
appendableToWriter
public static java.io.Writer appendableToWriter(java.lang.Appendable appendable)
-
createSymbolicLink
public static boolean createSymbolicLink(java.io.File link, java.io.File target) throws java.io.IOException
- Throws:
java.io.IOException
-
createSymbolicLink
public static boolean createSymbolicLink(java.nio.file.Path link, java.nio.file.Path target) throws java.io.IOException
- Throws:
java.io.IOException
-
isSymbolicLink
public static boolean isSymbolicLink(java.io.File link)
-
isSymbolicLink
public static boolean isSymbolicLink(java.nio.file.Path link)
-
createSymbolicLinkOrCopy
public static boolean createSymbolicLinkOrCopy(java.io.File link, java.io.File target)
Creates a symbolic link fromlink
to thetarget
, or copiestarget
tolink
if running on Windows.Creating symbolic links on Windows requires administrator permissions, so copying is a safer fallback. Copy only happens if timestamp and and file length are different than target
- Parameters:
link
- the location of the symbolic link, or destination of the copy.target
- the source of the symbolic link, or source of the copy.- Returns:
true
if the operation succeeds,false
otherwise.
-
createSymbolicLinkOrCopy
public static boolean createSymbolicLinkOrCopy(java.nio.file.Path link, java.nio.file.Path target)
Creates a symbolic link fromlink
to thetarget
, or copiestarget
tolink
if running on Windows.Creating symbolic links on Windows requires administrator permissions, so copying is a safer fallback. Copy only happens if timestamp and and file length are different than target
- Parameters:
link
- the location of the symbolic link, or destination of the copy.target
- the source of the symbolic link, or source of the copy.- Returns:
true
if the operation succeeds,false
otherwise.
-
toSafeFileName
public static java.lang.String toSafeFileName(java.lang.String string)
-
isWindows
public static boolean isWindows()
-
readUTF
public static java.lang.String readUTF(java.io.DataInput in) throws java.io.IOException
- Throws:
java.io.IOException
-
getJavaExecutablePath
public static java.lang.String getJavaExecutablePath(java.lang.String name)
-
-