
io.vertx.groovy.core.streams.ReadStream.groovy Maven / Gradle / Ivy
/*
* 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