|
12 | 12 |
|
13 | 13 | import java.io.BufferedReader; |
14 | 14 | import java.io.IOException; |
15 | | -import java.io.InputStream; |
16 | | -import java.io.InputStreamReader; |
17 | 15 | import java.io.PrintWriter; |
18 | 16 | import java.io.StringReader; |
19 | 17 | import java.util.HashMap; |
@@ -275,8 +273,8 @@ public boolean isKeychainAvailable() { |
275 | 273 | ); |
276 | 274 | final Process process = processBuilder.start(); |
277 | 275 | final int result = process.waitFor(); |
278 | | - stdOut = readStream(process.getInputStream()); |
279 | | - stdErr = readStream(process.getErrorStream()); |
| 276 | + stdOut = IOHelper.readToString(process.getInputStream()); |
| 277 | + stdErr = IOHelper.readToString(process.getErrorStream()); |
280 | 278 | checkResult(result, stdOut, stdErr); |
281 | 279 | } catch (final IOException | InterruptedException e) { |
282 | 280 | throw new Error(e); |
@@ -312,8 +310,8 @@ private static Map<String, Object> read(final SecretKind secretKind, final Strin |
312 | 310 | final Process process = processBuilder.start(); |
313 | 311 |
|
314 | 312 | final int result = process.waitFor(); |
315 | | - stdOut = readStream(process.getInputStream()); |
316 | | - stdErr = readStream(process.getErrorStream()); |
| 313 | + stdOut = IOHelper.readToString(process.getInputStream()); |
| 314 | + stdErr = IOHelper.readToString(process.getErrorStream()); |
317 | 315 | if (result != 0 && result != ITEM_NOT_FOUND_EXIT_CODE) { |
318 | 316 | checkResult(result, stdOut, stdErr); |
319 | 317 | } |
@@ -407,8 +405,8 @@ private static void write(final SecretKind secretKind, final String serviceName, |
407 | 405 | writer.println(command); |
408 | 406 |
|
409 | 407 | final int result = process.waitFor(); |
410 | | - stdOut = readStream(process.getInputStream()); |
411 | | - stdErr = readStream(process.getErrorStream()); |
| 408 | + stdOut = IOHelper.readToString(process.getInputStream()); |
| 409 | + stdErr = IOHelper.readToString(process.getErrorStream()); |
412 | 410 | checkResult(result, stdOut, stdErr); |
413 | 411 | } catch (final IOException | InterruptedException e) { |
414 | 412 | throw new Error(e); |
@@ -439,16 +437,4 @@ public void writeTokenPair(final String targetName, final TokenPair tokenPair) { |
439 | 437 | writeTokenKind(targetName, SecretKind.TokenPair_Refresh_Token, tokenPair.RefreshToken); |
440 | 438 | } |
441 | 439 | } |
442 | | - |
443 | | - private static String readStream(final InputStream inputStream) throws IOException { |
444 | | - final StringBuilder contents = new StringBuilder(); |
445 | | - try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream))) { |
446 | | - String line; |
447 | | - while ((line = bufferedReader.readLine()) != null) { |
448 | | - contents.append(line) |
449 | | - .append(System.lineSeparator()); |
450 | | - } |
451 | | - } |
452 | | - return contents.toString(); |
453 | | - } |
454 | 440 | } |
0 commit comments