5
5
6
6
import java .io .IOException ;
7
7
import java .io .InputStream ;
8
- import java .nio .charset .StandardCharsets ;
8
+ import java .io .InputStreamReader ;
9
+ import java .io .Reader ;
9
10
import java .util .ArrayList ;
10
11
import java .util .Collection ;
11
12
import java .util .Map ;
12
13
import java .util .concurrent .ConcurrentHashMap ;
13
14
import java .util .concurrent .ConcurrentMap ;
14
15
import java .util .concurrent .TimeUnit ;
15
16
17
+ import com .google .common .base .Charsets ;
18
+ import com .google .common .io .CharStreams ;
19
+
16
20
import io .kubernetes .client .ApiException ;
17
21
import io .kubernetes .client .Exec ;
18
22
import io .kubernetes .client .models .V1ObjectMeta ;
@@ -127,25 +131,15 @@ public NextAction apply(Packet packet) {
127
131
Exec exec = new Exec (holder .getApiClient ());
128
132
Process proc = null ;
129
133
try {
130
-
131
- // TEST
132
- System .out .println ("***** pod: " + podName );
133
-
134
134
proc = exec .exec (namespace , podName ,
135
135
new String [] { "/weblogic-operator/scripts/readState.sh" },
136
136
KubernetesConstants .CONTAINER_NAME , stdin , tty );
137
137
138
+ InputStream in = proc .getInputStream ();
138
139
if (proc .waitFor (timeoutSeconds , TimeUnit .SECONDS )) {
139
140
String state = null ;
140
- InputStream in = proc .getInputStream ();
141
- int a = in .available ();
142
- if (a > 0 ) {
143
- byte [] data = new byte [a ];
144
- in .read (data );
145
- state = new String (data , StandardCharsets .UTF_8 );
146
-
147
- // TEST
148
- System .out .println ("***** state: " + state );
141
+ try (final Reader reader = new InputStreamReader (in , Charsets .UTF_8 )) {
142
+ state = CharStreams .toString (reader );
149
143
}
150
144
151
145
@ SuppressWarnings ("unchecked" )
@@ -161,10 +155,9 @@ public NextAction apply(Packet packet) {
161
155
LOGGER .warning (MessageKeys .EXCEPTION , e );
162
156
} finally {
163
157
helper .recycle (holder );
164
- }
165
-
166
- if (proc != null ) {
167
- proc .destroy ();
158
+ if (proc != null ) {
159
+ proc .destroy ();
160
+ }
168
161
}
169
162
170
163
fiber .resume (packet );
0 commit comments