Package org.eclipse.net4j.util.io

## Class IOUtil

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

-     public final class IOUtil
      extends java.lang.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 int` | `DEFAULT_BUFFER_SIZE` |
    `static long` | `DEFAULT_TIMEOUT` |
    `static int` | `EOF` |
    `static java.lang.String` | `WILDCARD_MULTI_CHARS` |
    `static java.lang.String` | `WILDCARD_MULTI_DIRS` |
    `static java.lang.String` | `WILDCARD_SINGLE_CHAR` |

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `static void` | `close​(java.io.Closeable closeable)` |
    `static void` | `close​(Closeable closeable)` |
    `static java.lang.Exception` | `closeSilent​(java.io.Closeable closeable)` |
    `static java.lang.Exception` | `closeSilent​(Closeable closeable)` |
    `static void` | `copy​(java.io.InputStream input, java.io.OutputStream output)` |
    `static void` | `copy​(java.io.InputStream input, java.io.OutputStream output, byte[] buffer)` |
    `static void` | `copy​(java.io.InputStream input, java.io.OutputStream output, int bufferSize)` |
    `static int` | `copy​(java.io.InputStream input, java.io.OutputStream output, int size, byte[] buffer)` |
    `static long` | `copyBinary​(java.io.InputStream inputStream, java.io.OutputStream outputStream)` |
    `static void` | `copyBinary​(java.io.InputStream inputStream, java.io.OutputStream outputStream, long size)` |
    `static long` | `copyCharacter​(java.io.Reader reader, java.io.Writer writer)` |
    `static void` | `copyCharacter​(java.io.Reader reader, java.io.Writer writer, long size)` |
    `static void` | `copyFile​(java.io.File source, java.io.File target)` |
    `static void` | `copyText​(java.io.BufferedReader reader, java.io.BufferedWriter writer, IOFilter<java.lang.String>... lineFilters)` |
    `static void` | `copyText​(java.io.File source, java.io.File target, IOFilter<java.lang.String>... lineFilters)` |
    `static void` | `copyTree​(java.io.File source, java.io.File target)` |
    `static void` | `copyTrees​(java.util.Collection<java.io.File> sources, java.io.File target)` |
    `static int` | `delete​(java.io.File file)` |
    `static boolean` | `equals​(java.io.File file1, java.io.File file2)` |
    `static boolean` | `equals​(java.io.InputStream stream1, java.io.InputStream stream2)` |
    `static boolean` | `equals​(java.io.Reader reader1, java.io.Reader reader2)` |
    `static java.io.PrintStream` | `ERR()` |
    `static void` | `flush​(java.io.Flushable flushable)` |
    `static java.io.IOException` | `flushSilent​(java.io.Flushable flushable)` |
    `static int` | `getFreePort()` |
    `static java.util.List<java.io.File>` | `glob​(java.lang.String pattern, java.io.File folder)` |
    `static java.io.InputStream` | `IN()` |
    `static java.io.IOException` | `ioException​(java.lang.Exception ex)` |
    `static boolean` | `isFreePort​(int port)` |
    `static java.util.List<java.io.File>` | `listBreadthFirst​(java.io.File file)` |
    `static java.util.List<java.io.File>` | `listDepthFirst​(java.io.File file)` |
    `static java.lang.String` | `makeRelative​(java.io.File file, java.io.File toFolder)` |
    `static void` | `mkdirs​(java.io.File folder)` |
    `static java.lang.String` | `normalizeSeparator​(java.lang.String string)` |
    `static java.io.FileInputStream` | `openInputStream​(java.io.File file)` |
    `static java.io.FileInputStream` | `openInputStream​(java.lang.String fileName)` |
    `static java.io.FileOutputStream` | `openOutputStream​(java.io.File file)` |
    `static java.io.FileOutputStream` | `openOutputStream​(java.lang.String fileName)` |
    `static java.io.FileReader` | `openReader​(java.io.File file)` |
    `static java.io.FileReader` | `openReader​(java.lang.String fileName)` |
    `static boolean` | `openSystemBrowser​(java.lang.String url)` |
    `static java.io.FileWriter` | `openWriter​(java.io.File file)` |
    `static java.io.FileWriter` | `openWriter​(java.io.File file, boolean append)` |
    `static java.io.FileWriter` | `openWriter​(java.lang.String fileName)` |
    `static java.io.PrintStream` | `OUT()` |
    `static void` | `print​(java.lang.StackTraceElement[] elements)` |
    `static void` | `print​(java.lang.StackTraceElement[] elements, java.io.PrintStream stream)` |
    `static void` | `print​(java.lang.Throwable t)` |
    `static void` | `print​(java.lang.Throwable t, java.io.PrintStream stream)` |
    `static byte[]` | `readFile​(java.io.File file)` |
    `static java.lang.String` | `readText​(java.net.URL url)` |
    `static java.lang.String` | `readTextFile​(java.io.File file)` |
    `static void` | `safeInput​(java.io.File file, IORunnable<java.io.FileInputStream> runnable)` |
    `static void` | `safeOutput​(java.io.File file, IORunnable<java.io.FileOutputStream> runnable)` |
    `static void` | `safeRead​(java.io.File file, IORunnable<java.io.FileReader> runnable)` |
    `static <IO extends java.io.Closeable> void` | `safeRun​(IO io, IORunnable<IO> runnable)` |
    `static void` | `safeWrite​(java.io.File file, IORunnable<java.io.FileWriter> runnable)` |
    `static java.lang.String` | `toString​(java.lang.Throwable t)` |
    `static void` | `visitBreadthFirst​(java.io.File[] files, IOVisitor visitor)` |
    `static void` | `visitBreadthFirst​(java.io.File file, IOVisitor visitor)` |
    `static void` | `visitDepthFirst​(java.io.File[] files, IOVisitor visitor)` |
    `static void` | `visitDepthFirst​(java.io.File file, IOVisitor visitor)` |
    `static void` | `writeFile​(java.io.File file, byte[] bytes)` |
    `static void` | `writeText​(java.io.File file, boolean append, java.lang.String text)` |

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

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

- - ### Field Detail

    - #### 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 java.lang.String WILDCARD_SINGLE_CHAR

      Since:
        2.0
      See Also:
        Constant Field Values

    - #### WILDCARD_MULTI_CHARS

          public static final java.lang.String WILDCARD_MULTI_CHARS

      Since:
        2.0
      See Also:
        Constant Field Values

    - #### WILDCARD_MULTI_DIRS

          public static final java.lang.String WILDCARD_MULTI_DIRS

      Since:
        2.0
      See Also:
        Constant Field Values

  - ### Method Detail

    - #### IN

          public static java.io.InputStream IN()

    - #### OUT

          public static java.io.PrintStream OUT()

    - #### ERR

          public static java.io.PrintStream ERR()

    - #### ioException

          public static java.io.IOException ioException​(java.lang.Exception ex)

      Since:
        3.13

    - #### print

          public static void print​(java.lang.StackTraceElement[] elements)

      Since:
        3.1

    - #### print

          public static void print​(java.lang.StackTraceElement[] elements,
                                   java.io.PrintStream stream)

      Since:
        3.1

    - #### print

          public static void print​(java.lang.Throwable t,
                                   java.io.PrintStream stream)

    - #### print

          public static void print​(java.lang.Throwable t)

    - #### toString

          public static java.lang.String toString​(java.lang.Throwable t)

      Since:
        2.0

    - #### isFreePort

          public static boolean isFreePort​(int port)

      Since:
        3.5

    - #### getFreePort

          public static int getFreePort()
                                 throws java.io.IOException

      Throws:
        `java.io.IOException`
      Since:
        3.5

    - #### openSystemBrowser

          public static boolean openSystemBrowser​(java.lang.String url)

      Since:
        3.5

    - #### openInputStream

          public static java.io.FileInputStream openInputStream​(java.lang.String fileName)
                                                         throws IORuntimeException

      Throws:
        `IORuntimeException`

    - #### openInputStream

          public static java.io.FileInputStream openInputStream​(java.io.File file)
                                                         throws IORuntimeException

      Throws:
        `IORuntimeException`

    - #### openOutputStream

          public static java.io.FileOutputStream openOutputStream​(java.lang.String fileName)
                                                           throws IORuntimeException

      Throws:
        `IORuntimeException`

    - #### openOutputStream

          public static java.io.FileOutputStream openOutputStream​(java.io.File file)
                                                           throws IORuntimeException

      Throws:
        `IORuntimeException`

    - #### openReader

          public static java.io.FileReader openReader​(java.lang.String fileName)
                                               throws IORuntimeException

      Throws:
        `IORuntimeException`

    - #### openReader

          public static java.io.FileReader openReader​(java.io.File file)
                                               throws IORuntimeException

      Throws:
        `IORuntimeException`

    - #### openWriter

          public static java.io.FileWriter openWriter​(java.lang.String fileName)
                                               throws IORuntimeException

      Throws:
        `IORuntimeException`

    - #### openWriter

          public static java.io.FileWriter openWriter​(java.io.File file,
                                                      boolean append)
                                               throws IORuntimeException

      Throws:
        `IORuntimeException`
      Since:
        3.9

    - #### openWriter

          public static java.io.FileWriter openWriter​(java.io.File file)
                                               throws IORuntimeException

      Throws:
        `IORuntimeException`

    - #### closeSilent

          public static java.lang.Exception closeSilent​(java.io.Closeable closeable)

    - #### close

          public static void close​(java.io.Closeable closeable)
                            throws IORuntimeException

      Throws:
        `IORuntimeException`

    - #### closeSilent

          public static java.lang.Exception closeSilent​(Closeable closeable)

    - #### close

          public static void close​(Closeable closeable)
                            throws IORuntimeException

      Throws:
        `IORuntimeException`

    - #### flushSilent

          public static java.io.IOException flushSilent​(java.io.Flushable flushable)

      Since:
        3.3

    - #### flush

          public static void flush​(java.io.Flushable flushable)
                            throws IORuntimeException

      Throws:
        `IORuntimeException`
      Since:
        3.3

    - #### makeRelative

          public static java.lang.String makeRelative​(java.io.File file,
                                                      java.io.File toFolder)

      Since:
        2.0

    - #### normalizeSeparator

          public static java.lang.String normalizeSeparator​(java.lang.String string)

      Since:
        2.0

    - #### mkdirs

          public static void mkdirs​(java.io.File folder)

    - #### delete

          public static int delete​(java.io.File file)

    - #### copyTree

          public static void copyTree​(java.io.File source,
                                      java.io.File target)
                               throws IORuntimeException

      Throws:
        `IORuntimeException`

    - #### copyTrees

          public static void copyTrees​(java.util.Collection<java.io.File> sources,
                                       java.io.File target)
                                throws IORuntimeException

      Throws:
        `IORuntimeException`

    - #### copyText

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

      Throws:
        `IORuntimeException`

    - #### copyText

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

    - #### copyBinary

          public static long copyBinary​(java.io.InputStream inputStream,
                                        java.io.OutputStream outputStream)
                                 throws java.io.IOException

      Throws:
        `java.io.IOException`
      Since:
        3.1

    - #### copyBinary

          public static void copyBinary​(java.io.InputStream inputStream,
                                        java.io.OutputStream outputStream,
                                        long size)
                                 throws java.io.IOException

      Throws:
        `java.io.IOException`
      Since:
        3.1

    - #### copyCharacter

          public static long copyCharacter​(java.io.Reader reader,
                                           java.io.Writer writer)
                                    throws java.io.IOException

      Throws:
        `java.io.IOException`
      Since:
        3.1

    - #### copyCharacter

          public static void copyCharacter​(java.io.Reader reader,
                                           java.io.Writer writer,
                                           long size)
                                    throws java.io.IOException

      Throws:
        `java.io.IOException`
      Since:
        3.1

    - #### copy

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

      Throws:
        `IORuntimeException`

    - #### copy

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

      Throws:
        `IORuntimeException`

    - #### copy

          public static void copy​(java.io.InputStream input,
                                  java.io.OutputStream output,
                                  int bufferSize)
                           throws IORuntimeException

      Throws:
        `IORuntimeException`

    - #### copy

          public static void copy​(java.io.InputStream input,
                                  java.io.OutputStream output)
                           throws IORuntimeException

      Throws:
        `IORuntimeException`

    - #### copyFile

          public static void copyFile​(java.io.File source,
                                      java.io.File target)
                               throws IORuntimeException

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

    - #### readText

          public static java.lang.String readText​(java.net.URL url)
                                           throws IORuntimeException

      Throws:
        `IORuntimeException`
      Since:
        3.4

    - #### readTextFile

          public static java.lang.String readTextFile​(java.io.File file)
                                               throws IORuntimeException

      Throws:
        `IORuntimeException`
      Since:
        3.1

    - #### readFile

          public static byte[] readFile​(java.io.File file)
                                 throws IORuntimeException

      Throws:
        `IORuntimeException`

    - #### writeFile

          public static void writeFile​(java.io.File file,
                                       byte[] bytes)
                                throws IORuntimeException

      Throws:
        `IORuntimeException`

    - #### writeText

          public static void writeText​(java.io.File file,
                                       boolean append,
                                       java.lang.String text)
                                throws IORuntimeException

      Throws:
        `IORuntimeException`
      Since:
        3.9

    - #### listDepthFirst

          public static java.util.List<java.io.File> listDepthFirst​(java.io.File file)

    - #### listBreadthFirst

          public static java.util.List<java.io.File> listBreadthFirst​(java.io.File file)

    - #### visitDepthFirst

          public static void visitDepthFirst​(java.io.File file,
                                             IOVisitor visitor)
                                      throws IORuntimeException

      Throws:
        `IORuntimeException`

    - #### visitDepthFirst

          public static void visitDepthFirst​(java.io.File[] files,
                                             IOVisitor visitor)

    - #### visitBreadthFirst

          public static void visitBreadthFirst​(java.io.File file,
                                               IOVisitor visitor)
                                        throws IORuntimeException

      Throws:
        `IORuntimeException`

    - #### visitBreadthFirst

          public static void visitBreadthFirst​(java.io.File[] files,
                                               IOVisitor visitor)
                                        throws IORuntimeException

      Throws:
        `IORuntimeException`

    - #### safeRun

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

      Throws:
        `IORuntimeException`

    - #### safeInput

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

      Throws:
        `IORuntimeException`

    - #### safeOutput

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

      Throws:
        `IORuntimeException`

    - #### safeRead

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

      Throws:
        `IORuntimeException`

    - #### safeWrite

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

      Throws:
        `IORuntimeException`

    - #### equals

          public static boolean equals​(java.io.InputStream stream1,
                                       java.io.InputStream stream2)
                                throws IORuntimeException

      Throws:
        `IORuntimeException`

    - #### equals

          public static boolean equals​(java.io.Reader reader1,
                                       java.io.Reader reader2)
                                throws IORuntimeException

      Throws:
        `IORuntimeException`
      Since:
        3.2

    - #### equals

          public static boolean equals​(java.io.File file1,
                                       java.io.File file2)
                                throws IORuntimeException

      Throws:
        `IORuntimeException`

    - #### glob

          public static java.util.List<java.io.File> glob​(java.lang.String pattern,
                                                          java.io.File folder)

      Since:
        2.0