Skip to content

Commit b95cdfe

Browse files
author
Simon Abykov
committed
Use IOHelper for stream reading
1 parent 98afad4 commit b95cdfe

1 file changed

Lines changed: 6 additions & 20 deletions

File tree

src/main/java/com/microsoft/a4o/credentialstorage/storage/macosx/KeychainSecurityCliStore.java

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
import java.io.BufferedReader;
1414
import java.io.IOException;
15-
import java.io.InputStream;
16-
import java.io.InputStreamReader;
1715
import java.io.PrintWriter;
1816
import java.io.StringReader;
1917
import java.util.HashMap;
@@ -275,8 +273,8 @@ public boolean isKeychainAvailable() {
275273
);
276274
final Process process = processBuilder.start();
277275
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());
280278
checkResult(result, stdOut, stdErr);
281279
} catch (final IOException | InterruptedException e) {
282280
throw new Error(e);
@@ -312,8 +310,8 @@ private static Map<String, Object> read(final SecretKind secretKind, final Strin
312310
final Process process = processBuilder.start();
313311

314312
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());
317315
if (result != 0 && result != ITEM_NOT_FOUND_EXIT_CODE) {
318316
checkResult(result, stdOut, stdErr);
319317
}
@@ -407,8 +405,8 @@ private static void write(final SecretKind secretKind, final String serviceName,
407405
writer.println(command);
408406

409407
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());
412410
checkResult(result, stdOut, stdErr);
413411
} catch (final IOException | InterruptedException e) {
414412
throw new Error(e);
@@ -439,16 +437,4 @@ public void writeTokenPair(final String targetName, final TokenPair tokenPair) {
439437
writeTokenKind(targetName, SecretKind.TokenPair_Refresh_Token, tokenPair.RefreshToken);
440438
}
441439
}
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-
}
454440
}

0 commit comments

Comments
 (0)