Use Files.writeString() and Files.readString() where possible
See gh-31459
This commit is contained in:
committed by
Stephane Nicoll
parent
d9d1bdf0f6
commit
fb45fc4819
@@ -18,7 +18,6 @@ package org.springframework.boot.buildpack.platform.docker.ssl;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.cert.CertificateException;
|
||||
@@ -76,7 +75,7 @@ final class CertificateParser {
|
||||
|
||||
private static void readCertificates(Path path, CertificateFactory factory, Consumer<X509Certificate> consumer) {
|
||||
try {
|
||||
String text = readText(path);
|
||||
String text = Files.readString(path);
|
||||
Matcher matcher = PATTERN.matcher(text);
|
||||
while (matcher.find()) {
|
||||
String encodedText = matcher.group(1);
|
||||
@@ -92,11 +91,6 @@ final class CertificateParser {
|
||||
}
|
||||
}
|
||||
|
||||
private static String readText(Path path) throws IOException {
|
||||
byte[] bytes = Files.readAllBytes(path);
|
||||
return new String(bytes, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private static byte[] decodeBase64(String content) {
|
||||
byte[] bytes = content.replaceAll("\r", "").replaceAll("\n", "").getBytes();
|
||||
return Base64Utils.decode(bytes);
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.boot.buildpack.platform.docker.ssl;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.GeneralSecurityException;
|
||||
@@ -65,7 +64,7 @@ final class PrivateKeyParser {
|
||||
*/
|
||||
static PrivateKey parse(Path path) {
|
||||
try {
|
||||
String text = readText(path);
|
||||
String text = Files.readString(path);
|
||||
Matcher matcher = PKCS1_PATTERN.matcher(text);
|
||||
if (matcher.find()) {
|
||||
return parsePkcs1(decodeBase64(matcher.group(1)));
|
||||
@@ -132,11 +131,6 @@ final class PrivateKeyParser {
|
||||
}
|
||||
}
|
||||
|
||||
private static String readText(Path path) throws IOException {
|
||||
byte[] bytes = Files.readAllBytes(path);
|
||||
return new String(bytes, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private static byte[] decodeBase64(String content) {
|
||||
byte[] contentBytes = content.replaceAll("\r", "").replaceAll("\n", "").getBytes();
|
||||
return Base64Utils.decode(contentBytes);
|
||||
|
||||
Reference in New Issue
Block a user