001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.io;
019
020import java.io.FilterInputStream;
021import java.io.InputStream;
022import org.apache.yetus.audience.InterfaceAudience;
023
024/**
025 * An input stream that delegates all operations to another input stream. The delegate can be
026 * switched out for another at any time but to minimize the possibility of violating the InputStream
027 * contract it would be best to replace the delegate only once it has been fully consumed.
028 * <p>
029 * For example, a ByteArrayInputStream, which is implicitly bounded by the size of the underlying
030 * byte array can be converted into an unbounded stream fed by multiple instances of
031 * ByteArrayInputStream, switched out one for the other in sequence.
032 * <p>
033 * Although multithreaded access is allowed, users of this class will want to take care to order
034 * operations on this stream and the swap out of one delegate for another in a way that provides a
035 * valid view of stream contents.
036 */
037@InterfaceAudience.Private
038public class DelegatingInputStream extends FilterInputStream {
039
040  public DelegatingInputStream(InputStream in) {
041    super(in);
042  }
043
044  public InputStream getDelegate() {
045    return this.in;
046  }
047
048  public void setDelegate(InputStream in) {
049    this.in = in;
050  }
051
052}