FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
processing/app/src/processing/app/exec/StreamPump.java at master · processing/processing · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
processing
/
processing
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
1.5k
Star
6.5k
Code
Issues
0
Pull requests
0
Actions
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
processing
/
app
/
src
/
processing
/
app
/
exec
/
StreamPump.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
111 lines (96 loc) · 3.11 KB
Breadcrumbs
processing
/
app
/
src
/
processing
/
app
/
exec
/
StreamPump.java
Copy path
File metadata and controls
111 lines (96 loc) · 3.11 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package
processing
.
app
.
exec
;
import
java
.
io
.
BufferedReader
;
import
java
.
io
.
IOException
;
import
java
.
io
.
InputStream
;
import
java
.
io
.
InputStreamReader
;
import
java
.
io
.
OutputStream
;
import
java
.
io
.
PrintWriter
;
import
java
.
io
.
Writer
;
import
java
.
util
.
List
;
import
java
.
util
.
concurrent
.
CopyOnWriteArrayList
;
import
java
.
util
.
concurrent
.
ExecutorService
;
import
java
.
util
.
concurrent
.
Executors
;
import
java
.
util
.
concurrent
.
ThreadFactory
;
import
processing
.
app
.
Base
;
/**
* <p>A StreamPump reads lines of text from its given InputStream
* and informs its LineProcessors until the InputStream is exhausted.
* <b>It is useful only for pumping lines of text, and not for arbitrary
* binary cruft.</b> It's handy for reading the output of processes that
* emit textual data, for example.
*
* @author Jonathan Feinberg <jdf@pobox.com>
*
*/
public
class
StreamPump
implements
Runnable
{
private
static
final
ExecutorService
threads
=
Executors
.
newCachedThreadPool
(
new
ThreadFactory
() {
public
Thread
newThread
(
final
Runnable
r
) {
final
Thread
t
=
new
Thread
(
r
);
t
.
setDaemon
(
true
);
t
.
setName
(
"StreamPump "
+
t
.
getId
());
return
t
;
}
});
private
final
BufferedReader
reader
;
private
final
List
<
LineProcessor
>
outs
=
new
CopyOnWriteArrayList
<
LineProcessor
>();
private
final
String
name
;
public
StreamPump
(
final
InputStream
in
,
final
String
name
) {
this
.
reader
=
new
BufferedReader
(
new
InputStreamReader
(
in
));
this
.
name
=
name
;
}
public
StreamPump
addTarget
(
final
OutputStream
out
) {
outs
.
add
(
new
WriterLineProcessor
(
out
));
return
this
;
}
public
StreamPump
addTarget
(
final
Writer
out
) {
outs
.
add
(
new
WriterLineProcessor
(
out
));
return
this
;
}
public
StreamPump
addTarget
(
final
LineProcessor
out
) {
outs
.
add
(
out
);
return
this
;
}
public
void
start
() {
// System.out.println("starting new StreamPump");
// new Exception().printStackTrace(EditorConsole.systemOut);
threads
.
execute
(
this
);
}
public
void
run
() {
try
{
String
line
;
while
((
line
=
reader
.
readLine
()) !=
null
) {
for
(
final
LineProcessor
out
:
outs
) {
try
{
out
.
processLine
(
line
);
}
catch
(
final
Exception
e
) {
}
}
}
}
catch
(
final
IOException
e
) {
if
(
Base
.
DEBUG
) {
System
.
err
.
println
(
"StreamPump: "
+
name
);
e
.
printStackTrace
(
System
.
err
);
// removing for 0190, but need a better way to handle these
throw
new
RuntimeException
(
"Inside "
+
this
+
" for "
+
name
,
e
);
}
}
}
private
static
class
WriterLineProcessor
implements
LineProcessor
{
private
final
PrintWriter
writer
;
private
WriterLineProcessor
(
final
OutputStream
out
) {
this
.
writer
=
new
PrintWriter
(
out
,
true
);
}
private
WriterLineProcessor
(
final
Writer
writer
) {
this
.
writer
=
new
PrintWriter
(
writer
,
true
);
}
public
void
processLine
(
final
String
line
) {
writer
.
println
(
line
);
}
}
// public static final LineProcessor DEVNULL = new LineProcessor() {
// public void processLine(final String line) {
// // noop
// }
// };
}
Back
|
FazBrowse Home
|
New Git URL