Stream the specified readable.

@param readable readable to stream, must not be null
@param listener event based reader callback, must not be null
@throws IOException if an I/O error occurs
331662
public static void stream(final Readable readable, final VcfStreamListener listener) throws IOException {
        StreamingVcfParser.stream(readable, listener);
    }
1278142
static void parse(final Readable readable, final ParseListener listener)
		throws IOException
	{
		if (readable == null)
		{
			throw new IllegalArgumentException("readable must not be null");
		}
		FastqParserLineProcessor lineProcessor = new FastqParserLineProcessor(listener);
		CharStreams.readLines(readable, lineProcessor);
		if (lineProcessor.getState() == State.COMPLETE)
		{
			listener.complete();
			lineProcessor.setState(State.DESCRIPTION);
		}
		if (lineProcessor.getState() != State.DESCRIPTION)
		{
			throw new IOException("truncated sequence"); // at line " + lineNumber);
		}
	}
1157356
private void writeObject(final ObjectOutputStream objectOutputStream) throws IOException {
        final ArrayList<L> serializableListeners = new ArrayList<>();

        // don't just rely on instanceof Serializable:
        ObjectOutputStream testObjectOutputStream = new ObjectOutputStream(new ByteArrayOutputStream());
        for (final L listener : listeners) {
            try {
                testObjectOutputStream.writeObject(listener);
                serializableListeners.add(listener);
            } catch (final IOException exception) {
                //recreate test stream in case of indeterminate state
                testObjectOutputStream = new ObjectOutputStream(new ByteArrayOutputStream());
            }
        }
        /*
         * we can reconstitute everything we need from an array of our listeners,
         * which has the additional advantage of typically requiring less storage than a list:
         */
        objectOutputStream.writeObject(serializableListeners.toArray(prototypeArray));
    }
78553
@Override
    public void close() throws IOException {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
            Tr.debug(tc, "The input stream has been closed : " + this + " read Listener running ->" + listener);
        
        isClosed = true;
        listener = null;
        
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
            Tr.debug(tc, "The input stream has been closed : " + this + " read Listener ->" + listener);
        
        super.close();
    }
1074480
@Override
    public void setReadListener(ReadListener arg0) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.entry(tc, "setReadListener", this.listener);

        //Throw a NullPointerException if the ReadListener passed in was null
        if(arg0 == null){
            if (TraceComponent.isAnyTracingEnabled() && tc.isErrorEnabled())
                Tr.error(tc, "readlistener.is.null");
            throw new NullPointerException(Tr.formatMessage(tc, "readlistener.is.null"));
        }
        //Throw an IllegalStateException if async has not been started
        if(!this.request.isAsyncStarted()){
            if (TraceComponent.isAnyTracingEnabled() && tc.isErrorEnabled())
                Tr.error(tc, "readlistener.async.not.started");
            throw new IllegalStateException(Tr.formatMessage(tc, "readlistener.async.not.started"));
        }
        //Throw an IllegalStateException is there was already a ReadListener set for this InputStream
        if(this.listener != null){
            if (TraceComponent.isAnyTracingEnabled() && tc.isErrorEnabled())
                Tr.error(tc, "readlistener.already.started");
            throw new IllegalStateException(Tr.formatMessage(tc, "readlistener.already.started"));
        }
        
        this.listener = arg0;
        
        //Create a new ThreadContextManager to pass into the read Callback
        ThreadContextManager tcm = new ThreadContextManager();
        
        // If ISC is null the inbound request would have resulted in a login being needed so
        // post data has already been read and re-populated by the security component.In 
        // this case create a callback which works for the already read data.
        if (getISC()==null) {
            this.callback = new AsyncAlreadyReadCallback(this, tcm);
        } else {
            //Create a new HttpServletCallback so we can use it for our async read callbacks
            this.callback = new AsyncReadCallback(this, tcm);
        }    
        
        AsyncContext31Impl ac = (AsyncContext31Impl)request.getAsyncContext();

        try {
            ac.startReadListener(tcm, this);
        } catch (Exception e) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "An exception occurred while setting the ReadListener : " + e);
            }
            //There was a problem with the read so we should invoke their onError, since technically it's been set now
            this.listener.onError(e);
        }
        
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.exit(tc, "setReadListener", this.listener);
    }
1179606
private void readFromStream(InputStream in) throws IOException {
        document = DocumentFactory.newDocument(Json.read(in));
    }
799465
@Override
    final public void addConnectionEventListener(
                                                 final ConnectionEventListener listener) {

        if (TraceComponent.isAnyTracingEnabled() && TRACE.isEntryEnabled()) {
            SibTr.entry(this, TRACE, "addConnectionEventListener", listener);
        }

        synchronized (_connectionListeners) {
            _connectionListeners.add(listener);
        }

        if (TraceComponent.isAnyTracingEnabled() && TRACE.isEntryEnabled()) {
            SibTr.exit(this, TRACE, "addConnectionEventListener");
        }

    }
1314185
@Override
    public int read() throws IOException {
        if (metrics != null) {
            metrics.startEvent(Field.HttpSocketReadTime);
        }
        try {
            return in.read();
        } finally {
            if (metrics != null) {
                metrics.endEvent(Field.HttpSocketReadTime);
            }
        }
    }
640573
public ReadStreamOld openRead()
    throws IOException
  {
    closeWrite();
    
    TempReadStream read = new TempReadStream(_head);
    read.setFreeWhenDone(true);
    _head = null;
    _tail = null;
    
    return new ReadStreamOld(read);
  }
