-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStreamGobbler.java
52 lines (48 loc) · 1.25 KB
/
StreamGobbler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package util;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
/**
* Class for "gobbling" an input stream. Used to clear a stream without regards to contents.
*
* This is a modification of the StreamGobbler class created by Michael C. Daconta.
*
* Code retrieved on Jan29, 2012 from http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=4.
* The author is Michael C. Daconta who posted the article on December 29, 2000.
*/
public class StreamGobbler extends Thread
{
InputStream is;
/**
* Builds a stream gobbler.
* @param is the input stream.
*/
public StreamGobbler(InputStream is)
{
this.is = is;
}
/**
* Begins the stream gobbler.
*/
public void run()
{
try {
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
//String line = "";
while ( (br.readLine()) != null) {
//System.out.println(line);
}
isr.close();
br.close();
} catch (IOException e) {
//e.printStackTrace();
}
try {
is.close();
} catch (IOException e) {
//e.printStackTrace();
}
}
}