Package okio

Class Okio


  • public final class Okio
    extends java.lang.Object
    Essential APIs for working with Okio.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static Sink appendingSink​(java.io.File file)
      Returns a sink that appends to file.
      static Sink blackhole()
      Returns a sink that writes nowhere.
      static BufferedSink buffer​(Sink sink)
      Returns a new sink that buffers writes to sink.
      static BufferedSource buffer​(Source source)
      Returns a new source that buffers reads from source.
      static Sink sink​(java.io.File file)
      Returns a sink that writes to file.
      static Sink sink​(java.io.OutputStream out)
      Returns a sink that writes to out.
      static Sink sink​(java.net.Socket socket)
      Returns a sink that writes to socket.
      static Sink sink​(java.nio.file.Path path, java.nio.file.OpenOption... options)
      Returns a sink that writes to path.
      static Source source​(java.io.File file)
      Returns a source that reads from file.
      static Source source​(java.io.InputStream in)
      Returns a source that reads from in.
      static Source source​(java.net.Socket socket)
      Returns a source that reads from socket.
      static Source source​(java.nio.file.Path path, java.nio.file.OpenOption... options)
      Returns a source that reads from path.
      • Methods inherited from class java.lang.Object

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

      • buffer

        public static BufferedSource buffer​(Source source)
        Returns a new source that buffers reads from source. The returned source will perform bulk reads into its in-memory buffer. Use this wherever you read a source to get an ergonomic and efficient access to data.
      • buffer

        public static BufferedSink buffer​(Sink sink)
        Returns a new sink that buffers writes to sink. The returned sink will batch writes to sink. Use this wherever you write to a sink to get an ergonomic and efficient access to data.
      • sink

        public static Sink sink​(java.io.OutputStream out)
        Returns a sink that writes to out.
      • sink

        public static Sink sink​(java.net.Socket socket)
                         throws java.io.IOException
        Returns a sink that writes to socket. Prefer this over sink(OutputStream) because this method honors timeouts. When the socket write times out, the socket is asynchronously closed by a watchdog thread.
        Throws:
        java.io.IOException
      • source

        public static Source source​(java.io.InputStream in)
        Returns a source that reads from in.
      • source

        public static Source source​(java.io.File file)
                             throws java.io.FileNotFoundException
        Returns a source that reads from file.
        Throws:
        java.io.FileNotFoundException
      • source

        @IgnoreJRERequirement
        public static Source source​(java.nio.file.Path path,
                                    java.nio.file.OpenOption... options)
                             throws java.io.IOException
        Returns a source that reads from path.
        Throws:
        java.io.IOException
      • sink

        public static Sink sink​(java.io.File file)
                         throws java.io.FileNotFoundException
        Returns a sink that writes to file.
        Throws:
        java.io.FileNotFoundException
      • appendingSink

        public static Sink appendingSink​(java.io.File file)
                                  throws java.io.FileNotFoundException
        Returns a sink that appends to file.
        Throws:
        java.io.FileNotFoundException
      • sink

        @IgnoreJRERequirement
        public static Sink sink​(java.nio.file.Path path,
                                java.nio.file.OpenOption... options)
                         throws java.io.IOException
        Returns a sink that writes to path.
        Throws:
        java.io.IOException
      • blackhole

        public static Sink blackhole()
        Returns a sink that writes nowhere.
      • source

        public static Source source​(java.net.Socket socket)
                             throws java.io.IOException
        Returns a source that reads from socket. Prefer this over source(InputStream) because this method honors timeouts. When the socket read times out, the socket is asynchronously closed by a watchdog thread.
        Throws:
        java.io.IOException