Package org.eclipse.net4j.util.io

# Class IOUtil

java.lang.Object
org.eclipse.net4j.util.io.IOUtil

public final class IOUtil extends Object

Author:
  Eike Stepper

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static class`
`IOUtil.FileCollector`

## Field Summary

Fields
Modifier and Type
Field
Description
`static final int`
`DEFAULT_BUFFER_SIZE`
`static final long`
`DEFAULT_TIMEOUT`
`static final int`
`EOF`
`static final String`
`WILDCARD_MULTI_CHARS`
`static final String`
`WILDCARD_MULTI_DIRS`
`static final String`
`WILDCARD_SINGLE_CHAR`

## Method Summary

Modifier and Type
Method
Description
`static void`
`appendText(File file, String text)`
`static BufferedInputStream`
`buffered(InputStream in)`
`static BufferedOutputStream`
`buffered(OutputStream out)`
`static BufferedReader`
`buffered(Reader in)`
`static BufferedWriter`
`buffered(Writer out)`
`static void`
`close(Closeable closeable)`
`static void`
`close(Closeable closeable)`
`static Exception`
`closeSilent(Closeable closeable)`
`static Exception`
`closeSilent(Closeable closeable)`
`static void`
`copy(InputStream input, OutputStream output)`
`static void`
`copy(InputStream input, OutputStream output, byte[] buffer)`
`static void`
`copy(InputStream input, OutputStream output, int bufferSize)`
`static int`
`copy(InputStream input, OutputStream output, int size, byte[] buffer)`
`static long`
`copyBinary(InputStream inputStream, OutputStream outputStream)`
`static void`
`copyBinary(InputStream inputStream, OutputStream outputStream, long size)`
`static long`
`copyCharacter(Reader reader, Writer writer)`
`static void`
`copyCharacter(Reader reader, Writer writer, long size)`
`static void`
`copyFile(File source, File target)`
`static void`
`copyText(BufferedReader reader, BufferedWriter writer, IOFilter<String>... lineFilters)`
`static void`
`copyText(File source, File target, IOFilter<String>... lineFilters)`
`static void`
`copyTree(File source, File target)`
`static void`
`copyTrees(Collection<File> sources, File target)`
`static int`
`delete(File file)`
`static String`
`encodeFileName(String path)`
`static boolean`
`equals(File file1, File file2)`
`static boolean`
`equals(InputStream stream1, InputStream stream2)`
`static boolean`
`equals(Reader reader1, Reader reader2)`
`static PrintStream`
`ERR()`
`static void`
`flush(Flushable flushable)`
`static IOException`
`flushSilent(Flushable flushable)`
`static int`
`getFreePort()`
`static byte[]`
`getSHA1(InputStream contents)`
`static byte[]`
`getSHA1(String contents)`
`static List<File>`
`glob(String pattern, File folder)`
`static InputStream`
`IN()`
`static IOException`
`ioException(Exception ex)`
`static boolean`
`isFreePort(int port)`
`static List<File>`
`listBreadthFirst(File file)`
`static List<File>`
`listDepthFirst(File file)`
`static Properties`
`loadProperties(File file)`
`static String`
`makeRelative(File file, File toFolder)`
`static void`
`mkdirs(File folder)`
`static URL`
`newURL(String url)`
`static String`
`normalizeSeparator(String string)`
`static OutputStream`
`nullOutputStream()`
`static FileInputStream`
`openInputStream(File file)`
`static FileInputStream`
`openInputStream(String fileName)`
`static FileOutputStream`
`openOutputStream(File file)`
`static FileOutputStream`
`openOutputStream(String fileName)`
`static FileReader`
`openReader(File file)`
`static FileReader`
`openReader(String fileName)`
`static boolean`
`openSystemBrowser(String url)`
`static FileWriter`
`openWriter(File file)`
`static FileWriter`
`openWriter(File file, boolean append)`
`static FileWriter`
`openWriter(String fileName)`
`static PrintStream`
`OUT()`
`static void`
`print(StackTraceElement[] elements)`
`static void`
`print(StackTraceElement[] elements, PrintStream stream)`
`static void`
`print(Throwable t)`
`static void`
`print(Throwable t, PrintStream stream)`
`static byte[]`
`readBytes(InputStream in)`
`static byte[]`
`readBytes(InputStream in, int initialBufferSize)`
`static byte[]`
`readFile(File file)`
`static <T> T`
`readObject(File file)`
`static <T> T`
`readObject(File file, ClassLoader classLoader)`
`static <T> T`
`readObject(File file, ExtendedIOUtil.ClassResolver classResolver)`
`static <T> T`
`readObject(File file, ExtendedIOUtil.ClassResolver classResolver, ObjectInputFilter filter)`
`static String`
`readText(Reader input)`
`static String`
`readText(URL url)`
`static String`
`readTextFile(File file)`
`static void`
`safeInput(File file, IORunnable<FileInputStream> runnable)`
`static void`
`safeOutput(File file, IORunnable<FileOutputStream> runnable)`
`static void`
`safeRead(File file, IORunnable<FileReader> runnable)`
`static <IO extends Closeable>
void`
`safeRun(IO io, IORunnable<IO> runnable)`
`static void`
`safeWrite(File file, IORunnable<FileWriter> runnable)`
`static void`
`saveProperties(File file, Properties properties, String comments)`
`static String`
`toString(Throwable t)`
`static void`
`visitBreadthFirst(File[] files, IOVisitor visitor)`
`static void`
`visitBreadthFirst(File file, IOVisitor visitor)`
`static void`
`visitDepthFirst(File[] files, IOVisitor visitor)`
`static void`
`visitDepthFirst(File file, IOVisitor visitor)`
`static void`
`writeFile(File file, byte[] bytes)`
`static void`
`writeObject(File file, Object object)`
`static void`
`writeText(File file, boolean append, String text)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### EOF

