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 Sink} which forwards calls to another. Useful for subclassing. */
21public abstract class ForwardingSink implements Sink {
22  private final Sink delegate;
23
24  public ForwardingSink(Sink delegate) {
25    if (delegate == null) throw new IllegalArgumentException("delegate == null");
26    this.delegate = delegate;
27  }
28
29  /** {@link Sink} to which this instance is delegating. */
30  public final Sink delegate() {
31    return delegate;
32  }
33
34  @Override public void write(Buffer source, long byteCount) throws IOException {
35    delegate.write(source, byteCount);
36  }
37
38  @Override public void flush() throws IOException {
39    delegate.flush();
40  }
41
42  @Override public Timeout timeout() {
43    return delegate.timeout();
44  }
45
46  @Override public void close() throws IOException {
47    delegate.close();
48  }
49
50  @Override public String toString() {
51    return getClass().getSimpleName() + "(" + delegate.toString() + ")";
52  }
53}
54