diff options
author | Jim Hahn <jrh3@att.com> | 2020-04-03 09:44:26 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2020-04-06 09:41:59 -0400 |
commit | a56d3929f2387252525577fb36f9e03933064b8f (patch) | |
tree | 4b671549b5f1c0513c31d77baa19821e422f41e7 /utils/src/main/java/org/onap/policy/common/utils/resources/TextFileUtils.java | |
parent | 7da3ddfa40de2f683a2d423d62b78a8d001108eb (diff) |
Address sonar issues in common
Addressed the following sonar issues:
- missing assertion in junit test case
- disable sonars about setAccessible() as it's required for jackson
emulation
- sleep in junit
- don't use wild-cards (e.g., "*") with java.util Pattern
- use re2j instead of java.util Pattern
- use String methods (e.g., startsWith())
- duplicate method bodies
- duplicate code in Coder classes
- string concatenation in logger calls
- UTF-8 encoding
- return primitive instead of boxed primitive
- add assertion to tests
- renamed support methods from doTestXxx to verifyXxx
- cognitive complexity
- use AtomicRef instead of volatile
- use specific Functionals (e.g., IntConsumer)
- function always returns the same value
- serializable vs transient
Issue-ID: POLICY-2305
Change-Id: I08eb7aa495a80bdc1d26827ba17a7946c83b9828
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'utils/src/main/java/org/onap/policy/common/utils/resources/TextFileUtils.java')
-rw-r--r-- | utils/src/main/java/org/onap/policy/common/utils/resources/TextFileUtils.java | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/utils/src/main/java/org/onap/policy/common/utils/resources/TextFileUtils.java b/utils/src/main/java/org/onap/policy/common/utils/resources/TextFileUtils.java index 01af7fd8..c5b8c981 100644 --- a/utils/src/main/java/org/onap/policy/common/utils/resources/TextFileUtils.java +++ b/utils/src/main/java/org/onap/policy/common/utils/resources/TextFileUtils.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +26,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; /** @@ -34,7 +36,6 @@ import java.nio.file.Files; * @author Liam Fallon (liam.fallon@est.tech) */ public abstract class TextFileUtils { - private static final String UTF_8 = "UTF-8"; private static final int READER_CHAR_BUFFER_SIZE_4096 = 4096; private TextFileUtils() { @@ -50,7 +51,7 @@ public abstract class TextFileUtils { */ public static String getTextFileAsString(final String textFilePath) throws IOException { final File textFile = new File(textFilePath); - return new String(Files.readAllBytes(textFile.toPath()), UTF_8); + return Files.readString(textFile.toPath()); } /** @@ -77,7 +78,7 @@ public abstract class TextFileUtils { * @throws IOException on errors reading text from the file */ public static void putStringAsFile(final String outString, final File textFile) throws IOException { - Files.write(textFile.toPath(), outString.getBytes(UTF_8)); + Files.writeString(textFile.toPath(), outString); } /** @@ -88,7 +89,7 @@ public abstract class TextFileUtils { * @throws IOException on errors reading text from the file */ public static String getStreamAsString(final InputStream textStream) throws IOException { - return getReaderAsString(new InputStreamReader(textStream, UTF_8)); + return getReaderAsString(new InputStreamReader(textStream, StandardCharsets.UTF_8)); } /** |