public static final int EOF

Since:
  3.1
See Also:
  - Constant Field Values

### DEFAULT_TIMEOUT

public static final long DEFAULT_TIMEOUT

Since:
  3.1

### DEFAULT_BUFFER_SIZE

public static final int DEFAULT_BUFFER_SIZE

See Also:
  - Constant Field Values

### WILDCARD_SINGLE_CHAR

public static final String WILDCARD_SINGLE_CHAR

Since:
  2.0
See Also:
  - Constant Field Values

### WILDCARD_MULTI_CHARS

public static final String WILDCARD_MULTI_CHARS

Since:
  2.0
See Also:
  - Constant Field Values

### WILDCARD_MULTI_DIRS

public static final String WILDCARD_MULTI_DIRS

Since:
  2.0
See Also:
  - Constant Field Values

## Method Details

### IN

public static InputStream IN()

### OUT

public static PrintStream OUT()

### ERR

public static PrintStream ERR()

### ioException

public static IOException ioException(Exception ex)

Since:
  3.13

### print

public static void print(StackTraceElement[] elements)

Since:
  3.1

### print

public static void print(StackTraceElement[] elements, PrintStream stream)

Since:
  3.1

### print

public static void print(Throwable t, PrintStream stream)

### print

public static void print(Throwable t)

### toString

public static String toString(Throwable t)

Since:
  2.0

### isFreePort

public static boolean isFreePort(int port)

Since:
  3.5

### getFreePort

public static int getFreePort() throws IOException

Throws:
  `IOException`
Since:
  3.5

### getSHA1

public static byte[] getSHA1(String contents) throws NoSuchAlgorithmException, IOException

Throws:
  `NoSuchAlgorithmException`
  `IOException`
Since:
  3.29

### getSHA1

public static byte[] getSHA1(InputStream contents) throws NoSuchAlgorithmException, IOException

Throws:
  `NoSuchAlgorithmException`
  `IOException`
Since:
  3.29

### encodeFileName

public static String encodeFileName(String path)

Since:
  3.29

### newURL

public static URL newURL(String url) throws MalformedURLException

Throws:
  `MalformedURLException`
Since:
  3.25

### openSystemBrowser

public static boolean openSystemBrowser(String url)

Since:
  3.5

### openInputStream

public static FileInputStream openInputStream(String fileName) throws IORuntimeException

Throws:
  `IORuntimeException`

