src/share/classes/java/io/Reader.java

Print this page




  74      * @param lock  The Object to synchronize on.
  75      */
  76     protected Reader(Object lock) {
  77         if (lock == null) {
  78             throw new NullPointerException();
  79         }
  80         this.lock = lock;
  81     }
  82 
  83     /**
  84      * Attempts to read characters into the specified character buffer.
  85      * The buffer is used as a repository of characters as-is: the only
  86      * changes made are the results of a put operation. No flipping or
  87      * rewinding of the buffer is performed.
  88      *
  89      * @param target the buffer to read characters into
  90      * @return The number of characters added to the buffer, or
  91      *         -1 if this source of characters is at its end
  92      * @throws IOException if an I/O error occurs
  93      * @throws NullPointerException if target is null
  94      * @throws ReadOnlyBufferException if target is a read only buffer
  95      * @since 1.5
  96      */
  97     public int read(java.nio.CharBuffer target) throws IOException {
  98         int len = target.remaining();
  99         char[] cbuf = new char[len];
 100         int n = read(cbuf, 0, len);
 101         if (n > 0)
 102             target.put(cbuf, 0, n);
 103         return n;
 104     }
 105 
 106     /**
 107      * Reads a single character.  This method will block until a character is
 108      * available, an I/O error occurs, or the end of the stream is reached.
 109      *
 110      * <p> Subclasses that intend to support efficient single-character input
 111      * should override this method.
 112      *
 113      * @return     The character read, as an integer in the range 0 to 65535
 114      *             (<tt>0x00-0xffff</tt>), or -1 if the end of the stream has




  74      * @param lock  The Object to synchronize on.
  75      */
  76     protected Reader(Object lock) {
  77         if (lock == null) {
  78             throw new NullPointerException();
  79         }
  80         this.lock = lock;
  81     }
  82 
  83     /**
  84      * Attempts to read characters into the specified character buffer.
  85      * The buffer is used as a repository of characters as-is: the only
  86      * changes made are the results of a put operation. No flipping or
  87      * rewinding of the buffer is performed.
  88      *
  89      * @param target the buffer to read characters into
  90      * @return The number of characters added to the buffer, or
  91      *         -1 if this source of characters is at its end
  92      * @throws IOException if an I/O error occurs
  93      * @throws NullPointerException if target is null
  94      * @throws java.nio.ReadOnlyBufferException if target is a read only buffer
  95      * @since 1.5
  96      */
  97     public int read(java.nio.CharBuffer target) throws IOException {
  98         int len = target.remaining();
  99         char[] cbuf = new char[len];
 100         int n = read(cbuf, 0, len);
 101         if (n > 0)
 102             target.put(cbuf, 0, n);
 103         return n;
 104     }
 105 
 106     /**
 107      * Reads a single character.  This method will block until a character is
 108      * available, an I/O error occurs, or the end of the stream is reached.
 109      *
 110      * <p> Subclasses that intend to support efficient single-character input
 111      * should override this method.
 112      *
 113      * @return     The character read, as an integer in the range 0 to 65535
 114      *             (<tt>0x00-0xffff</tt>), or -1 if the end of the stream has