Home | History | Annotate | Download | only in okio
      1 /*
      2  * Copyright (C) 2015 Square, Inc.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 package okio;
     17 
     18 import java.io.IOException;
     19 import java.util.concurrent.TimeUnit;
     20 
     21 /** A {@link Timeout} which forwards calls to another. Useful for subclassing. */
     22 public class ForwardingTimeout extends Timeout {
     23   private Timeout delegate;
     24 
     25   public ForwardingTimeout(Timeout delegate) {
     26     if (delegate == null) throw new IllegalArgumentException("delegate == null");
     27     this.delegate = delegate;
     28   }
     29 
     30   /** {@link Timeout} instance to which this instance is currently delegating. */
     31   public final Timeout delegate() {
     32     return delegate;
     33   }
     34 
     35   public final ForwardingTimeout setDelegate(Timeout delegate) {
     36     if (delegate == null) throw new IllegalArgumentException("delegate == null");
     37     this.delegate = delegate;
     38     return this;
     39   }
     40 
     41   @Override public Timeout timeout(long timeout, TimeUnit unit) {
     42     return delegate.timeout(timeout, unit);
     43   }
     44 
     45   @Override public long timeoutNanos() {
     46     return delegate.timeoutNanos();
     47   }
     48 
     49   @Override public boolean hasDeadline() {
     50     return delegate.hasDeadline();
     51   }
     52 
     53   @Override public long deadlineNanoTime() {
     54     return delegate.deadlineNanoTime();
     55   }
     56 
     57   @Override public Timeout deadlineNanoTime(long deadlineNanoTime) {
     58     return delegate.deadlineNanoTime(deadlineNanoTime);
     59   }
     60 
     61   @Override public Timeout clearTimeout() {
     62     return delegate.clearTimeout();
     63   }
     64 
     65   @Override public Timeout clearDeadline() {
     66     return delegate.clearDeadline();
     67   }
     68 
     69   @Override public void throwIfReached() throws IOException {
     70     delegate.throwIfReached();
     71   }
     72 }
     73