### openInputStream

public static FileInputStream openInputStream(File file) throws IORuntimeException

Throws:
  `IORuntimeException`

### openOutputStream

public static FileOutputStream openOutputStream(String fileName) throws IORuntimeException

Throws:
  `IORuntimeException`

### openOutputStream

public static FileOutputStream openOutputStream(File file) throws IORuntimeException

Throws:
  `IORuntimeException`

### openReader

public static FileReader openReader(String fileName) throws IORuntimeException

Throws:
  `IORuntimeException`

### openReader

public static FileReader openReader(File file) throws IORuntimeException

Throws:
  `IORuntimeException`

### openWriter

public static FileWriter openWriter(String fileName) throws IORuntimeException

Throws:
  `IORuntimeException`

### openWriter

public static FileWriter openWriter(File file, boolean append) throws IORuntimeException

Throws:
  `IORuntimeException`
Since:
  3.9

### openWriter

public static FileWriter openWriter(File file) throws IORuntimeException

Throws:
  `IORuntimeException`

### nullOutputStream

public static OutputStream nullOutputStream()

Since:
  3.28

### buffered

public static BufferedInputStream buffered(InputStream in)

Since:
  3.26

### buffered

public static BufferedReader buffered(Reader in)

Since:
  3.26

### buffered

public static BufferedOutputStream buffered(OutputStream out)

Since:
  3.26

### buffered

public static BufferedWriter buffered(Writer out)

Since:
  3.26

### closeSilent

public static Exception closeSilent(Closeable closeable)

### close

public static void close(Closeable closeable) throws IORuntimeException

Throws:
  `IORuntimeException`

### closeSilent

public static Exception closeSilent(Closeable closeable)

### close

public static void close(Closeable closeable) throws IORuntimeException

Throws:
  `IORuntimeException`

### flushSilent

public static IOException flushSilent(Flushable flushable)

Since:
  3.3

### flush

public static void flush(Flushable flushable) throws IORuntimeException

Throws:
  `IORuntimeException`
Since:
  3.3

### makeRelative

public static String makeRelative(File file, File toFolder)

Since:
  2.0

### normalizeSeparator

public static String normalizeSeparator(String string)

Since:
  2.0

### mkdirs

public static void mkdirs(File folder)

### delete

public static int delete(File file)

### copyTree

public static void copyTree(File source, File target) throws IORuntimeException

Throws:
  `IORuntimeException`

### copyTrees

public static void copyTrees(Collection<File> sources, File target) throws IORuntimeException

Throws:
  `IORuntimeException`

### copyText

@SafeVarargs public static void copyText(File source, File target, IOFilter<String>... lineFilters) throws IORuntimeException

Throws:
  `IORuntimeException`

### copyText

@SafeVarargs public static void copyText(BufferedReader reader, BufferedWriter writer, IOFilter<String>... lineFilters)

### copyBinary

public static long copyBinary(InputStream inputStream, OutputStream outputStream) throws IOException

Throws:
  `IOException`
Since:
  3.1

### copyBinary

public static void copyBinary(InputStream inputStream, OutputStream outputStream, long size) throws IOException

Throws:
  `IOException`
Since:
  3.1

### copyCharacter

public static long copyCharacter(Reader reader, Writer writer) throws IOException

Throws:
  `IOException`
Since:
  3.1

### copyCharacter

public static void copyCharacter(Reader reader, Writer writer, long size) throws IOException

Throws:
  `IOException`
Since:
  3.1

### copy

public static int copy(InputStream input, OutputStream output, int size, byte[] buffer) throws IORuntimeException

Throws:
  `IORuntimeException`

### copy

public static void copy(InputStream input, OutputStream output, byte[] buffer) throws IORuntimeException

Throws:
  `IORuntimeException`

### copy

public static void copy(InputStream input, OutputStream output, int bufferSize) throws IORuntimeException

Throws:
  `IORuntimeException`

### copy

public static void copy(InputStream input, OutputStream output) throws IORuntimeException

Throws:
  `IORuntimeException`

### copyFile

public static void copyFile(File source, File target) throws IORuntimeException

Throws:
  `IORuntimeException`
