com.hazelcast.nio

## Class IOUtil

- java.lang.Object
- - com.hazelcast.nio.IOUtil

-     @PrivateApi
      public final class IOUtil
      extends Object

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static byte` | `PRIMITIVE_TYPE_BOOLEAN`
    `static byte` | `PRIMITIVE_TYPE_BYTE`
    `static byte` | `PRIMITIVE_TYPE_DOUBLE`
    `static byte` | `PRIMITIVE_TYPE_FLOAT`
    `static byte` | `PRIMITIVE_TYPE_INTEGER`
    `static byte` | `PRIMITIVE_TYPE_LONG`
    `static byte` | `PRIMITIVE_TYPE_SHORT`
    `static byte` | `PRIMITIVE_TYPE_UTF`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `close(Connection conn, String reason)`
    `static void` | `close(ServerSocket serverSocket)` Quietly attempts to close a `ServerSocket`, swallowing any exception.
    `static void` | `close(Socket socket)` Quietly attempts to close a `Socket`, swallowing any exception.
    `static void` | `closeResource(Closeable closeable)` Quietly attempts to close a `Closeable` resource, swallowing any exception.
    `static void` | `compactOrClear(ByteBuffer bb)` Compacts or clears the buffer depending if bytes are remaining in the byte-buffer.
    `static byte[]` | `compress(byte[] input)`
    `static void` | `copy(File source, File target)` Deep copies source to target and creates the target if necessary.
    `static void` | `copy(InputStream source, File target)` Deep copies source to target.
    `static void` | `copyFile(File source, File target, long sourceCount)` Copies source file to target and creates the target if necessary.
    `static int` | `copyToHeapBuffer(ByteBuffer src, ByteBuffer dst)`
    `static byte[]` | `decompress(byte[] compressedData)`
    `static void` | `delete(File f)` Ensures that the file described by the supplied parameter does not exist after the method returns.
    `static void` | `deleteQuietly(File f)` Ensures that the file described by the supplied parameter does not exist after the method returns.
    `static void` | `drainTo(InputStream input, OutputStream output)`
    `static File` | `getFileFromResources(String resourceFileName)`
    `static InputStream` | `getFileFromResourcesAsStream(String resourceFileName)`
    `static String` | `getPath(String... parts)` Concatenates path parts to a single path using the `File.separator` where it applies.
    `static ByteBuffer` | `newByteBuffer(int bufferSize, boolean direct)`
    `static InputStream` | `newInputStream(ByteBuffer src)`
    `static ObjectInputStream` | `newObjectInputStream(ClassLoader classLoader, ClassNameFilter classFilter, InputStream in)`
    `static OutputStream` | `newOutputStream(ByteBuffer dst)`
    `static Object` | `readAttributeValue(ObjectDataInput in)`
    `static byte[]` | `readByteArray(ObjectDataInput in)`
    `static void` | `readFully(InputStream in, byte[] buffer)` Fills a buffer from an `InputStream`.
    `static boolean` | `readFullyOrNothing(InputStream in, byte[] buffer)` Fills a buffer from an `InputStream`.
    `static <T> T` | `readObject(ObjectDataInput in)`
    `static void` | `rename(File fileNow, File fileToBe)` Ensures that the file described by `fileNow` is renamed to file described by `fileToBe`.
    `static void` | `setChannelOptions(com.hazelcast.internal.networking.Channel channel, EndpointConfig config)` Sets configured channel options on given `Channel`.
    `static byte[]` | `toByteArray(InputStream is)`
    `static String` | `toDebugString(String name, ByteBuffer byteBuffer)` Creates a debug String for te given ByteBuffer.
    `static String` | `toFileName(String name)`
    `static void` | `touch(File file)` Simulates a Linux `touch` command, by setting the last modified time of given file.
    `static void` | `writeAttributeValue(Object value, ObjectDataOutput out)`
    `static void` | `writeByteArray(ObjectDataOutput out, byte[] value)`
    `static void` | `writeObject(ObjectDataOutput out, Object object)`

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

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

- - ### Field Detail

    - #### PRIMITIVE_TYPE_BOOLEAN

          public static final byte PRIMITIVE_TYPE_BOOLEAN

      See Also:
        Constant Field Values

    - #### PRIMITIVE_TYPE_BYTE

          public static final byte PRIMITIVE_TYPE_BYTE

      See Also:
        Constant Field Values

    - #### PRIMITIVE_TYPE_SHORT

          public static final byte PRIMITIVE_TYPE_SHORT

      See Also:
        Constant Field Values

    - #### PRIMITIVE_TYPE_INTEGER

          public static final byte PRIMITIVE_TYPE_INTEGER

      See Also:
        Constant Field Values

    - #### PRIMITIVE_TYPE_LONG

          public static final byte PRIMITIVE_TYPE_LONG

      See Also:
        Constant Field Values

    - #### PRIMITIVE_TYPE_FLOAT

          public static final byte PRIMITIVE_TYPE_FLOAT

      See Also:
        Constant Field Values

    - #### PRIMITIVE_TYPE_DOUBLE

          public static final byte PRIMITIVE_TYPE_DOUBLE

      See Also:
        Constant Field Values

    - #### PRIMITIVE_TYPE_UTF

          public static final byte PRIMITIVE_TYPE_UTF

      See Also:
        Constant Field Values

  - ### Method Detail

    - #### compactOrClear

          public static void compactOrClear(ByteBuffer bb)

      Compacts or clears the buffer depending if bytes are remaining in the byte-buffer.
      Parameters:
        `bb` - the ByteBuffer

    - #### newByteBuffer

          public static ByteBuffer newByteBuffer(int bufferSize,
                                                 boolean direct)

    - #### writeByteArray

          public static void writeByteArray(ObjectDataOutput out,
                                            byte[] value)
                                     throws IOException

      Throws:
        `IOException`

    - #### readByteArray

          public static byte[] readByteArray(ObjectDataInput in)
                                      throws IOException

      Throws:
        `IOException`

    - #### writeObject

          public static void writeObject(ObjectDataOutput out,
                                         Object object)
                                  throws IOException

      Throws:
        `IOException`

    - #### readObject

          public static <T> T readObject(ObjectDataInput in)
                                  throws IOException

      Throws:
        `IOException`

    - #### readFullyOrNothing

          public static boolean readFullyOrNothing(InputStream in,
                                                   byte[] buffer)
                                            throws IOException

      Fills a buffer from an `InputStream`. If it doesn't contain any more data, returns `false`. If it contains some data, but not enough to fill the buffer, `EOFException` is thrown.
      Parameters:
        `in` - the `InputStream` to read from
        `buffer` - the buffer to fill
      Returns:
        `true` if the buffer was filled completely, `false` if there was no data in the `InputStream`
      Throws:
        `EOFException` - if there was some, but not enough, data in the `InputStream` to fill the buffer
        `IOException`

    - #### readFully

          public static void readFully(InputStream in,
                                       byte[] buffer)
                                throws IOException

      Fills a buffer from an `InputStream`.
      Parameters:
        `in` - the `InputStream` to read from
        `buffer` - the buffer to fill
      Throws:
        `EOFException` - if there was not enough data in the `InputStream` to fill the buffer
        `IOException`

    - #### newObjectInputStream

          public static ObjectInputStream newObjectInputStream(ClassLoader classLoader,
                                                               ClassNameFilter classFilter,
                                                               InputStream in)
                                                        throws IOException

      Throws:
        `IOException`

    - #### newOutputStream

          public static OutputStream newOutputStream(ByteBuffer dst)

    - #### newInputStream

          public static InputStream newInputStream(ByteBuffer src)

    - #### copyToHeapBuffer

          public static int copyToHeapBuffer(ByteBuffer src,
                                             ByteBuffer dst)

    - #### compress

          public static byte[] compress(byte[] input)

    - #### decompress

          public static byte[] decompress(byte[] compressedData)

    - #### writeAttributeValue

          public static void writeAttributeValue(Object value,
                                                 ObjectDataOutput out)
                                          throws IOException

      Throws:
        `IOException`

    - #### readAttributeValue

          public static Object readAttributeValue(ObjectDataInput in)
                                           throws IOException

      Throws:
        `IOException`

    - #### closeResource

          public static void closeResource(Closeable closeable)

      Quietly attempts to close a `Closeable` resource, swallowing any exception.
      Parameters:
        `closeable` - the resource to close. If `null`, no action is taken.

    - #### close

          public static void close(Connection conn,
                                   String reason)

    - #### close

          public static void close(ServerSocket serverSocket)

      Quietly attempts to close a `ServerSocket`, swallowing any exception.
      Parameters:
        `serverSocket` - server socket to close. If `null`, no action is taken.

    - #### close

          public static void close(Socket socket)

      Quietly attempts to close a `Socket`, swallowing any exception.
      Parameters:
        `socket` - socket to close. If `null`, no action is taken.

    - #### deleteQuietly

          public static void deleteQuietly(File f)

      Ensures that the file described by the supplied parameter does not exist after the method returns. If the file didn't exist, returns silently. If the file could not be deleted, returns silently. If the file is a directory, its children are recursively deleted.

    - #### delete

          public static void delete(File f)

      Ensures that the file described by the supplied parameter does not exist after the method returns. If the file didn't exist, returns silently. If the file could not be deleted, fails with an exception. If the file is a directory, its children are recursively deleted.

    - #### rename

          public static void rename(File fileNow,
                                    File fileToBe)

      Ensures that the file described by `fileNow` is renamed to file described by `fileToBe`. First attempts to perform a direct, atomic rename; if that fails, checks whether the target exists, deletes it, and retries. Throws an exception in each case where the rename failed.
      Parameters:
        `fileNow` - describes an existing file
        `fileToBe` - describes the desired pathname for the file

    - #### toFileName

          public static String toFileName(String name)

    - #### getPath

          public static String getPath(String... parts)

      Concatenates path parts to a single path using the `File.separator` where it applies. There is no validation done on the newly formed path.
      Parameters:
        `parts` - The path parts that together should form a path
      Returns:
        The path formed using the parts
      Throws:
        `IllegalArgumentException` - if the parts param is null or empty

    - #### getFileFromResources

          public static File getFileFromResources(String resourceFileName)

    - #### getFileFromResourcesAsStream

          public static InputStream getFileFromResourcesAsStream(String resourceFileName)

    - #### touch

          public static void touch(File file)

      Simulates a Linux `touch` command, by setting the last modified time of given file.
      Parameters:
        `file` - the file to touch

    - #### copy

          public static void copy(File source,
                                  File target)

      Deep copies source to target and creates the target if necessary.

      The source can be a directory or a file and the target can be a directory or file.

      If the source is a directory, it expects that the target is a directory (or that it doesn't exist) and nests the copied source under the target directory.

      Parameters:
        `source` - the source
        `target` - the destination
      Throws:
        `IllegalArgumentException` - if the source was not found or the source is a directory and the target is a file
        `HazelcastException` - if there was any exception while creating directories or copying

    - #### copy

          public static void copy(InputStream source,
                                  File target)

      Deep copies source to target. If target doesn't exist, this will fail with `HazelcastException`.

      The source is only accessed here, but not managed. It's the responsibility of the caller to release any resources hold by the source.

      Parameters:
        `source` - the source
        `target` - the destination
      Throws:
        `HazelcastException` - if the target doesn't exist

    - #### copyFile

          public static void copyFile(File source,
                                      File target,
                                      long sourceCount)

      Copies source file to target and creates the target if necessary. The target can be a directory or file. If the target is a file, nests the new file under the target directory, otherwise copies to the given target.
      Parameters:
        `source` - the source file
        `target` - the destination file or directory
        `sourceCount` - the maximum number of bytes to be transferred (if negative transfers the entire source file)
      Throws:
        `IllegalArgumentException` - if the source was not found or the source not a file
        `HazelcastException` - if there was any exception while creating directories or copying

    - #### toByteArray

          public static byte[] toByteArray(InputStream is)
                                    throws IOException

      Throws:
        `IOException`

    - #### drainTo

          public static void drainTo(InputStream input,
                                     OutputStream output)
                              throws IOException

      Throws:
        `IOException`

    - #### toDebugString

          public static String toDebugString(String name,
                                             ByteBuffer byteBuffer)

      Creates a debug String for te given ByteBuffer. Useful when debugging IO.

      Do not remove even if this method isn't used.

      Parameters:
        `name` - name of the ByteBuffer.
        `byteBuffer` - the ByteBuffer
      Returns:
        the debug String

    - #### setChannelOptions

          public static void setChannelOptions(com.hazelcast.internal.networking.Channel channel,
                                               EndpointConfig config)

      Sets configured channel options on given `Channel`.
      Parameters:
        `channel` - the `Channel` on which options will be set
        `config` - the endpoint configuration

Copyright © 2019. All rights reserved.