Package aQute.lib.io
Class IO
java.lang.Object
aQute.lib.io.IO
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Filestatic final Filestatic final OutputStreamstatic final Writerstatic final File -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringabsolutePath(File file) static StringabsolutePath(Path path) static WriterappendableToWriter(Appendable appendable) static Throwablestatic Throwableclose(AutoCloseable in) static booleanWill iterate over the given toBeClose and silently close any object that implements AutoCloseable.static Stringstatic Stringstatic Stringstatic Stringcollect(InputStream in) static Stringcollect(InputStream in, String encoding) static Stringcollect(InputStream in, Charset encoding) static Stringstatic Stringstatic Stringstatic Stringstatic Stringstatic Stringcollect(ByteBuffer bb, Charset encoding) static Stringstatic Stringstatic Filestatic OutputStreamcopy(byte[] data, OutputStream out) static Writerstatic Pathstatic Filestatic OutputStreamcopy(File file, OutputStream out) static MessageDigestcopy(File file, MessageDigest md) static byte[]copy(InputStream in, byte[] data) static byte[]copy(InputStream in, byte[] data, int off, int len) static ByteBufferOutputStreamcopy(InputStream in, ByteBufferOutputStream out) static DataOutputcopy(InputStream in, DataOutput out) static Filecopy(InputStream in, File file) static OutputStreamcopy(InputStream in, OutputStream out) static OutputStreamcopy(InputStream in, OutputStream out, int limit) static Writercopy(InputStream in, Writer w) static Writercopy(InputStream in, Writer w, String charset) static Writercopy(InputStream in, Writer w, Charset charset) static URLcopy(InputStream in, URL url) static URLcopy(InputStream in, URL url, String method) static ByteBuffercopy(InputStream in, ByteBuffer bb) static WritableByteChannelcopy(InputStream in, WritableByteChannel out) static Pathcopy(InputStream in, Path path) static MessageDigestcopy(InputStream in, MessageDigest md) static OutputStreamcopy(Reader r, OutputStream out) static OutputStreamcopy(Reader r, OutputStream out, String charset) static OutputStreamcopy(Reader r, OutputStream out, Charset charset) static Writerstatic Filecopy(URLConnection conn, File file) static MessageDigestcopy(URLConnection conn, MessageDigest md) static Filestatic MessageDigestcopy(URL url, MessageDigest md) static DataOutputcopy(ByteBuffer bb, DataOutput out) static OutputStreamcopy(ByteBuffer bb, OutputStream out) static OutputStreamcopy(ReadableByteChannel in, OutputStream out) static WritableByteChannelcopy(ReadableByteChannel in, WritableByteChannel out) static MessageDigestcopy(ReadableByteChannel in, MessageDigest md) static OutputStreamcopy(Path path, OutputStream out) static Pathstatic MessageDigestcopy(Path path, MessageDigest md) static OutputStreamcopy(Collection<?> c, OutputStream out) static booleancreateSymbolicLink(File link, File target) static booleancreateSymbolicLink(Path link, Path target) static booleancreateSymbolicLinkOrCopy(File link, File target) Creates a symbolic link fromlinkto thetarget, or copiestargettolinkif running on Windows.static booleancreateSymbolicLinkOrCopy(Path link, Path target) Creates a symbolic link fromlinkto thetarget, or copiestargettolinkif running on Windows.static FilecreateTempFile(File directory, String pattern, String suffix) Create a temporary file.static CharBufferdecode(ByteBuffer bb, Charset encoding) static voidDeletes the specified file.static voidDeletes the specified path.static voiddeleteContent(File dir) Deletes the specified content of the given directory.static voiddeleteWithException(File file) Deletes the specified file.static voiddeleteWithException(Path path) Deletes the specified path.static longdrain(InputStream in) static ByteBufferstatic ByteBufferencode(CharBuffer cb, Charset encoding) static Collatorstatic <FILE> Comparator<FILE> fileComparator(Function<? super FILE, ? extends String> keyExtractor) static FilegetBasedFile(File base, String file) static PathgetBasedPath(Path base, String file) static StringgetExtension(String fileName, String deflt) static Filestatic Filestatic StringgetJavaExecutablePath(String name) static Pathstatic Pathstatic voidinitialize(File dir) Deletes and creates directoriesstatic booleanisSymbolicLink(File link) static booleanisSymbolicLink(Path link) static booleanlist(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 Filestatic Pathstatic StringnormalizePath(File file) static StringnormalizePath(String path) static StringnormalizePath(Path path) static OutputStreamoutputStream(File file) static OutputStreamoutputStream(Path path) static byte[]static byte[]read(InputStream in) static byte[]static byte[]read(ByteBuffer bb) static ByteBufferstatic FileChannelreadChannel(Path path) static BufferedReaderstatic BufferedReaderstatic BufferedReaderstatic BufferedReaderreader(InputStream in) static BufferedReaderreader(InputStream in, String encoding) static BufferedReaderreader(InputStream in, Charset encoding) static BufferedReaderstatic BufferedReaderreader(ByteBuffer bb, Charset encoding) static BufferedReaderreader(ReadableByteChannel in, Charset encoding) static BufferedReaderreader(CharBuffer cb) static BufferedReaderstatic Stringstatic FileRenamesfromtotoreplacing the target file if necessary.static PathRenamesfromtotoreplacing the target file if necessary.static voidstore(ConsumerWithException<OutputStream> store, File target) Store output in a file but ensure that the content is updated atomically.static voidstatic voidstatic voidstore(Object o, OutputStream out) static voidstore(Object o, OutputStream out, String encoding) static voidstore(Object o, OutputStream out, Charset encoding) static voidstatic voidstatic InputStreamstream(byte[] data) static InputStreamstatic InputStreamstatic InputStreamstatic InputStreamstatic InputStreamstatic InputStreamstream(ByteBuffer bb) static InputStreamstatic StringtoSafeFileName(String string) static URLstatic Collection<File> static Collection<File> static voidstatic voidwrite(byte[] data, OutputStream out) static FileChannelwriteChannel(Path path) static PrintWriterstatic PrintWriterstatic PrintWriterstatic PrintWriterwriter(OutputStream out) static PrintWriterwriter(OutputStream out, String encoding) static PrintWriterwriter(OutputStream out, Charset encoding) static PrintWriterwriter(WritableByteChannel out, Charset encoding) static PrintWriterstatic PrintWriter
-
Field Details
-
work
-
home
-
JAVA_HOME
-
nullStream
-
nullWriter
-
-
Constructor Details
-
IO
public IO()
-
-
Method Details
-
getExtension
-
tree
-
tree
-
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
-
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
Renamesfromtotoreplacing the target file if necessary.- Parameters:
from- source fileto- destination file- Throws:
IOException- if the rename operation fails
-
rename
Renamesfromtotoreplacing 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 fromlinkto thetarget, or copiestargettolinkif 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:
trueif the operation succeeds,falseotherwise.
-
createSymbolicLinkOrCopy
Creates a symbolic link fromlinkto thetarget, or copiestargettolinkif 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:
trueif the operation succeeds,falseotherwise.
-
toSafeFileName
-
isWindows
public static boolean isWindows() -
readUTF
- Throws:
IOException
-
getJavaExecutablePath
-