All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.vertx.groovy.core.streams.ReadStream.groovy Maven / Gradle / Ivy

There is a newer version: 5.0.0.CR3
Show newest version
/*
 * Copyright 2014 Red Hat, Inc.
 *
 * Red Hat licenses this file to you under the Apache License, version 2.0
 * (the "License"); you may not use this file except in compliance with the
 * License.  You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package io.vertx.groovy.core.streams;
import groovy.transform.CompileStatic
import io.vertx.lang.groovy.InternalHelper
import io.vertx.core.json.JsonObject
import io.vertx.core.Handler
/**
 * Represents a stream of items that can be read from.
 * 

* Any class that implements this interface can be used by a {@link io.vertx.groovy.core.streams.Pump} to pump data from it * to a {@link io.vertx.groovy.core.streams.WriteStream}. */ @CompileStatic public interface ReadStream extends StreamBase { public Object getDelegate(); ReadStream exceptionHandler(Handler handler); ReadStream handler(Handler handler); ReadStream pause(); ReadStream resume(); ReadStream endHandler(Handler endHandler); } @CompileStatic class ReadStreamImpl implements ReadStream { private final def io.vertx.core.streams.ReadStream delegate; public ReadStreamImpl(Object delegate) { this.delegate = (io.vertx.core.streams.ReadStream) delegate; } public Object getDelegate() { return delegate; } /** * Set an exception handler on the read stream. * @param handler the exception handler * @return a reference to this, so the API can be used fluently */ public ReadStream exceptionHandler(Handler handler) { ( /* Work around for https://jira.codehaus.org/browse/GROOVY-6970 */ (io.vertx.core.streams.StreamBase) this.delegate).exceptionHandler(handler); return this; } /** * Set a data handler. As data is read, the handler will be called with the data. * @param handler * @return a reference to this, so the API can be used fluently */ public ReadStream handler(Handler handler) { ((io.vertx.core.streams.ReadStream) this.delegate).handler(new Handler() { public void handle(Object event) { handler.handle(InternalHelper.wrapObject(event)) } }); return this; } /** * Pause the ReadSupport. While it's paused, no data will be sent to the dataHandler * @return a reference to this, so the API can be used fluently */ public ReadStream pause() { ((io.vertx.core.streams.ReadStream) this.delegate).pause(); return this; } /** * Resume reading. If the ReadSupport has been paused, reading will recommence on it. * @return a reference to this, so the API can be used fluently */ public ReadStream resume() { ((io.vertx.core.streams.ReadStream) this.delegate).resume(); return this; } /** * Set an end handler. Once the stream has ended, and there is no more data to be read, this handler will be called. * @param endHandler * @return a reference to this, so the API can be used fluently */ public ReadStream endHandler(Handler endHandler) { ((io.vertx.core.streams.ReadStream) this.delegate).endHandler(endHandler); return this; } }