Package aQute.lib.io
Class IO
java.lang.Object
aQute.lib.io.IO
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final class
(package private) static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
private static final int
static final File
private static final boolean
static final File
static final OutputStream
static final Writer
private static final EnumSet<StandardOpenOption>
private static final Pattern
private static final Pattern
static final File
private static final EnumSet<StandardOpenOption>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
absolutePath
(File file) static String
absolutePath
(Path path) static Writer
appendableToWriter
(Appendable appendable) static Throwable
static Throwable
close
(AutoCloseable in) static boolean
Will iterate over the given toBeClose and silently close any object that implements AutoCloseable.static String
static String
static String
static String
collect
(InputStream in) static String
collect
(InputStream in, String encoding) static String
collect
(InputStream in, Charset encoding) static String
static String
static String
static String
static String
static String
collect
(ByteBuffer bb, Charset encoding) static String
static String
static File
static OutputStream
copy
(byte[] data, OutputStream out) static Writer
static Path
static File
static OutputStream
copy
(File file, OutputStream out) static MessageDigest
copy
(File file, MessageDigest md) static byte[]
copy
(InputStream in, byte[] data) static byte[]
copy
(InputStream in, byte[] data, int off, int len) static ByteBufferOutputStream
copy
(InputStream in, ByteBufferOutputStream out) static DataOutput
copy
(InputStream in, DataOutput out) static File
copy
(InputStream in, File file) static OutputStream
copy
(InputStream in, OutputStream out) static OutputStream
copy
(InputStream in, OutputStream out, int limit) static Writer
copy
(InputStream in, Writer w) static Writer
copy
(InputStream in, Writer w, String charset) static Writer
copy
(InputStream in, Writer w, Charset charset) static URL
copy
(InputStream in, URL url) static URL
copy
(InputStream in, URL url, String method) static ByteBuffer
copy
(InputStream in, ByteBuffer bb) static WritableByteChannel
copy
(InputStream in, WritableByteChannel out) static Path
copy
(InputStream in, Path path) static MessageDigest
copy
(InputStream in, MessageDigest md) static OutputStream
copy
(Reader r, OutputStream out) static OutputStream
copy
(Reader r, OutputStream out, String charset) static OutputStream
copy
(Reader r, OutputStream out, Charset charset) static Writer
static File
copy
(URLConnection conn, File file) static MessageDigest
copy
(URLConnection conn, MessageDigest md) static File
static MessageDigest
copy
(URL url, MessageDigest md) static DataOutput
copy
(ByteBuffer bb, DataOutput out) static OutputStream
copy
(ByteBuffer bb, OutputStream out) static OutputStream
copy
(ReadableByteChannel in, OutputStream out) static WritableByteChannel
copy
(ReadableByteChannel in, WritableByteChannel out) static MessageDigest
copy
(ReadableByteChannel in, MessageDigest md) static OutputStream
copy
(Path path, OutputStream out) static Path
static MessageDigest
copy
(Path path, MessageDigest md) static OutputStream
copy
(Collection<?> c, OutputStream out) 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 fromlink
to thetarget
, or copiestarget
tolink
if running on Windows.static boolean
createSymbolicLinkOrCopy
(Path link, Path target) Creates a symbolic link fromlink
to thetarget
, or copiestarget
tolink
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
Deletes the specified file.static void
Deletes the specified path.static void
deleteContent
(File dir) Deletes the specified content of the given directory.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
static ByteBuffer
encode
(CharBuffer cb, Charset encoding) static Collator
static <FILE> Comparator<FILE>
fileComparator
(Function<? super FILE, ? extends String> keyExtractor) static File
getBasedFile
(File base, String file) static Path
getBasedPath
(Path base, String file) static String
getExtension
(String fileName, String deflt) static File
static File
static String
getJavaExecutablePath
(String name) static Path
static Path
static void
initialize
(File dir) Deletes and creates directoriesstatic boolean
isSymbolicLink
(File link) static boolean
isSymbolicLink
(Path link) static boolean
list
(File dir, BiPredicate<? super File, ? super String> filter) list
(Path dir, BiPredicate<? super Path, ? super String> filter) listFiles
(File dir, BiPredicate<? super File, ? super String> filter) listPaths
(Path dir, BiPredicate<? super Path, ? super String> filter) listStream
(File dir) listStream
(File dir, BiPredicate<? super File, ? super String> filter) listStream
(Path dir) listStream
(Path dir, BiPredicate<? super Path, ? super String> filter) listStream
(Path dir, Predicate<? super Path> filter) static File
static Path
static String
normalizePath
(File file) static String
normalizePath
(String path) static String
normalizePath
(Path path) static OutputStream
outputStream
(File file) static OutputStream
outputStream
(Path path) static byte[]
static byte[]
read
(InputStream in) private static int
read
(InputStream in, byte[] b, int off, int len) If InputStream throws EOFException, map it to returning -1.static byte[]
static byte[]
read
(ByteBuffer bb) private static int
read
(ReadableByteChannel in, ByteBuffer bb) If ReadableByteChannel throws EOFException, map it to returning -1.static ByteBuffer
static FileChannel
readChannel
(Path path) static BufferedReader
static BufferedReader
static BufferedReader
static BufferedReader
reader
(InputStream in) static BufferedReader
reader
(InputStream in, String encoding) static BufferedReader
reader
(InputStream in, Charset encoding) static BufferedReader
static BufferedReader
reader
(ByteBuffer bb, Charset encoding) static BufferedReader
reader
(ReadableByteChannel in, Charset encoding) static BufferedReader
reader
(CharBuffer cb) static BufferedReader
static String
static File
Renamesfrom
toto
replacing the target file if necessary.static Path
Renamesfrom
toto
replacing the target file if necessary.static void
store
(ConsumerWithException<OutputStream> store, File target) Store output in a file but ensure that the content is updated atomically.static void
static void
static void
store
(Object o, OutputStream out) static void
store
(Object o, OutputStream out, String encoding) static void
store
(Object o, OutputStream out, Charset encoding) static void
static void
static InputStream
stream
(byte[] data) static InputStream
static InputStream
static InputStream
static InputStream
static InputStream
static InputStream
stream
(ByteBuffer bb) static InputStream
static String
toSafeFileName
(String string) static URL
private static void
traverse
(Collection<File> files, File current, Glob glob) static Collection<File>
static Collection<File>
static void
static void
write
(byte[] data, OutputStream out) static FileChannel
writeChannel
(Path path) static PrintWriter
static PrintWriter
static PrintWriter
static PrintWriter
writer
(OutputStream out) static PrintWriter
writer
(OutputStream out, String encoding) static PrintWriter
writer
(OutputStream out, Charset encoding) static PrintWriter
writer
(WritableByteChannel out, Charset encoding) static PrintWriter
static PrintWriter
-
Field Details
-
WINDOWS_MACROS
-
BUFFER_SIZE
private static final int BUFFER_SIZE- See Also:
-
DIRECT_MAP_THRESHOLD
private static final int DIRECT_MAP_THRESHOLD- See Also:
-
isWindows
private static final boolean isWindows -
work
-
home
-
JAVA_HOME
-
writeOptions
-
readOptions
-
nullStream
-
nullWriter
-
RESERVED_WINDOWS_P
-
-
Constructor Details
-
IO
public IO()
-
-
Method Details
-
getExtension
-
tree
-
tree
-
traverse
-
fileCollator
-
fileComparator
public static <FILE> Comparator<FILE> fileComparator(Function<? super FILE, ? extends String> keyExtractor) -
listStream
-
listStream
-
list
-
list
-
listFiles
-
listFiles
-
listStream
-
listStream
-
listStream
-
list
-
list
-
list
-
listPaths
-
listPaths
-
listPaths
-
copy
- Throws:
IOException
-
copy
- Throws:
IOException
-
copy
- Throws:
IOException
-
copy
- Throws:
IOException
-
copy
- Throws:
IOException
-
copy
- Throws:
IOException
-
copy
- Throws:
IOException
-
copy
- Throws:
IOException
-
copy
- Throws:
IOException
-
copy
- Throws:
IOException
-
copy
- Throws:
IOException
-
read
If InputStream throws EOFException, map it to returning -1. Other IOExceptions are propagated.- Throws:
IOException
-
read
If ReadableByteChannel throws EOFException, map it to returning -1. Other IOExceptions are propagated.- Throws:
IOException
-
copy
- Throws:
IOException
-
copy
- Throws:
IOException
-
copy
public static ByteBufferOutputStream copy(InputStream in, ByteBufferOutputStream out) throws IOException - Throws:
IOException
-
copy
- Throws:
IOException
-
copy
public static WritableByteChannel copy(ReadableByteChannel in, WritableByteChannel out) throws IOException - Throws:
IOException
-
copy
- Throws:
IOException
-
copy
- Throws:
IOException
-
copy
- Throws:
IOException
-
copy
- Throws:
IOException
-
copy
- Throws:
IOException
-
copy
- Throws:
IOException
-
copy
- Throws:
IOException
-
copy
- Throws:
IOException
-
copy
- Throws:
IOException
-
copy
- Throws:
IOException
-
copy
- Throws:
IOException
-
copy
- Throws:
IOException
-
copy
- Throws:
IOException
-
copy
- Throws:
IOException
-
copy
- Throws:
IOException
-
copy
- Throws:
IOException
-
copy
- Throws:
IOException
-
copy
- Throws:
IOException
-
copy
- Throws:
IOException
-
copy
- Throws:
IOException
-
copy
- Throws:
IOException
-
copy
- Throws:
IOException
-
copy
- Throws:
IOException
-
read
- Throws:
IOException
-
read
- Throws:
IOException
-
read
-
read
- Throws:
IOException
-
read
- Throws:
IOException
-
write
- Throws:
IOException
-
write
- Throws:
IOException
-
collect
- Throws:
IOException
-
collect
- Throws:
IOException
-
collect
- Throws:
IOException
-
collect
- Throws:
IOException
-
collect
- Throws:
IOException
-
collect
-
collect
- Throws:
IOException
-
collect
- Throws:
IOException
-
collect
- Throws:
IOException
-
collect
- Throws:
IOException
-
collect
- Throws:
IOException
-
collect
- Throws:
IOException
-
collect
- Throws:
IOException
-
collect
- Throws:
IOException
-
createTempFile
public static File createTempFile(File directory, String pattern, String suffix) throws IllegalArgumentException, 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:
IllegalArgumentException
- when pattern is null or too shortIOException
- when the specified (non-null) directory is not a directory
-
absolutePath
-
absolutePath
-
normalizePath
-
normalizePath
-
normalizePath
-
getFile
-
getFile
-
getBasedFile
- Throws:
IOException
-
getPath
-
getPath
-
getBasedPath
- Throws:
IOException
-
delete
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
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
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
Deletes and creates directories -
deleteWithException
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:
IOException
- if the file (or contents of a folder) could not be deleted
-
deleteWithException
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:
IOException
- if the path (or contents of a folder) could not be deleted
-
rename
Renamesfrom
toto
replacing the target file if necessary.- Parameters:
from
- source fileto
- destination file- Throws:
IOException
- if the rename operation fails
-
rename
Renamesfrom
toto
replacing the target file if necessary.- Parameters:
from
- source pathto
- destination path- Throws:
IOException
- if the rename operation fails
-
mkdirs
- Throws:
IOException
-
mkdirs
- Throws:
IOException
-
drain
- Throws:
IOException
-
copy
- Throws:
IOException
-
close
-
close
-
closeAll
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
- Throws:
MalformedURLException
-
store
- Throws:
IOException
-
store
- Throws:
IOException
-
store
- Throws:
IOException
-
store
- Throws:
IOException
-
store
- Throws:
IOException
-
store
- Throws:
IOException
-
store
- Throws:
IOException
-
store
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:
Exception
-
stream
-
stream
-
stream
-
stream
-
stream
-
stream
- Throws:
IOException
-
stream
- Throws:
IOException
-
stream
- Throws:
IOException
-
readChannel
- Throws:
IOException
-
outputStream
- Throws:
IOException
-
outputStream
- Throws:
IOException
-
writeChannel
- Throws:
IOException
-
decode
-
encode
-
encode
-
reader
-
reader
- Throws:
IOException
-
reader
- Throws:
IOException
-
reader
- Throws:
IOException
-
reader
- Throws:
IOException
-
reader
-
reader
-
reader
-
reader
-
reader
-
reader
-
writer
- Throws:
IOException
-
writer
- Throws:
IOException
-
writer
- Throws:
IOException
-
writer
- Throws:
IOException
-
writer
- Throws:
IOException
-
writer
-
writer
-
writer
-
writer
-
appendableToWriter
-
createSymbolicLink
- Throws:
IOException
-
createSymbolicLink
- Throws:
IOException
-
isSymbolicLink
-
isSymbolicLink
-
createSymbolicLinkOrCopy
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
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
-
isWindows
public static boolean isWindows() -
readUTF
- Throws:
IOException
-
getJavaExecutablePath
-