1 /*
2 * Copyright (C) 2014 Cristian Sulea ( http://cristian.sulea.net )
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 package jatoo.exec;
19
20 import java.io.IOException;
21 import java.io.InputStream;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25
26 /**
27 * A class that will exhaust a provided {@link InputStream}.
28 *
29 * @author <a href="http://cristian.sulea.net" rel="author">Cristian Sulea</a>
30 * @version 1.4, July 25, 2014
31 */
32 public class InputStreamExhauster implements Runnable {
33
34 private static final Log LOGGER = LogFactory.getLog(InputStreamExhauster.class);
35
36 private final InputStream processInputStream;
37
38 public InputStreamExhauster(final InputStream processInputStream) {
39 this.processInputStream = processInputStream;
40 }
41
42 public final void exhaust() {
43 try {
44 while (processInputStream.read() != -1) {}
45 } catch (IOException e) {
46 LOGGER.error("error exhausting the stream", e);
47 }
48 }
49
50 @Override
51 public final void run() {
52 exhaust();
53 }
54
55 }