Exemple #1
0
    @Override
    public int read() throws IOException {
      synchronized (stream) {
        // If it can be pulled direct from the buffer, don't go via the slow path
        if (stream.hasBufferedInputBytes()) {
          try {
            return stream.read();
          } catch (BadDescriptorException ex) {
            throw new IOException(ex.getMessage());
          }
        }
      }

      byte[] b = new byte[1];
      // java.io.InputStream#read must return an unsigned value;
      return read(b, 0, 1) == 1 ? b[0] & 0xff : -1;
    }