Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2014 Red Hat, Inc., and individual contributors
   * as indicated by the @author tags.
   *
   * Licensed 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.undertow.channels;
 
 
A stream source channel that can be marked as detached. Once this is marked as detached then calls will no longer be forwarded to the delegate.

Author(s):
Stuart Douglas
 
 public abstract class DetachableStreamSourceChannel implements StreamSourceChannel{
 
     protected final StreamSourceChannel delegate;
 
 
     public DetachableStreamSourceChannel(final StreamSourceChannel delegate) {
         this. = delegate;
     }
 
     protected abstract boolean isFinished();
 
     @Override
     public void resumeReads() {
         if (isFinished()) {
             return;
         }
         .resumeReads();
     }
 
     public long transferTo(final long positionfinal long countfinal FileChannel targetthrows IOException {
         if (isFinished()) {
             return -1;
         }
         return .transferTo(positioncounttarget);
     }
 
     public void awaitReadable() throws IOException {
         if (isFinished()) {
             return;
         }
         .awaitReadable();
     }
 
     public void suspendReads() {
         if (isFinished()) {
             return;
         }
         .suspendReads();
     }
 
     public long transferTo(final long countfinal ByteBuffer throughBufferfinal StreamSinkChannel targetthrows IOException {
         if (isFinished()) {
             return -1;
         }
         return .transferTo(countthroughBuffertarget);
     }
 
     public XnioWorker getWorker() {
         return .getWorker();
     }
 
     public boolean isReadResumed() {
         if (isFinished()) {
             return false;
         }
        return .isReadResumed();
    }
    public <T> T setOption(final Option<T> optionfinal T valuethrows IllegalArgumentExceptionIOException {
        if (isFinished()) {
            throw ..channelIsClosed();
        }
        return .setOption(optionvalue);
    }
    public boolean supportsOption(final Option<?> option) {
        return .supportsOption(option);
    }
    public void shutdownReads() throws IOException {
        if (isFinished()) {
            return;
        }
        .shutdownReads();
    }
    public ChannelListener.Setter<? extends StreamSourceChannelgetReadSetter() {
        if ( == null) {
             = new ChannelListener.SimpleSetter<>();
            if (!isFinished()) {
                if( instanceof ConduitStreamSourceChannel) {
                    ((ConduitStreamSourceChannel)).setReadListener(ChannelListeners.delegatingChannelListener(this));
                } else {
                    .getReadSetter().set(ChannelListeners.delegatingChannelListener(this));
                }
            }
        }
        return ;
    }
    public boolean isOpen() {
        if (isFinished()) {
            return false;
        }
        return .isOpen();
    }
    public long read(final ByteBuffer[] dststhrows IOException {
        if (isFinished()) {
            return -1;
        }
        return .read(dsts);
    }
    public long read(final ByteBuffer[] dstsfinal int offsetfinal int lengththrows IOException {
        if (isFinished()) {
            return -1;
        }
        return .read(dstsoffsetlength);
    }
    public void wakeupReads() {
        if (isFinished()) {
            return;
        }
        .wakeupReads();
    }
    public XnioExecutor getReadThread() {
        return .getReadThread();
    }
    public void awaitReadable(final long timefinal TimeUnit timeUnitthrows IOException {
        if (isFinished()) {
            throw ..channelIsClosed();
        }
        .awaitReadable(timetimeUnit);
    }
    public ChannelListener.Setter<? extends StreamSourceChannelgetCloseSetter() {
        if ( == null) {
             = new ChannelListener.SimpleSetter<>();
            if (!isFinished()) {
                if( instanceof ConduitStreamSourceChannel) {
                    ((ConduitStreamSourceChannel)).setCloseListener(ChannelListeners.delegatingChannelListener(this));
                } else {
                    .getCloseSetter().set(ChannelListeners.delegatingChannelListener(this));
                }
            }
        }
        return ;
    }
    public void close() throws IOException {
        if (isFinished()) {
            return;
        }
        .close();
    }
    public <T> T getOption(final Option<T> optionthrows IOException {
        if (isFinished()) {
            throw ..streamIsClosed();
        }
        return .getOption(option);
    }
    public int read(final ByteBuffer dstthrows IOException {
        if (isFinished()) {
            return -1;
        }
        return .read(dst);
    }
    @Override
    public XnioIoThread getIoThread() {
        return .getIoThread();
    }
New to GrepCode? Check out our FAQ X