类 BinaryStdIn


  • public final class BinaryStdIn
    extends java.lang.Object
    Binary standard input. This class provides methods for reading in bits from standard input, either one bit at a time (as a boolean), 8 bits at a time (as a byte or char), 16 bits at a time (as a short), 32 bits at a time (as an int or float), or 64 bits at a time (as a double or long).

    All primitive types are assumed to be represented using their standard Java representations, in big-endian (most significant byte first) order.

    The client should not intermix calls to BinaryStdIn with calls to StdIn or System.in; otherwise unexpected behavior will result.

    • 方法概要

      修饰符和类型 方法 说明
      static void close()
      Close this input stream and release any associated system resources.
      static boolean isEmpty()
      Returns true if standard input is empty.
      static void main​(java.lang.String[] args)
      Test client.
      static boolean readBoolean()
      Reads the next bit of data from standard input and return as a boolean.
      static byte readByte()
      Reads the next 8 bits from standard input and return as an 8-bit byte.
      static char readChar()
      Reads the next 8 bits from standard input and return as an 8-bit char.
      static char readChar​(int r)
      Reads the next r bits from standard input and return as an r-bit character.
      static double readDouble()
      Reads the next 64 bits from standard input and return as a 64-bit double.
      static float readFloat()
      Reads the next 32 bits from standard input and return as a 32-bit float.
      static int readInt()
      Reads the next 32 bits from standard input and return as a 32-bit int.
      static int readInt​(int r)
      Reads the next r bits from standard input and return as an r-bit int.
      static long readLong()
      Reads the next 64 bits from standard input and return as a 64-bit long.
      static short readShort()
      Reads the next 16 bits from standard input and return as a 16-bit short.
      static java.lang.String readString()
      Reads the remaining bytes of data from standard input and return as a string.
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 方法详细资料

      • close

        public static void close()
        Close this input stream and release any associated system resources.
      • isEmpty

        public static boolean isEmpty()
        Returns true if standard input is empty.
        返回:
        true if and only if standard input is empty
      • readBoolean

        public static boolean readBoolean()
        Reads the next bit of data from standard input and return as a boolean.
        返回:
        the next bit of data from standard input as a boolean
        抛出:
        java.util.NoSuchElementException - if standard input is empty
      • readChar

        public static char readChar()
        Reads the next 8 bits from standard input and return as an 8-bit char. Note that char is a 16-bit type; to read the next 16 bits as a char, use readChar(16).
        返回:
        the next 8 bits of data from standard input as a char
        抛出:
        java.util.NoSuchElementException - if there are fewer than 8 bits available on standard input
      • readChar

        public static char readChar​(int r)
        Reads the next r bits from standard input and return as an r-bit character.
        参数:
        r - number of bits to read.
        返回:
        the next r bits of data from standard input as a char
        抛出:
        java.util.NoSuchElementException - if there are fewer than r bits available on standard input
        java.lang.IllegalArgumentException - unless 1 <= r <= 16
      • readString

        public static java.lang.String readString()
        Reads the remaining bytes of data from standard input and return as a string.
        返回:
        the remaining bytes of data from standard input as a String
        抛出:
        java.util.NoSuchElementException - if standard input is empty or if the number of bits available on standard input is not a multiple of 8 (byte-aligned)
      • readShort

        public static short readShort()
        Reads the next 16 bits from standard input and return as a 16-bit short.
        返回:
        the next 16 bits of data from standard input as a short
        抛出:
        java.util.NoSuchElementException - if there are fewer than 16 bits available on standard input
      • readInt

        public static int readInt()
        Reads the next 32 bits from standard input and return as a 32-bit int.
        返回:
        the next 32 bits of data from standard input as a int
        抛出:
        java.util.NoSuchElementException - if there are fewer than 32 bits available on standard input
      • readInt

        public static int readInt​(int r)
        Reads the next r bits from standard input and return as an r-bit int.
        参数:
        r - number of bits to read.
        返回:
        the next r bits of data from standard input as a int
        抛出:
        java.util.NoSuchElementException - if there are fewer than r bits available on standard input
        java.lang.IllegalArgumentException - unless 1 <= r <= 32
      • readLong

        public static long readLong()
        Reads the next 64 bits from standard input and return as a 64-bit long.
        返回:
        the next 64 bits of data from standard input as a long
        抛出:
        java.util.NoSuchElementException - if there are fewer than 64 bits available on standard input
      • readDouble

        public static double readDouble()
        Reads the next 64 bits from standard input and return as a 64-bit double.
        返回:
        the next 64 bits of data from standard input as a double
        抛出:
        java.util.NoSuchElementException - if there are fewer than 64 bits available on standard input
      • readFloat

        public static float readFloat()
        Reads the next 32 bits from standard input and return as a 32-bit float.
        返回:
        the next 32 bits of data from standard input as a float
        抛出:
        java.util.NoSuchElementException - if there are fewer than 32 bits available on standard input
      • readByte

        public static byte readByte()
        Reads the next 8 bits from standard input and return as an 8-bit byte.
        返回:
        the next 8 bits of data from standard input as a byte
        抛出:
        java.util.NoSuchElementException - if there are fewer than 8 bits available on standard input
      • main

        public static void main​(java.lang.String[] args)
        Test client. Reads in a binary input file from standard input and writes it to standard output.
        参数:
        args - the command-line arguments