Class IOUtils


  • public class IOUtils
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.nio.ByteBuffer clone​(java.nio.ByteBuffer original)  
      static PathPrivilege readPathPrivilege​(java.io.DataInputStream inputStream, java.lang.String encoding, java.lang.ThreadLocal<byte[]> strBufferLocal)
      Read a PathPrivilege from the given stream.
      static java.lang.String readString​(java.io.DataInputStream inputStream, java.lang.String encoding, java.lang.ThreadLocal<byte[]> strBufferLocal)
      Read a string from the given stream.
      static void replaceFile​(java.io.File newFile, java.io.File oldFile)
      Replace newFile with oldFile.
      static void writeInt​(java.io.OutputStream outputStream, int i, java.lang.ThreadLocal<java.nio.ByteBuffer> encodingBufferLocal)
      Write an integer into the given stream.
      static void writePathPrivilege​(java.io.OutputStream outputStream, PathPrivilege pathPrivilege, java.lang.String encoding, java.lang.ThreadLocal<java.nio.ByteBuffer> encodingBufferLocal)
      Write a PathPrivilege to the given stream.
      static void writeString​(java.io.OutputStream outputStream, java.lang.String str, java.lang.String encoding, java.lang.ThreadLocal<java.nio.ByteBuffer> encodingBufferLocal)
      Write a string into the given stream.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • writeString

        public static void writeString​(java.io.OutputStream outputStream,
                                       java.lang.String str,
                                       java.lang.String encoding,
                                       java.lang.ThreadLocal<java.nio.ByteBuffer> encodingBufferLocal)
                                throws java.io.IOException
        Write a string into the given stream.
        Parameters:
        outputStream - the destination to insert.
        str - the string to be written.
        encoding - string encoding like 'utf-8'.
        encodingBufferLocal - a ThreadLocal buffer may be passed to avoid frequently memory allocations. A null may also be passed to use a local buffer.
        Throws:
        java.io.IOException - when an exception raised during operating the stream.
      • writeInt

        public static void writeInt​(java.io.OutputStream outputStream,
                                    int i,
                                    java.lang.ThreadLocal<java.nio.ByteBuffer> encodingBufferLocal)
                             throws java.io.IOException
        Write an integer into the given stream.
        Parameters:
        outputStream - the destination to insert.
        i - the integer to be written.
        encodingBufferLocal - a ThreadLocal buffer may be passed to avoid frequently memory allocations. A null may also be passed to use a local buffer.
        Throws:
        java.io.IOException - when an exception raised during operating the stream.
      • readString

        public static java.lang.String readString​(java.io.DataInputStream inputStream,
                                                  java.lang.String encoding,
                                                  java.lang.ThreadLocal<byte[]> strBufferLocal)
                                           throws java.io.IOException
        Read a string from the given stream.
        Parameters:
        inputStream - the source to read.
        encoding - string encoding like 'utf-8'.
        strBufferLocal - a ThreadLocal buffer may be passed to avoid frequently memory allocations. A null may also be passed to use a local buffer.
        Returns:
        a string read from the stream.
        Throws:
        java.io.IOException - when an exception raised during operating the stream.
      • readPathPrivilege

        public static PathPrivilege readPathPrivilege​(java.io.DataInputStream inputStream,
                                                      java.lang.String encoding,
                                                      java.lang.ThreadLocal<byte[]> strBufferLocal)
                                               throws java.io.IOException,
                                                      IllegalPathException
        Read a PathPrivilege from the given stream.
        Parameters:
        inputStream - the source to read.
        encoding - string encoding like 'utf-8'.
        strBufferLocal - a ThreadLocal buffer may be passed to avoid frequently memory allocations. A null may also be passed to use a local buffer.
        Returns:
        a PathPrivilege read from the stream.
        Throws:
        java.io.IOException - when an exception raised during operating the stream.
        IllegalPathException
      • writePathPrivilege

        public static void writePathPrivilege​(java.io.OutputStream outputStream,
                                              PathPrivilege pathPrivilege,
                                              java.lang.String encoding,
                                              java.lang.ThreadLocal<java.nio.ByteBuffer> encodingBufferLocal)
                                       throws java.io.IOException
        Write a PathPrivilege to the given stream.
        Parameters:
        outputStream - the destination to insert.
        pathPrivilege - the PathPrivilege to be written.
        encoding - string encoding like 'utf-8'.
        encodingBufferLocal - a ThreadLocal buffer may be passed to avoid frequently memory allocations. A null may also be passed to use a local buffer.
        Throws:
        java.io.IOException - when an exception raised during operating the stream.
      • replaceFile

        public static void replaceFile​(java.io.File newFile,
                                       java.io.File oldFile)
                                throws java.io.IOException
        Replace newFile with oldFile. If the file system does not support atomic file replacement then delete the old file first.
        Parameters:
        newFile - the new file.
        oldFile - the file to be replaced.
        Throws:
        java.io.IOException
      • clone

        public static java.nio.ByteBuffer clone​(java.nio.ByteBuffer original)