Class IOUtils

java.lang.Object
com.google.api.client.util.IOUtils

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

    • IOUtils

      public IOUtils()
  • Method Details

    • copy

      public static void copy(InputStream inputStream, OutputStream outputStream) throws IOException
      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:
      IOException
    • copy

      public static void copy(InputStream inputStream, OutputStream outputStream, boolean closeInputStream) throws IOException
      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:
      IOException
    • computeLength

      public static long computeLength(StreamingContent content) throws 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:
      IOException
    • serialize

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

      public static void serialize(Object value, OutputStream outputStream) throws 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:
      IOException
      Since:
      1.16
    • deserialize

      public static <S extends Serializable> S deserialize(byte[] bytes) throws 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:
      IOException
      Since:
      1.16
    • deserialize

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

      public static boolean isSymbolicLink(File file) throws IOException
      Returns whether the given file is a symbolic link.
      Throws:
      IOException
      Since:
      1.16