001/* 002 * Copyright 2014 Konik.io 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package io.konik.carriage.utils; 017import java.io.Closeable; 018import java.io.FilterInputStream; 019import java.io.IOException; 020import java.io.InputStream; 021 022 023/** 024 * The Class CallBackInputStream. 025 */ 026public class CallBackInputStream extends FilterInputStream { 027 028 029 private Closeable callback; 030 031 /** 032 * Instantiates a new call back input stream. 033 * 034 * @param in the in 035 * @param callback the callback 036 */ 037 public CallBackInputStream(InputStream in, Closeable callback) { 038 super(in); 039 this.callback = callback; 040 } 041 042 @Override 043 public void close() throws IOException { 044 in.close(); 045 callback.close(); 046 } 047 048 @Override 049 protected void finalize() throws Throwable { 050 close(); 051 super.finalize(); 052 } 053}