See Also:
  - `NIOUtil.copyFile(File, File)`

### readText

public static String readText(Reader input) throws IORuntimeException

Throws:
  `IORuntimeException`
Since:
  3.25

### readText

public static String readText(URL url) throws IORuntimeException

Throws:
  `IORuntimeException`
Since:
  3.4

### readTextFile

public static String readTextFile(File file) throws IORuntimeException

Throws:
  `IORuntimeException`
Since:
  3.1

### readFile

public static byte[] readFile(File file) throws IORuntimeException

Throws:
  `IORuntimeException`

### readBytes

public static byte[] readBytes(InputStream in)

Since:
  3.29

### readBytes

public static byte[] readBytes(InputStream in, int initialBufferSize)

Since:
  3.29

### readObject

public static <T> T readObject(File file) throws Exception

Throws:
  `Exception`
Since:
  3.26

### readObject

public static <T> T readObject(File file, ClassLoader classLoader) throws Exception

Throws:
  `Exception`
Since:
  3.26

### readObject

public static <T> T readObject(File file, ExtendedIOUtil.ClassResolver classResolver) throws Exception

Throws:
  `Exception`
Since:
  3.26

### readObject

public static <T> T readObject(File file, ExtendedIOUtil.ClassResolver classResolver, ObjectInputFilter filter) throws Exception

Throws:
  `Exception`
Since:
  3.30

### writeObject

public static void writeObject(File file, Object object) throws Exception

Throws:
  `Exception`
Since:
  3.26

### writeFile

public static void writeFile(File file, byte[] bytes) throws IORuntimeException

Throws:
  `IORuntimeException`

### writeText

public static void writeText(File file, boolean append, String text) throws IORuntimeException

Throws:
  `IORuntimeException`
Since:
  3.9

### appendText

public static void appendText(File file, String text) throws IORuntimeException

Throws:
  `IORuntimeException`
Since:
  3.23

### loadProperties

public static Properties loadProperties(File file) throws IOException

Throws:
  `IOException`
Since:
  3.29

### saveProperties

public static void saveProperties(File file, Properties properties, String comments) throws IOException

Throws:
  `IOException`
Since:
  3.29

### listDepthFirst

public static List<File> listDepthFirst(File file)

### listBreadthFirst

public static List<File> listBreadthFirst(File file)

### visitDepthFirst

public static void visitDepthFirst(File file, IOVisitor visitor) throws IORuntimeException

Throws:
  `IORuntimeException`

### visitDepthFirst

public static void visitDepthFirst(File[] files, IOVisitor visitor)

### visitBreadthFirst

public static void visitBreadthFirst(File file, IOVisitor visitor) throws IORuntimeException

Throws:
  `IORuntimeException`

### visitBreadthFirst

public static void visitBreadthFirst(File[] files, IOVisitor visitor) throws IORuntimeException

Throws:
  `IORuntimeException`

### safeRun

public static <IO extends Closeable> void safeRun(IO io, IORunnable<IO> runnable) throws IORuntimeException

Throws:
  `IORuntimeException`

### safeInput

public static void safeInput(File file, IORunnable<FileInputStream> runnable) throws IORuntimeException

Throws:
  `IORuntimeException`

### safeOutput

public static void safeOutput(File file, IORunnable<FileOutputStream> runnable) throws IORuntimeException

Throws:
  `IORuntimeException`

### safeRead

public static void safeRead(File file, IORunnable<FileReader> runnable) throws IORuntimeException

Throws:
  `IORuntimeException`

### safeWrite

public static void safeWrite(File file, IORunnable<FileWriter> runnable) throws IORuntimeException

Throws:
  `IORuntimeException`

### equals

public static boolean equals(InputStream stream1, InputStream stream2) throws IORuntimeException

Throws:
  `IORuntimeException`

### equals

public static boolean equals(Reader reader1, Reader reader2) throws IORuntimeException

Throws:
  `IORuntimeException`
Since:
  3.2

### equals

public static boolean equals(File file1, File file2) throws IORuntimeException

Throws:
  `IORuntimeException`

### glob

public static List<File> glob(String pattern, File folder)

Since:
  2.0