public class IO extends Object
Modifier and Type | Field and Description |
---|---|
static File |
home |
static OutputStream |
nullStream |
static Writer |
nullWriter |
static File |
work |
Constructor and Description |
---|
IO() |
Modifier and Type | Method and Description |
---|---|
static Throwable |
close(Closeable in) |
static String |
collect(ByteBuffer bb,
Charset encoding) |
static String |
collect(File file) |
static String |
collect(File file,
Charset encoding) |
static String |
collect(File file,
String encoding) |
static String |
collect(InputStream in) |
static String |
collect(InputStream in,
Charset encoding) |
static String |
collect(InputStream in,
String encoding) |
static String |
collect(Path path) |
static String |
collect(Path path,
Charset encoding) |
static String |
collect(Reader r) |
static String |
collect(String path) |
static String |
collect(URL url) |
static String |
collect(URL url,
Charset encoding) |
static String |
collect(URL url,
String encoding) |
static File |
copy(byte[] data,
File file) |
static OutputStream |
copy(byte[] data,
OutputStream out) |
static Path |
copy(byte[] data,
Path path) |
static Writer |
copy(byte[] data,
Writer w) |
static OutputStream |
copy(ByteBuffer bb,
OutputStream out) |
static OutputStream |
copy(Collection<?> c,
OutputStream out) |
static File |
copy(File src,
File tgt) |
static MessageDigest |
copy(File file,
MessageDigest md) |
static OutputStream |
copy(File file,
OutputStream out) |
static byte[] |
copy(InputStream in,
byte[] data) |
static byte[] |
copy(InputStream in,
byte[] data,
int off,
int len) |
static ByteBuffer |
copy(InputStream in,
ByteBuffer bb) |
static DataOutput |
copy(InputStream in,
DataOutput out) |
static File |
copy(InputStream in,
File file) |
static MessageDigest |
copy(InputStream in,
MessageDigest md) |
static OutputStream |
copy(InputStream in,
OutputStream out) |
static Path |
copy(InputStream in,
Path path) |
static URL |
copy(InputStream in,
URL url) |
static URL |
copy(InputStream in,
URL url,
String method) |
static WritableByteChannel |
copy(InputStream in,
WritableByteChannel out) |
static Writer |
copy(InputStream in,
Writer w) |
static Writer |
copy(InputStream in,
Writer w,
Charset charset) |
static Writer |
copy(InputStream in,
Writer w,
String charset) |
static MessageDigest |
copy(Path path,
MessageDigest md) |
static OutputStream |
copy(Path path,
OutputStream out) |
static Path |
copy(Path src,
Path tgt) |
static MessageDigest |
copy(ReadableByteChannel in,
MessageDigest md) |
static OutputStream |
copy(ReadableByteChannel in,
OutputStream out) |
static WritableByteChannel |
copy(ReadableByteChannel in,
WritableByteChannel out) |
static OutputStream |
copy(Reader r,
OutputStream out) |
static OutputStream |
copy(Reader r,
OutputStream out,
Charset charset) |
static OutputStream |
copy(Reader r,
OutputStream out,
String charset) |
static Writer |
copy(Reader r,
Writer w) |
static File |
copy(URLConnection conn,
File file) |
static MessageDigest |
copy(URLConnection conn,
MessageDigest md) |
static File |
copy(URL url,
File file) |
static MessageDigest |
copy(URL url,
MessageDigest md) |
static boolean |
createSymbolicLink(File link,
File target) |
static boolean |
createSymbolicLink(Path link,
Path target) |
static boolean |
createSymbolicLinkOrCopy(File link,
File target)
Creates a symbolic link from
link to the target , or
copies target to link if running on Windows. |
static boolean |
createSymbolicLinkOrCopy(Path link,
Path target)
Creates a symbolic link from
link to the target , or
copies target to link if running on Windows. |
static File |
createTempFile(File directory,
String pattern,
String suffix)
Create a temporary file.
|
static CharBuffer |
decode(ByteBuffer bb,
Charset encoding) |
static void |
delete(File file)
Deletes the specified file.
|
static void |
delete(Path path)
Deletes the specified path.
|
static void |
deleteWithException(File file)
Deletes the specified file.
|
static void |
deleteWithException(Path path)
Deletes the specified path.
|
static long |
drain(InputStream in) |
static ByteBuffer |
encode(CharBuffer cb,
Charset encoding) |
static String |
getExtension(String fileName,
String deflt) |
static File |
getFile(File base,
String file) |
static File |
getFile(String filename) |
static void |
initialize(File dir)
Deletes and creates directories
|
static boolean |
isSymbolicLink(File link) |
static boolean |
isSymbolicLink(Path link) |
static boolean |
isWindows() |
static void |
mkdirs(File dir) |
static void |
mkdirs(Path dir) |
static OutputStream |
outputStream(File file) |
static OutputStream |
outputStream(Path path) |
static byte[] |
read(ByteBuffer bb) |
static byte[] |
read(File file) |
static byte[] |
read(InputStream in) |
static ByteBuffer |
read(Path path) |
static byte[] |
read(URL url) |
static FileChannel |
readChannel(Path path) |
static BufferedReader |
reader(ByteBuffer bb,
Charset encoding) |
static BufferedReader |
reader(CharBuffer cb) |
static BufferedReader |
reader(File file) |
static BufferedReader |
reader(File file,
Charset encoding) |
static BufferedReader |
reader(File file,
String encoding) |
static BufferedReader |
reader(InputStream in) |
static BufferedReader |
reader(InputStream in,
Charset encoding) |
static BufferedReader |
reader(InputStream in,
String encoding) |
static BufferedReader |
reader(Path path,
Charset encoding) |
static BufferedReader |
reader(ReadableByteChannel in,
Charset encoding) |
static BufferedReader |
reader(String s) |
static void |
rename(File from,
File to)
Renames
from to to replacing the target file if
necessary. |
static void |
rename(Path from,
Path to)
Renames
from to to replacing the target file if
necessary. |
static void |
store(Object o,
File file) |
static void |
store(Object o,
File file,
String encoding) |
static void |
store(Object o,
OutputStream out) |
static void |
store(Object o,
OutputStream out,
Charset encoding) |
static void |
store(Object o,
OutputStream out,
String encoding) |
static void |
store(Object o,
Path path,
Charset encoding) |
static void |
store(Object o,
Writer w) |
static InputStream |
stream(byte[] data) |
static InputStream |
stream(ByteBuffer bb) |
static InputStream |
stream(File file) |
static InputStream |
stream(Path path) |
static InputStream |
stream(String s) |
static InputStream |
stream(String s,
Charset encoding) |
static InputStream |
stream(String s,
String encoding) |
static InputStream |
stream(URL url) |
static String |
toSafeFileName(String string) |
static URL |
toURL(String s,
File base) |
static Collection<File> |
tree(File current) |
static Collection<File> |
tree(File current,
String glob) |
static void |
write(byte[] data,
File file) |
static void |
write(byte[] data,
OutputStream out) |
static FileChannel |
writeChannel(Path path) |
static PrintWriter |
writer(File file) |
static PrintWriter |
writer(File file,
Charset encoding) |
static PrintWriter |
writer(File file,
String encoding) |
static PrintWriter |
writer(OutputStream out) |
static PrintWriter |
writer(OutputStream out,
Charset encoding) |
static PrintWriter |
writer(OutputStream out,
String encoding) |
static PrintWriter |
writer(Path path,
Charset encoding) |
static PrintWriter |
writer(WritableByteChannel out,
Charset encoding) |
public static final File work
public static final File home
public static final OutputStream nullStream
public static final Writer nullWriter
public static Collection<File> tree(File current)
public static Collection<File> tree(File current, String glob)
public static File copy(byte[] data, File file) throws IOException
IOException
public static Path copy(byte[] data, Path path) throws IOException
IOException
public static Writer copy(byte[] data, Writer w) throws IOException
IOException
public static OutputStream copy(byte[] data, OutputStream out) throws IOException
IOException
public static Writer copy(Reader r, Writer w) throws IOException
IOException
public static OutputStream copy(Reader r, OutputStream out) throws IOException
IOException
public static OutputStream copy(Reader r, OutputStream out, String charset) throws IOException
IOException
public static OutputStream copy(Reader r, OutputStream out, Charset charset) throws IOException
IOException
public static Writer copy(InputStream in, Writer w) throws IOException
IOException
public static Writer copy(InputStream in, Writer w, String charset) throws IOException
IOException
public static Writer copy(InputStream in, Writer w, Charset charset) throws IOException
IOException
public static OutputStream copy(InputStream in, OutputStream out) throws IOException
IOException
public static DataOutput copy(InputStream in, DataOutput out) throws IOException
IOException
public static WritableByteChannel copy(ReadableByteChannel in, WritableByteChannel out) throws IOException
IOException
public static ByteBuffer copy(InputStream in, ByteBuffer bb) throws IOException
IOException
public static byte[] copy(InputStream in, byte[] data) throws IOException
IOException
public static byte[] copy(InputStream in, byte[] data, int off, int len) throws IOException
IOException
public static OutputStream copy(ByteBuffer bb, OutputStream out) throws IOException
IOException
public static MessageDigest copy(URL url, MessageDigest md) throws IOException
IOException
public static MessageDigest copy(File file, MessageDigest md) throws IOException
IOException
public static MessageDigest copy(Path path, MessageDigest md) throws IOException
IOException
public static MessageDigest copy(URLConnection conn, MessageDigest md) throws IOException
IOException
public static MessageDigest copy(InputStream in, MessageDigest md) throws IOException
IOException
public static MessageDigest copy(ReadableByteChannel in, MessageDigest md) throws IOException
IOException
public static File copy(URL url, File file) throws IOException
IOException
public static File copy(URLConnection conn, File file) throws IOException
IOException
public static URL copy(InputStream in, URL url) throws IOException
IOException
public static URL copy(InputStream in, URL url, String method) throws IOException
IOException
public static File copy(File src, File tgt) throws IOException
IOException
public static Path copy(Path src, Path tgt) throws IOException
IOException
public static File copy(InputStream in, File file) throws IOException
IOException
public static Path copy(InputStream in, Path path) throws IOException
IOException
public static OutputStream copy(File file, OutputStream out) throws IOException
IOException
public static OutputStream copy(Path path, OutputStream out) throws IOException
IOException
public static WritableByteChannel copy(InputStream in, WritableByteChannel out) throws IOException
IOException
public static OutputStream copy(ReadableByteChannel in, OutputStream out) throws IOException
IOException
public static byte[] read(File file) throws IOException
IOException
public static ByteBuffer read(Path path) throws IOException
IOException
public static byte[] read(ByteBuffer bb) throws IOException
IOException
public static byte[] read(URL url) throws IOException
IOException
public static byte[] read(InputStream in) throws IOException
IOException
public static void write(byte[] data, OutputStream out) throws Exception
Exception
public static String collect(File file) throws IOException
IOException
public static String collect(File file, String encoding) throws IOException
IOException
public static String collect(File file, Charset encoding) throws IOException
IOException
public static String collect(Path path) throws IOException
IOException
public static String collect(Path path, Charset encoding) throws IOException
IOException
public static String collect(ByteBuffer bb, Charset encoding) throws IOException
IOException
public static String collect(URL url, String encoding) throws IOException
IOException
public static String collect(URL url, Charset encoding) throws IOException
IOException
public static String collect(URL url) throws IOException
IOException
public static String collect(String path) throws IOException
IOException
public static String collect(InputStream in) throws IOException
IOException
public static String collect(InputStream in, String encoding) throws IOException
IOException
public static String collect(InputStream in, Charset encoding) throws IOException
IOException
public static String collect(Reader r) throws IOException
IOException
public static File createTempFile(File directory, String pattern, String suffix) throws IllegalArgumentException, IOException
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 usedIllegalArgumentException
- when pattern is null or too shortIOException
- when the specified (non-null) directory is not a
directorypublic static void delete(File file)
file
- file to be deletedpublic static void delete(Path path)
path
- path to be deletedpublic static void initialize(File dir)
public static void deleteWithException(File file) throws IOException
file
- file to be deletedIOException
- if the file (or contents of a folder) could not be
deletedpublic static void deleteWithException(Path path) throws IOException
path
- path to be deletedIOException
- if the path (or contents of a folder) could not be
deletedpublic static void rename(File from, File to) throws IOException
from
to to
replacing the target file if
necessary.from
- source fileto
- destination fileIOException
- if the rename operation failspublic static void rename(Path from, Path to) throws IOException
from
to to
replacing the target file if
necessary.from
- source pathto
- destination pathIOException
- if the rename operation failspublic static void mkdirs(File dir) throws IOException
IOException
public static void mkdirs(Path dir) throws IOException
IOException
public static long drain(InputStream in) throws IOException
IOException
public static OutputStream copy(Collection<?> c, OutputStream out) throws IOException
IOException
public static URL toURL(String s, File base) throws MalformedURLException
MalformedURLException
public static void store(Object o, File file) throws IOException
IOException
public static void store(Object o, File file, String encoding) throws IOException
IOException
public static void store(Object o, Path path, Charset encoding) throws IOException
IOException
public static void store(Object o, OutputStream out) throws IOException
IOException
public static void store(Object o, OutputStream out, String encoding) throws IOException
IOException
public static void store(Object o, OutputStream out, Charset encoding) throws IOException
IOException
public static void store(Object o, Writer w) throws IOException
IOException
public static InputStream stream(byte[] data)
public static InputStream stream(ByteBuffer bb)
public static InputStream stream(String s)
public static InputStream stream(String s, String encoding) throws IOException
IOException
public static InputStream stream(String s, Charset encoding)
public static InputStream stream(File file) throws IOException
IOException
public static InputStream stream(Path path) throws IOException
IOException
public static InputStream stream(URL url) throws IOException
IOException
public static FileChannel readChannel(Path path) throws IOException
IOException
public static OutputStream outputStream(File file) throws IOException
IOException
public static OutputStream outputStream(Path path) throws IOException
IOException
public static FileChannel writeChannel(Path path) throws IOException
IOException
public static CharBuffer decode(ByteBuffer bb, Charset encoding) throws IOException
IOException
public static ByteBuffer encode(CharBuffer cb, Charset encoding) throws IOException
IOException
public static BufferedReader reader(String s)
public static BufferedReader reader(File file) throws IOException
IOException
public static BufferedReader reader(File file, String encoding) throws IOException
IOException
public static BufferedReader reader(File file, Charset encoding) throws IOException
IOException
public static BufferedReader reader(Path path, Charset encoding) throws IOException
IOException
public static BufferedReader reader(ByteBuffer bb, Charset encoding) throws IOException
IOException
public static BufferedReader reader(CharBuffer cb) throws IOException
IOException
public static BufferedReader reader(ReadableByteChannel in, Charset encoding) throws IOException
IOException
public static BufferedReader reader(InputStream in) throws IOException
IOException
public static BufferedReader reader(InputStream in, String encoding) throws IOException
IOException
public static BufferedReader reader(InputStream in, Charset encoding) throws IOException
IOException
public static PrintWriter writer(File file) throws IOException
IOException
public static PrintWriter writer(File file, String encoding) throws IOException
IOException
public static PrintWriter writer(File file, Charset encoding) throws IOException
IOException
public static PrintWriter writer(Path path, Charset encoding) throws IOException
IOException
public static PrintWriter writer(WritableByteChannel out, Charset encoding) throws IOException
IOException
public static PrintWriter writer(OutputStream out) throws IOException
IOException
public static PrintWriter writer(OutputStream out, String encoding) throws IOException
IOException
public static PrintWriter writer(OutputStream out, Charset encoding) throws IOException
IOException
public static boolean createSymbolicLink(File link, File target) throws Exception
Exception
public static boolean createSymbolicLink(Path link, Path target) throws Exception
Exception
public static boolean isSymbolicLink(File link)
public static boolean isSymbolicLink(Path link)
public static boolean createSymbolicLinkOrCopy(File link, File target)
link
to the target
, or
copies target
to link
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
link
- the location of the symbolic link, or destination of the
copy.target
- the source of the symbolic link, or source of the copy.true
if the operation succeeds, false
otherwise.public static boolean createSymbolicLinkOrCopy(Path link, Path target)
link
to the target
, or
copies target
to link
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
link
- the location of the symbolic link, or destination of the
copy.target
- the source of the symbolic link, or source of the copy.true
if the operation succeeds, false
otherwise.public static boolean isWindows()
Copyright © 2021 aQute SARL. All rights reserved.