1011689
def _readable(self, watcher, events):
        
        protocol = self.factory.build(self.loop)
        try:
            sock, address = self.sock.accept()
            connection = Connection(self.loop, sock, address, protocol, self)
            self.connections.add(connection)
            connection.make_connection()
            logger.debug("added connection")
        except IOError as e:
            self.shutdown(e)
297444
static Reader asReader(final Readable readable) {
    checkNotNull(readable);
    if (readable instanceof Reader) {
      return (Reader) readable;
    }
    return new Reader() {
      @Override
      public int read(char[] cbuf, int off, int len) throws IOException {
        return read(CharBuffer.wrap(cbuf, off, len));
      }

      @Override
      public int read(CharBuffer target) throws IOException {
        return readable.read(target);
      }

      @Override
      public void close() throws IOException {
        if (readable instanceof Closeable) {
          ((Closeable) readable).close();
        }
      }
    };
  }
590156
public void write(InputStream stream) throws IOException {
        onNewLine = false;
        try (ReadableByteChannel readable = Channels.newChannel(stream)) {
            flush();
            while (readable.read(buffer) != -1) {
                flush();
            }
        }
    }
272603
public static void runReadLoop(InputStream stream, StreamConnection connection) throws Exception {
        ByteBuffer dbuf = ByteBuffer.allocateDirect(Math.min(Math.max(connection.getMaxMessageSize(), BUFFER_SIZE_LOWER_BOUND), BUFFER_SIZE_UPPER_BOUND));
        byte[] readBuff = new byte[dbuf.capacity()];
        while (true) {
            // TODO Kill the message duplication here
            checkState(dbuf.remaining() > 0 && dbuf.remaining() <= readBuff.length);
            int read = stream.read(readBuff, 0, Math.max(1, Math.min(dbuf.remaining(), stream.available())));
            if (read == -1)
                return;
            dbuf.put(readBuff, 0, read);
            // "flip" the buffer - setting the limit to the current position and setting position to 0
            dbuf.flip();
            // Use connection.receiveBytes's return value as a double-check that it stopped reading at the right
            // location
            int bytesConsumed = connection.receiveBytes(dbuf);
            checkState(dbuf.position() == bytesConsumed);
            // Now drop the bytes which were read by compacting dbuf (resetting limit and keeping relative
            // position)
            dbuf.compact();
        }
    }
406343
public static String readFully(Reader reader) throws IOException {
        try {
            StringWriter writer = new StringWriter();
            char[] buffer = new char[1024];
            int count;
            while ((count = reader.read(buffer)) != -1) {
                writer.write(buffer, 0, count);
            }
            return writer.toString();
        } finally {
            reader.close();
        }
    }
145688
static void stream(final Readable readable, final FastqVariant variant, final StreamListener listener)
		throws IOException
	{
		if (readable == null)
		{
			throw new IllegalArgumentException("readable must not be null");
		}
		if (variant == null)
		{
			throw new IllegalArgumentException("variant must not be null");
		}
		if (listener == null)
		{
			throw new IllegalArgumentException("listener must not be null");
		}

		final FastqBuilder builder = new FastqBuilder().withVariant(variant);
		FastqParser.parse(readable, new ParseListener()
			{
				@Override
				public void description(final String description) throws IOException
				{
					builder.withDescription(description);
				}

				@Override
				public void sequence(final String sequence) throws IOException
				{
					builder.withSequence(sequence);
				}

				@Override
				public void appendSequence(final String sequence) throws IOException
				{
					builder.appendSequence(sequence);
				}

				@Override
				public void repeatDescription(final String repeatDescription) throws IOException
				{
					String description = builder.getDescription();
					if ((description != null) && (description.length() > 0) && (repeatDescription.length() > 0))
					{
						if (!description.equals(repeatDescription))
						{
							throw new IOException("repeat description must match description");
						}
					}
				}

				/**
				 * Validate the specified quality line.
				 *
				 * @param quality quality line to validate
				 * @throws IOException if an I/O error occurs
				 */
				private void validateQuality(final String quality) throws IOException
				{
					for (int i = 0, size = quality.length(); i < size; i++)
					{
						char c = quality.charAt(i);
						int qualityScore = variant.qualityScore(c);
						if (qualityScore < variant.minimumQualityScore() || qualityScore > variant.maximumQualityScore())
						{
							throw new IOException("quality score must be between " + variant.minimumQualityScore() +
												  " and " + variant.maximumQualityScore() + ", was " + qualityScore +
												  " for ASCII char '" + c + "'");
						}
					}
				}

				@Override
				public void quality(final String quality) throws IOException
				{
					validateQuality(quality);
					builder.withQuality(quality);
				}

				@Override
				public void appendQuality(final String quality) throws IOException
				{
					validateQuality(quality);
					builder.appendQuality(quality);
				}

				@Override
				public void complete() throws IOException
				{
					try
					{
						listener.fastq(builder.build());
					}
					catch (IllegalStateException e)
					{
						throw new IOException("caught an IllegalStateException", e);
					}
				}
			});
	}
718917
public static Reader reader(File file) {
        E.illegalArgumentIfNot(file.canRead(), "file not readable: " + file.getPath());
        try {
            return new FileReader(file);
        } catch (IOException e) {
            throw E.ioException(e);
        }
    }
868472
public function addWriteStream($stream, callable $listener)
    {
        $this->emit('addWriteStream', [$stream, $listener]);
        $this->loop->addWriteStream($stream, function ($stream) use ($listener) {
            $this->emit('writeStreamTick', [$stream, $listener]);
            $listener($stream, $this);
        });
    }