1/* 2 * Copyright (C) 2014 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 */ 16package okio; 17 18import java.io.IOException; 19 20/** A {@link Source} which forwards calls to another. Useful for subclassing. */ 21public abstract class ForwardingSource implements Source { 22 private final Source delegate; 23 24 public ForwardingSource(Source delegate) { 25 if (delegate == null) throw new IllegalArgumentException("delegate == null"); 26 this.delegate = delegate; 27 } 28 29 /** {@link Source} to which this instance is delegating. */ 30 public final Source delegate() { 31 return delegate; 32 } 33 34 @Override public long read(Buffer sink, long byteCount) throws IOException { 35 return delegate.read(sink, byteCount); 36 } 37 38 @Override public Timeout timeout() { 39 return delegate.timeout(); 40 } 41 42 @Override public void close() throws IOException { 43 delegate.close(); 44 } 45 46 @Override public String toString() { 47 return getClass().getSimpleName() + "(" + delegate.toString() + ")"; 48 } 49} 50