Skip to content

Commit

Permalink
Use Files.readString instead of Files.readAllBytes (#5428)
Browse files Browse the repository at this point in the history
The former avoids creating a copy of byte array,
so it's slightly more performant
  • Loading branch information
geoand authored Jan 3, 2025
1 parent 4a2c330 commit 3eb4248
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private static Pattern resolvOption(String regex) {
File f = new File("/etc/resolv.conf");
try {
if (f.exists() && f.isFile()) {
String conf = new String(Files.readAllBytes(f.toPath()));
String conf = Files.readString(f.toPath());
int ndotsOption = parseNdotsOptionFromResolvConf(conf);
if (ndotsOption != -1) {
ndots = ndotsOption;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public String getClassName() {
*/
private static String parsePackage(File file) {
try {
String source = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8);
String source = Files.readString(file.toPath());
// http://stackoverflow.com/questions/1657066/java-regular-expression-finding-comments-in-code
source = source.replaceAll( "//.*|(\"(?:\\\\[^\"]|\\\\\"|.)*?\")|(?s)/\\*.*?\\*/", "$1 " );
for (String line : source.split("\\r?\\n")) {
Expand Down

0 comments on commit 3eb4248

Please sign in to comment.