Package libcore.io

Class Streams


  • public final class Streams
    extends Object
    • Method Detail

      • readSingleByte

        public static int readSingleByte​(InputStream in)
                                  throws IOException
        Implements InputStream.read(int) in terms of InputStream.read(byte[], int, int). InputStream assumes that you implement InputStream.read(int) and provides default implementations of the others, but often the opposite is more efficient.
        Throws:
        IOException
      • writeSingleByte

        public static void writeSingleByte​(OutputStream out,
                                           int b)
                                    throws IOException
        Implements OutputStream.write(int) in terms of OutputStream.write(byte[], int, int). OutputStream assumes that you implement OutputStream.write(int) and provides default implementations of the others, but often the opposite is more efficient.
        Throws:
        IOException
      • readFully

        public static void readFully​(InputStream in,
                                     byte[] dst)
                              throws IOException
        Fills 'dst' with bytes from 'in', throwing EOFException if insufficient bytes are available.
        Throws:
        IOException
      • readFully

        public static byte[] readFully​(InputStream in)
                                throws IOException
        Returns a byte[] containing the remainder of 'in', closing it when done.
        Throws:
        IOException
      • readFullyNoClose

        public static byte[] readFullyNoClose​(InputStream in)
                                       throws IOException
        Returns a byte[] containing the remainder of 'in'.
        Throws:
        IOException
      • readFully

        public static String readFully​(Reader reader)
                                throws IOException
        Returns the remainder of 'reader' as a string, closing it when done.
        Throws:
        IOException
      • skipByReading

        public static long skipByReading​(InputStream in,
                                         long byteCount)
                                  throws IOException
        Skip at most byteCount bytes from in by calling read repeatedly until either the stream is exhausted or we read fewer bytes than we ask for.

        This method reuses the skip buffer but is careful to never use it at the same time that another stream is using it. Otherwise streams that use the caller's buffer for consistency checks like CRC could be clobbered by other threads. A thread-local buffer is also insufficient because some streams may call other streams in their skip() method, also clobbering the buffer.

        Throws:
        IOException
      • readAsciiLine

        public static String readAsciiLine​(InputStream in)
                                    throws IOException
        Returns the ASCII characters up to but not including the next "\r\n", or "\n".
        Throws:
        EOFException - if the stream is exhausted before the next newline character.
        IOException