Class IOUtils


  • public class IOUtils
    extends java.lang.Object
    Utilities for I/O streams.
    Since:
    1.14
    • Constructor Summary

      Constructors 
      Constructor Description
      IOUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static long computeLength​(StreamingContent content)
      Computes and returns the byte content length for a streaming content by calling StreamingContent.writeTo(OutputStream) on a fake output stream that only counts bytes written.
      static void copy​(java.io.InputStream inputStream, java.io.OutputStream outputStream)
      Deprecated.
      use ByteStreams.copy(InputStream, OutputStream)
      static void copy​(java.io.InputStream inputStream, java.io.OutputStream outputStream, boolean closeInputStream)
      Deprecated.
      use ByteStreams.copy(InputStream, OutputStream)
      static <S extends java.io.Serializable>
      S
      deserialize​(byte[] bytes)
      Deserializes the given byte array into to a newly allocated object.
      static <S extends java.io.Serializable>
      S
      deserialize​(java.io.InputStream inputStream)
      Deserializes the given input stream into to a newly allocated object, and close the input stream.
      static boolean isSymbolicLink​(java.io.File file)
      Deprecated.
      use java.nio.file.Path#isSymbolicLink
      static byte[] serialize​(java.lang.Object value)
      Serializes the given object value to a newly allocated byte array.
      static void serialize​(java.lang.Object value, java.io.OutputStream outputStream)
      Serializes the given object value to an output stream, and close the output stream.
      • Methods inherited from class java.lang.Object

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

      • IOUtils

        public IOUtils()
    • Method Detail

      • copy

        @Deprecated
        public static void copy​(java.io.InputStream inputStream,
                                java.io.OutputStream outputStream)
                         throws java.io.IOException
        Deprecated.
        use ByteStreams.copy(InputStream, OutputStream)
        Writes the content provided by the given source input stream into the given destination output stream.

        The input stream is guaranteed to be closed at the end of this method.

        Sample use:

         static void copy(InputStream inputStream, File file) throws IOException {
         FileOutputStream out = new FileOutputStream(file);
         try {
         IOUtils.copy(inputStream, out);
         } finally {
         out.close();
         }
         }
         
        Parameters:
        inputStream - source input stream
        outputStream - destination output stream
        Throws:
        java.io.IOException
      • copy

        @Deprecated
        public static void copy​(java.io.InputStream inputStream,
                                java.io.OutputStream outputStream,
                                boolean closeInputStream)
                         throws java.io.IOException
        Deprecated.
        use ByteStreams.copy(InputStream, OutputStream)
        Writes the content provided by the given source input stream into the given destination output stream, optionally closing the input stream.

        Sample use:

         static void copy(InputStream inputStream, File file) throws IOException {
         FileOutputStream out = new FileOutputStream(file);
         try {
         IOUtils.copy(inputStream, out, true);
         } finally {
         out.close();
         }
         }
         
        Parameters:
        inputStream - source input stream
        outputStream - destination output stream
        closeInputStream - whether the input stream should be closed at the end of this method
        Throws:
        java.io.IOException
      • computeLength

        public static long computeLength​(StreamingContent content)
                                  throws java.io.IOException
        Computes and returns the byte content length for a streaming content by calling StreamingContent.writeTo(OutputStream) on a fake output stream that only counts bytes written.
        Parameters:
        content - streaming content
        Throws:
        java.io.IOException
      • serialize

        public static byte[] serialize​(java.lang.Object value)
                                throws java.io.IOException
        Serializes the given object value to a newly allocated byte array.
        Parameters:
        value - object value to serialize
        Throws:
        java.io.IOException
        Since:
        1.16
      • serialize

        public static void serialize​(java.lang.Object value,
                                     java.io.OutputStream outputStream)
                              throws java.io.IOException
        Serializes the given object value to an output stream, and close the output stream.
        Parameters:
        value - object value to serialize
        outputStream - output stream to serialize into
        Throws:
        java.io.IOException
        Since:
        1.16
      • deserialize

        public static <S extends java.io.Serializable> S deserialize​(byte[] bytes)
                                                              throws java.io.IOException
        Deserializes the given byte array into to a newly allocated object.
        Parameters:
        bytes - byte array to deserialize or null for null result
        Returns:
        new allocated object or null for null input
        Throws:
        java.io.IOException
        Since:
        1.16
      • deserialize

        public static <S extends java.io.Serializable> S deserialize​(java.io.InputStream inputStream)
                                                              throws java.io.IOException
        Deserializes the given input stream into to a newly allocated object, and close the input stream.
        Parameters:
        inputStream - input stream to deserialize
        Throws:
        java.io.IOException
        Since:
        1.16
      • isSymbolicLink

        @Deprecated
        public static boolean isSymbolicLink​(java.io.File file)
                                      throws java.io.IOException
        Deprecated.
        use java.nio.file.Path#isSymbolicLink
        Returns whether the given file is a symbolic link.
        Throws:
        java.io.IOException
        Since:
        1.16