diff --git a/cli/src/main/java/org/jboss/as/cli/gui/metacommand/ScriptAction.java b/cli/src/main/java/org/jboss/as/cli/gui/metacommand/ScriptAction.java index 60ec3b8e121..630291b5230 100644 --- a/cli/src/main/java/org/jboss/as/cli/gui/metacommand/ScriptAction.java +++ b/cli/src/main/java/org/jboss/as/cli/gui/metacommand/ScriptAction.java @@ -19,12 +19,12 @@ package org.jboss.as.cli.gui.metacommand; import java.awt.event.ActionEvent; -import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.File; -import java.io.FileReader; +import java.io.IOException; import java.io.PrintStream; -import java.util.ArrayList; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.List; import javax.swing.AbstractAction; import javax.swing.JOptionPane; @@ -32,7 +32,6 @@ import org.jboss.as.cli.gui.CliGuiContext; import org.jboss.as.cli.gui.component.CLIOutput; import org.jboss.as.cli.gui.component.ScriptMenu; -import org.jboss.as.protocol.StreamUtils; /** * Abstract action that runs scripts. @@ -85,22 +84,11 @@ protected void runScript(File script) { // read the file as a list of text lines private List getCommandLines(File file) { - List lines = new ArrayList(); - BufferedReader reader = null; try { - reader = new BufferedReader(new FileReader(file)); - String line = reader.readLine(); - while (line != null) { - lines.add(line); - line = reader.readLine(); - } - } catch (Throwable e) { + return Files.readAllLines(file.toPath(), StandardCharsets.UTF_8); + } catch (IOException e) { throw new IllegalStateException("Failed to process file " + file.getAbsolutePath(), e); - } finally { - StreamUtils.safeClose(reader); } - - return lines; } // We need this class because we have to pass on whether or not a diff --git a/cli/src/main/java/org/jboss/as/cli/handlers/ArchiveHandler.java b/cli/src/main/java/org/jboss/as/cli/handlers/ArchiveHandler.java index dfac8b0e0fa..08b475b86c0 100644 --- a/cli/src/main/java/org/jboss/as/cli/handlers/ArchiveHandler.java +++ b/cli/src/main/java/org/jboss/as/cli/handlers/ArchiveHandler.java @@ -26,9 +26,10 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; -import java.io.FileReader; import java.io.IOException; import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.Enumeration; import java.util.Random; import java.util.jar.JarEntry; @@ -104,8 +105,7 @@ public ModelNode buildRequestWithoutHeaders(CommandContext ctx) throws CommandFo } ctx.printLine("Processing script '" + script + "'."); - try { - BufferedReader reader = new BufferedReader(new FileReader(scriptFile)); + try (BufferedReader reader = Files.newBufferedReader(scriptFile.toPath(), StandardCharsets.UTF_8)){ String line = reader.readLine(); while (!ctx.isTerminated() && line != null) { ctx.handle(line); diff --git a/cli/src/main/java/org/jboss/as/cli/handlers/CommandHandlerWithHelp.java b/cli/src/main/java/org/jboss/as/cli/handlers/CommandHandlerWithHelp.java index a9ff2811b32..f4f47353fe8 100644 --- a/cli/src/main/java/org/jboss/as/cli/handlers/CommandHandlerWithHelp.java +++ b/cli/src/main/java/org/jboss/as/cli/handlers/CommandHandlerWithHelp.java @@ -24,6 +24,7 @@ import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.util.Collection; import org.jboss.as.cli.CommandContext; @@ -91,8 +92,9 @@ public void handle(CommandContext ctx) throws CommandLineException { protected void printHelp(CommandContext ctx) throws CommandLineException { InputStream helpInput = WildFlySecurityManager.getClassLoaderPrivileged(CommandHandlerWithHelp.class).getResourceAsStream(filename); if(helpInput != null) { - BufferedReader reader = new BufferedReader(new InputStreamReader(helpInput)); + BufferedReader reader = null; try { + reader = new BufferedReader(new InputStreamReader(helpInput, StandardCharsets.UTF_8)); /* String helpLine = reader.readLine(); while(helpLine != null) { ctx.printLine(helpLine); diff --git a/cli/src/main/java/org/jboss/as/cli/handlers/DeployHandler.java b/cli/src/main/java/org/jboss/as/cli/handlers/DeployHandler.java index f3754ceeaa6..373664347fb 100644 --- a/cli/src/main/java/org/jboss/as/cli/handlers/DeployHandler.java +++ b/cli/src/main/java/org/jboss/as/cli/handlers/DeployHandler.java @@ -25,10 +25,11 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; -import java.io.FileReader; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -658,7 +659,7 @@ public ModelNode buildRequestWithoutHeaders(CommandContext ctx) throws CommandFo BufferedReader reader = null; try { - reader = new BufferedReader(new FileReader(scriptFile)); + reader = Files.newBufferedReader(scriptFile.toPath(), StandardCharsets.UTF_8); String line = reader.readLine(); while (!ctx.isTerminated() && line != null) { ctx.handle(line); diff --git a/cli/src/main/java/org/jboss/as/cli/handlers/UndeployHandler.java b/cli/src/main/java/org/jboss/as/cli/handlers/UndeployHandler.java index 4c1b114597e..8aa37f7a90f 100644 --- a/cli/src/main/java/org/jboss/as/cli/handlers/UndeployHandler.java +++ b/cli/src/main/java/org/jboss/as/cli/handlers/UndeployHandler.java @@ -25,8 +25,9 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; -import java.io.FileReader; import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -351,7 +352,7 @@ public ModelNode buildRequestWithoutHeaders(CommandContext ctx) throws CommandFo BufferedReader reader = null; try { - reader = new BufferedReader(new FileReader(scriptFile)); + reader = Files.newBufferedReader(scriptFile.toPath(), StandardCharsets.UTF_8); String line = reader.readLine(); while (!ctx.isTerminated() && line != null) { ctx.handle(line); diff --git a/cli/src/main/java/org/jboss/as/cli/handlers/batch/BatchHandler.java b/cli/src/main/java/org/jboss/as/cli/handlers/batch/BatchHandler.java index 4af22afb66e..e34359f0b63 100644 --- a/cli/src/main/java/org/jboss/as/cli/handlers/batch/BatchHandler.java +++ b/cli/src/main/java/org/jboss/as/cli/handlers/batch/BatchHandler.java @@ -23,8 +23,9 @@ import java.io.BufferedReader; import java.io.File; -import java.io.FileReader; import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -150,7 +151,7 @@ protected void doHandle(CommandContext ctx) throws CommandLineException { BufferedReader reader = null; try { - reader = new BufferedReader(new FileReader(f)); + reader = Files.newBufferedReader(f.toPath(), StandardCharsets.UTF_8); String line = reader.readLine(); batchManager.activateNewBatch(); final Batch batch = batchManager.getActiveBatch(); diff --git a/cli/src/main/java/org/jboss/as/cli/handlers/batch/BatchRunHandler.java b/cli/src/main/java/org/jboss/as/cli/handlers/batch/BatchRunHandler.java index 6e1a0ae1eb0..131e6c028f8 100644 --- a/cli/src/main/java/org/jboss/as/cli/handlers/batch/BatchRunHandler.java +++ b/cli/src/main/java/org/jboss/as/cli/handlers/batch/BatchRunHandler.java @@ -21,10 +21,12 @@ */ package org.jboss.as.cli.handlers.batch; + import java.io.BufferedReader; import java.io.File; -import java.io.FileReader; import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.List; import org.jboss.as.cli.Attachments; @@ -175,7 +177,7 @@ protected ModelNode buildRequestWOValidation(CommandContext ctx) throws CommandF BufferedReader reader = null; try { - reader = new BufferedReader(new FileReader(f)); + reader = Files.newBufferedReader(f.toPath(), StandardCharsets.UTF_8); String line = reader.readLine(); batchManager.activateNewBatch(); while(line != null) { diff --git a/cli/src/main/java/org/jboss/as/cli/impl/CliLauncher.java b/cli/src/main/java/org/jboss/as/cli/impl/CliLauncher.java index 319179d0400..160ae66e22f 100644 --- a/cli/src/main/java/org/jboss/as/cli/impl/CliLauncher.java +++ b/cli/src/main/java/org/jboss/as/cli/impl/CliLauncher.java @@ -25,7 +25,8 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.FileReader; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -333,7 +334,7 @@ private static void processFile(File file, final CommandContext cmdCtx) { BufferedReader reader = null; try { - reader = new BufferedReader(new FileReader(file)); + reader = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8); String line = reader.readLine(); while (cmdCtx.getExitCode() == 0 && !cmdCtx.isTerminated() && line != null) { cmdCtx.handleSafe(line.trim()); diff --git a/cli/src/main/java/org/jboss/as/cli/impl/CommandContextImpl.java b/cli/src/main/java/org/jboss/as/cli/impl/CommandContextImpl.java index 75b109496bd..533e9b34fca 100644 --- a/cli/src/main/java/org/jboss/as/cli/impl/CommandContextImpl.java +++ b/cli/src/main/java/org/jboss/as/cli/impl/CommandContextImpl.java @@ -25,12 +25,14 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; -import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; import java.net.URI; import java.net.URISyntaxException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; import java.security.GeneralSecurityException; import java.security.KeyStore; import java.security.cert.Certificate; @@ -1576,14 +1578,11 @@ protected void setOutputTarget(String filePath) { this.outputTarget = null; return; } - FileWriter writer; try { - writer = new FileWriter(filePath, false); + this.outputTarget = Files.newBufferedWriter(Paths.get(filePath), StandardCharsets.UTF_8); } catch (IOException e) { error(e.getLocalizedMessage()); - return; } - this.outputTarget = new BufferedWriter(writer); } protected void notifyListeners(CliEvent event) { diff --git a/controller/src/main/java/org/jboss/as/controller/audit/AbstractFileAuditLogHandler.java b/controller/src/main/java/org/jboss/as/controller/audit/AbstractFileAuditLogHandler.java index a57ddfda122..e946c992ad9 100644 --- a/controller/src/main/java/org/jboss/as/controller/audit/AbstractFileAuditLogHandler.java +++ b/controller/src/main/java/org/jboss/as/controller/audit/AbstractFileAuditLogHandler.java @@ -33,6 +33,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.nio.charset.StandardCharsets; /** * All methods on this class should be called with {@link org.jboss.as.controller.audit.ManagedAuditLoggerImpl}'s lock taken. @@ -41,7 +42,7 @@ * @author Ivo Studensky */ public abstract class AbstractFileAuditLogHandler extends AuditLogHandler { - protected static final byte[] LINE_TERMINATOR = String.format("%n").getBytes(); + protected static final byte[] LINE_TERMINATOR = System.lineSeparator().getBytes(StandardCharsets.UTF_8); private final PathManagerService pathManager; private final String path; private final String relativeTo; @@ -93,7 +94,7 @@ void writeLogItem(String formattedItem) throws IOException { final FileOutputStream fos = new FileOutputStream(file, true); final BufferedOutputStream output = new BufferedOutputStream(fos); try { - output.write(formattedItem.getBytes()); + output.write(formattedItem.getBytes(StandardCharsets.UTF_8)); output.write(LINE_TERMINATOR); //Flush and force the file to sync diff --git a/controller/src/main/java/org/jboss/as/controller/audit/SizeRotatingFileAuditLogHandler.java b/controller/src/main/java/org/jboss/as/controller/audit/SizeRotatingFileAuditLogHandler.java index 6a5e3646e1c..eb70655dd9f 100644 --- a/controller/src/main/java/org/jboss/as/controller/audit/SizeRotatingFileAuditLogHandler.java +++ b/controller/src/main/java/org/jboss/as/controller/audit/SizeRotatingFileAuditLogHandler.java @@ -26,6 +26,7 @@ import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; /** * All methods on this class should be called with {@link org.jboss.as.controller.audit.ManagedAuditLoggerImpl}'s lock taken. @@ -85,7 +86,7 @@ protected void rotateLogFile(final File file) { @Override void writeLogItem(String formattedItem) throws IOException { super.writeLogItem(formattedItem); - currentSize += formattedItem.getBytes().length; + currentSize += formattedItem.getBytes(StandardCharsets.UTF_8).length; currentSize += LINE_TERMINATOR.length; } diff --git a/controller/src/main/java/org/jboss/as/controller/operations/common/XmlMarshallingHandler.java b/controller/src/main/java/org/jboss/as/controller/operations/common/XmlMarshallingHandler.java index abb00c6ed4a..4cddf92c3e6 100644 --- a/controller/src/main/java/org/jboss/as/controller/operations/common/XmlMarshallingHandler.java +++ b/controller/src/main/java/org/jboss/as/controller/operations/common/XmlMarshallingHandler.java @@ -28,6 +28,7 @@ import java.io.BufferedOutputStream; import java.io.ByteArrayOutputStream; import java.io.Closeable; +import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.EnumSet; import java.util.Set; @@ -95,7 +96,7 @@ public void execute(OperationContext context, ModelNode operation) { } finally { safeClose(baos); } - String xml = new String(baos.toByteArray()); + String xml = new String(baos.toByteArray(), StandardCharsets.UTF_8); context.getResult().set(xml); } catch (RuntimeException e) { throw e; diff --git a/controller/src/main/java/org/jboss/as/controller/operations/global/ListOperations.java b/controller/src/main/java/org/jboss/as/controller/operations/global/ListOperations.java index e593414d1ac..d2bc36e237d 100644 --- a/controller/src/main/java/org/jboss/as/controller/operations/global/ListOperations.java +++ b/controller/src/main/java/org/jboss/as/controller/operations/global/ListOperations.java @@ -153,7 +153,7 @@ void updateModel(final OperationContext context, ModelNode model, ModelNode list /** * Add element to list, with optional index where to put it *

- *

:list-remove(name=list-attribute, value="some value")
+ *
:list-get(name=list-attribute, index=5)
* * @author Tomaz Cerar (c) 2014 Red Hat Inc. */ diff --git a/controller/src/main/java/org/jboss/as/controller/transform/SubsystemDescriptionDump.java b/controller/src/main/java/org/jboss/as/controller/transform/SubsystemDescriptionDump.java index 1eb05aa37f5..eb0700bb643 100644 --- a/controller/src/main/java/org/jboss/as/controller/transform/SubsystemDescriptionDump.java +++ b/controller/src/main/java/org/jboss/as/controller/transform/SubsystemDescriptionDump.java @@ -22,9 +22,11 @@ package org.jboss.as.controller.transform; -import java.io.File; import java.io.IOException; import java.io.PrintWriter; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.Locale; import org.jboss.as.controller.OperationContext; @@ -43,7 +45,7 @@ import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelType; -/** +/** todo move to test code, no need to have it at proper runtime * @author Tomaz Cerar */ public class SubsystemDescriptionDump implements OperationStepHandler { @@ -80,7 +82,7 @@ public static void dumpManagementResourceRegistration(final ImmutableManagementR SubsystemInformation info = registry.getSubsystemInfo(subsystem); ModelNode desc = readFullModelDescription(PathAddress.pathAddress(pe), registration); String name = subsystem + "-" + info.getManagementInterfaceMajorVersion() + "." + info.getManagementInterfaceMinorVersion() +"."+info.getManagementInterfaceMicroVersion()+ ".dmr"; - PrintWriter pw = new PrintWriter(new File(path, name)); + PrintWriter pw = new PrintWriter(Files.newBufferedWriter(Paths.get(path,name), StandardCharsets.UTF_8)); desc.writeString(pw, false); pw.close(); } diff --git a/controller/src/test/java/org/jboss/as/controller/persistence/PersistanceResourceTestCase.java b/controller/src/test/java/org/jboss/as/controller/persistence/PersistanceResourceTestCase.java index b16f8cdcca5..f961ee6662a 100644 --- a/controller/src/test/java/org/jboss/as/controller/persistence/PersistanceResourceTestCase.java +++ b/controller/src/test/java/org/jboss/as/controller/persistence/PersistanceResourceTestCase.java @@ -31,12 +31,9 @@ import static org.junit.Assert.assertThat; import java.io.BufferedReader; -import java.io.BufferedWriter; import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; import java.io.IOException; -import java.io.Writer; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.attribute.AclEntry; @@ -62,7 +59,6 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.xnio.IoUtils; /** * @@ -916,12 +912,7 @@ private File createFile(File dir, String name, String contents) throws IOExcepti checkDirectoryExists(dir); File file = new File(dir, name); if (contents != null) { - Writer out = new BufferedWriter(new FileWriter(file)); - try { - out.write(contents); - } finally { - IoUtils.safeClose(out); - } + Files.write(file.toPath(), contents.getBytes(StandardCharsets.UTF_8)); } return file; } @@ -945,15 +936,12 @@ private void delete(File file) { private void assertFileContents(File file, String expectedContents) throws Exception { Assert.assertTrue(file + " does not exist", file.exists()); StringBuilder sb = new StringBuilder(); - BufferedReader in = new BufferedReader(new FileReader(file)); - try { + try (BufferedReader in = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8)){ String s = in.readLine(); while (s != null) { sb.append(s); s = in.readLine(); } - } finally { - in.close(); } Assert.assertEquals(expectedContents, sb.toString()); } diff --git a/controller/src/test/java/org/jboss/as/controller/persistence/PersistentResourceXMLParserTestCase.java b/controller/src/test/java/org/jboss/as/controller/persistence/PersistentResourceXMLParserTestCase.java index c1a9fb928e6..bb35ed9d6ee 100644 --- a/controller/src/test/java/org/jboss/as/controller/persistence/PersistentResourceXMLParserTestCase.java +++ b/controller/src/test/java/org/jboss/as/controller/persistence/PersistentResourceXMLParserTestCase.java @@ -34,6 +34,7 @@ import java.io.StringReader; import java.io.StringWriter; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -100,7 +101,7 @@ private static String readResource(final String name) throws IOException { Assert.assertNotNull(name + " url is null", configURL); StringWriter writer = new StringWriter(); - try (BufferedReader reader = new BufferedReader(new InputStreamReader(configURL.openStream()))) { + try (BufferedReader reader = new BufferedReader(new InputStreamReader(configURL.openStream(), StandardCharsets.UTF_8))) { String line; while ((line = reader.readLine()) != null) { writer.write(line + "\n"); diff --git a/controller/src/test/java/org/jboss/as/controller/persistence/TestConfigurationPersister.java b/controller/src/test/java/org/jboss/as/controller/persistence/TestConfigurationPersister.java index 0e82aeb95a3..245c6305ae3 100644 --- a/controller/src/test/java/org/jboss/as/controller/persistence/TestConfigurationPersister.java +++ b/controller/src/test/java/org/jboss/as/controller/persistence/TestConfigurationPersister.java @@ -22,6 +22,7 @@ package org.jboss.as.controller.persistence; import java.io.OutputStream; +import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.List; import java.util.Set; @@ -53,7 +54,7 @@ public List load() throws ConfigurationPersistenceException { @Override public void marshallAsXml(ModelNode model, OutputStream output) throws ConfigurationPersistenceException { try { - output.write(model.asString().getBytes()); + output.write(model.asString().getBytes(StandardCharsets.UTF_8)); } catch (Exception e) { throw new ConfigurationPersistenceException(e); } diff --git a/deployment-scanner/src/main/java/org/jboss/as/server/deployment/scanner/FileSystemDeploymentService.java b/deployment-scanner/src/main/java/org/jboss/as/server/deployment/scanner/FileSystemDeploymentService.java index 015d9017874..29bf90515f9 100644 --- a/deployment-scanner/src/main/java/org/jboss/as/server/deployment/scanner/FileSystemDeploymentService.java +++ b/deployment-scanner/src/main/java/org/jboss/as/server/deployment/scanner/FileSystemDeploymentService.java @@ -52,6 +52,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.net.MalformedURLException; +import java.nio.charset.StandardCharsets; import java.nio.file.DirectoryStream; import java.nio.file.DirectoryStream.Filter; import java.nio.file.Files; @@ -1305,7 +1306,7 @@ private void createMarkerFile(final File marker, String deploymentName) { // marker.createNewFile(); - Don't create before the write as there is a potential race condition where // the file is deleted between the two calls. fos = new FileOutputStream(marker); - fos.write(deploymentName.getBytes()); + fos.write(deploymentName.getBytes(StandardCharsets.UTF_8)); } catch (IOException io) { ROOT_LOGGER.errorWritingDeploymentMarker(io, marker.getAbsolutePath()); } finally { @@ -1331,7 +1332,7 @@ private void writeFailedMarker(final File deploymentFile, final String failureDe try { // failedMarker.createNewFile(); fos = new FileOutputStream(failedMarker); - fos.write(failureDescription.getBytes()); + fos.write(failureDescription.getBytes(StandardCharsets.UTF_8)); } catch (IOException io) { ROOT_LOGGER.errorWritingDeploymentMarker(io, failedMarker.getAbsolutePath()); } finally { diff --git a/deployment-scanner/src/test/java/org/jboss/as/server/deployment/scanner/FileSystemDeploymentServiceUnitTestCase.java b/deployment-scanner/src/test/java/org/jboss/as/server/deployment/scanner/FileSystemDeploymentServiceUnitTestCase.java index 5aa3c91a3b7..9a1647b6811 100644 --- a/deployment-scanner/src/test/java/org/jboss/as/server/deployment/scanner/FileSystemDeploymentServiceUnitTestCase.java +++ b/deployment-scanner/src/test/java/org/jboss/as/server/deployment/scanner/FileSystemDeploymentServiceUnitTestCase.java @@ -54,9 +54,9 @@ import static org.junit.Assert.fail; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; -import java.io.PrintWriter; +import java.nio.charset.StandardCharsets; + import java.nio.file.Files; import java.util.ArrayList; import java.util.Arrays; @@ -1973,16 +1973,8 @@ private File createFile(String fileName) throws IOException { private File createFile(File dir, String fileName) throws IOException { dir.mkdirs(); - File f = new File(dir, fileName); - FileOutputStream fos = new FileOutputStream(f); - try { - PrintWriter writer = new PrintWriter(fos); - writer.write(fileName); - writer.close(); - } finally { - fos.close(); - } + Files.write(f.toPath(), fileName.getBytes(StandardCharsets.UTF_8)); assertTrue(f.exists()); return f; } @@ -1991,14 +1983,7 @@ private File createXmlFile(String fileName, String contents) throws IOException tmpDir.mkdirs(); File f = new File(tmpDir, fileName); - FileOutputStream fos = new FileOutputStream(f); - try { - PrintWriter writer = new PrintWriter(fos); - writer.write(contents); - writer.close(); - } finally { - fos.close(); - } + Files.write(f.toPath(), contents.getBytes(StandardCharsets.UTF_8)); assertTrue(f.exists()); return f; } diff --git a/domain-http/interface/src/main/java/org/jboss/as/domain/http/server/Common.java b/domain-http/interface/src/main/java/org/jboss/as/domain/http/server/Common.java index c1f72b298e0..0fe692ed9c8 100644 --- a/domain-http/interface/src/main/java/org/jboss/as/domain/http/server/Common.java +++ b/domain-http/interface/src/main/java/org/jboss/as/domain/http/server/Common.java @@ -27,6 +27,7 @@ import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; +import java.nio.charset.StandardCharsets; import io.undertow.io.IoCallback; import io.undertow.server.HttpServerExchange; @@ -81,7 +82,7 @@ static void sendError(HttpServerExchange exchange, boolean encode, ModelNode msg exchange.getResponseHeaders().put(Headers.CONTENT_LENGTH, String.valueOf(bytes.length)); exchange.setStatusCode(errorCode); - exchange.getResponseSender().send(new String(bytes), IoCallback.END_EXCHANGE); + exchange.getResponseSender().send(new String(bytes, StandardCharsets.UTF_8), IoCallback.END_EXCHANGE); } catch (IOException e) { // fallback, should not happen @@ -101,7 +102,7 @@ static void sendError(HttpServerExchange exchange, boolean encode, ModelNode msg } String msgString = stringWriter.toString(); - byte[] bytes = msgString.getBytes(); + byte[] bytes = msgString.getBytes(StandardCharsets.UTF_8); exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, APPLICATION_JSON + "; charset=" + UTF_8); exchange.getResponseHeaders().put(Headers.CONTENT_LENGTH, String.valueOf(bytes.length)); exchange.setStatusCode(errorCode); diff --git a/domain-http/interface/src/main/java/org/jboss/as/domain/http/server/DomainApiGenericOperationHandler.java b/domain-http/interface/src/main/java/org/jboss/as/domain/http/server/DomainApiGenericOperationHandler.java index a25a53d5068..eec3cd39ee9 100644 --- a/domain-http/interface/src/main/java/org/jboss/as/domain/http/server/DomainApiGenericOperationHandler.java +++ b/domain-http/interface/src/main/java/org/jboss/as/domain/http/server/DomainApiGenericOperationHandler.java @@ -41,6 +41,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.Deque; import java.util.Iterator; @@ -206,7 +207,7 @@ private InputStream convertToStream(FormData.FormValue op) throws IOException { if (op.isFile()) { return Files.newInputStream(op.getPath()); } else { - return new ByteArrayInputStream(op.getValue().getBytes()); + return new ByteArrayInputStream(op.getValue().getBytes(StandardCharsets.UTF_8)); } } diff --git a/domain-http/interface/src/main/java/org/jboss/as/domain/http/server/DomainApiHandler.java b/domain-http/interface/src/main/java/org/jboss/as/domain/http/server/DomainApiHandler.java index fb95f2db8ae..00606cab7c5 100644 --- a/domain-http/interface/src/main/java/org/jboss/as/domain/http/server/DomainApiHandler.java +++ b/domain-http/interface/src/main/java/org/jboss/as/domain/http/server/DomainApiHandler.java @@ -47,6 +47,7 @@ import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.util.ArrayList; import java.util.Deque; @@ -222,7 +223,7 @@ public void operationPrepared(final ModelController.OperationTransaction transac if (cachable && streamIndex > -1) { // Use the MD5 of the model nodes asString() method as ETag MessageDigest md = MessageDigest.getInstance("MD5"); - md.update(response.getResponseNode().asString().getBytes()); + md.update(response.getResponseNode().toString().getBytes(StandardCharsets.UTF_8)); ETag etag = new ETag(false, HexConverter.convertToHexString(md.digest())); operationParameterBuilder.etag(etag); if (!ETagUtils.handleIfNoneMatch(exchange, etag, false)) { diff --git a/domain-management/src/main/java/org/jboss/as/domain/management/security/LdapGroupSearcherFactory.java b/domain-management/src/main/java/org/jboss/as/domain/management/security/LdapGroupSearcherFactory.java index 9e90b698ef2..064429e8a97 100644 --- a/domain-management/src/main/java/org/jboss/as/domain/management/security/LdapGroupSearcherFactory.java +++ b/domain-management/src/main/java/org/jboss/as/domain/management/security/LdapGroupSearcherFactory.java @@ -26,6 +26,7 @@ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; @@ -364,7 +365,7 @@ private LdapEntry parseRole(String dn, String groupNameAttribute, URI groupRefer if (attr != null) { Object value = attr.get(); if (value != null) { - return new LdapEntry( (value instanceof byte[]) ? new String((byte[]) value) : value.toString(), dn, groupReferralAddress); + return new LdapEntry( (value instanceof byte[]) ? new String((byte[]) value, StandardCharsets.UTF_8) : value.toString(), dn, groupReferralAddress); } } } diff --git a/domain-management/src/main/java/org/jboss/as/domain/management/security/PropertiesFileLoader.java b/domain-management/src/main/java/org/jboss/as/domain/management/security/PropertiesFileLoader.java index 92b27f15eed..10b143193a5 100644 --- a/domain-management/src/main/java/org/jboss/as/domain/management/security/PropertiesFileLoader.java +++ b/domain-management/src/main/java/org/jboss/as/domain/management/security/PropertiesFileLoader.java @@ -30,12 +30,11 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; -import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; +import java.nio.file.Files; import java.util.Arrays; import java.util.List; import java.util.Properties; @@ -282,19 +281,7 @@ protected String cleanKey(final String key) { } protected List readFile(File file) throws IOException { - FileReader fileReader = new FileReader(file); - BufferedReader bufferedFileReader = new BufferedReader(fileReader); - List content = new ArrayList(); - try { - String line; - while ((line = bufferedFileReader.readLine()) != null) { - addLineContent(bufferedFileReader, content, line); - } - } finally { - safeClose(bufferedFileReader); - safeClose(fileReader); - } - return content; + return Files.readAllLines(file.toPath(), StandardCharsets.UTF_8); } /** diff --git a/domain-management/src/main/java/org/jboss/as/domain/management/security/SecretIdentityService.java b/domain-management/src/main/java/org/jboss/as/domain/management/security/SecretIdentityService.java index 8cbd3beaf13..7adcd50777a 100644 --- a/domain-management/src/main/java/org/jboss/as/domain/management/security/SecretIdentityService.java +++ b/domain-management/src/main/java/org/jboss/as/domain/management/security/SecretIdentityService.java @@ -33,6 +33,7 @@ import org.jboss.msc.service.StartException; import org.jboss.msc.service.StopContext; +import java.nio.charset.StandardCharsets; import java.util.Base64; import javax.security.auth.callback.Callback; import javax.security.auth.callback.CallbackHandler; @@ -66,7 +67,7 @@ public void start(StartContext startContext) throws StartException { final char[] thePassword; if (base64) { byte[] value = Base64.getDecoder().decode(password); - String tempPassword = new String(value); + String tempPassword = new String(value, StandardCharsets.ISO_8859_1); String trimmedPassword = tempPassword.trim(); if (tempPassword.equals(trimmedPassword) == false) { ROOT_LOGGER.whitespaceTrimmed(); diff --git a/domain-management/src/main/java/org/jboss/as/domain/management/security/UserPropertiesFileLoader.java b/domain-management/src/main/java/org/jboss/as/domain/management/security/UserPropertiesFileLoader.java index 7160d784003..e4d7361bf27 100644 --- a/domain-management/src/main/java/org/jboss/as/domain/management/security/UserPropertiesFileLoader.java +++ b/domain-management/src/main/java/org/jboss/as/domain/management/security/UserPropertiesFileLoader.java @@ -24,8 +24,9 @@ import java.io.BufferedReader; import java.io.BufferedWriter; -import java.io.FileReader; import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; @@ -94,10 +95,11 @@ protected void load() throws IOException { super.load(); String realmName = null; - BufferedReader br = new BufferedReader(new FileReader(propertiesFile)); + BufferedReader br = null; disabledUserNames.clear(); enabledUserNames.clear(); try { + br = Files.newBufferedReader(propertiesFile.toPath(), StandardCharsets.UTF_8); String currentLine; while (realmName == null && (currentLine = br.readLine()) != null) { final String trimmed = currentLine.trim(); diff --git a/domain-management/src/main/java/org/jboss/as/domain/management/security/adduser/DisplaySecret.java b/domain-management/src/main/java/org/jboss/as/domain/management/security/adduser/DisplaySecret.java index bb2adc426fb..a91db8384f9 100644 --- a/domain-management/src/main/java/org/jboss/as/domain/management/security/adduser/DisplaySecret.java +++ b/domain-management/src/main/java/org/jboss/as/domain/management/security/adduser/DisplaySecret.java @@ -23,6 +23,8 @@ package org.jboss.as.domain.management.security.adduser; import org.jboss.as.domain.management.logging.DomainManagementLogger; + +import java.nio.charset.StandardCharsets; import java.util.Base64; import static org.jboss.as.domain.management.security.adduser.AddUser.NEW_LINE; @@ -43,7 +45,7 @@ public DisplaySecret(ConsoleWrapper theConsole, final StateValues stateValues) { } public State execute() { - String pwdBase64 = Base64.getEncoder().encodeToString(stateValues.getPassword().getBytes()); + String pwdBase64 = Base64.getEncoder().encodeToString(stateValues.getPassword().getBytes(StandardCharsets.UTF_8)); theConsole.printf(DomainManagementLogger.ROOT_LOGGER.secretElement(pwdBase64)); theConsole.printf(NEW_LINE); diff --git a/domain-management/src/test/java/org/jboss/as/domain/management/security/adduser/PropertyTestHelper.java b/domain-management/src/test/java/org/jboss/as/domain/management/security/adduser/PropertyTestHelper.java index 5b77af13fd5..c3f2c990841 100644 --- a/domain-management/src/test/java/org/jboss/as/domain/management/security/adduser/PropertyTestHelper.java +++ b/domain-management/src/test/java/org/jboss/as/domain/management/security/adduser/PropertyTestHelper.java @@ -26,11 +26,11 @@ import org.jboss.msc.service.StartException; import org.junit.Before; -import java.io.BufferedReader; -import java.io.Closeable; import java.io.File; -import java.io.FileReader; import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.Properties; @@ -275,25 +275,6 @@ private String getValueFromFile(String userName, String filePath, boolean onlyDi } private List readContent(String filePath) throws IOException { - List content = new ArrayList(); - FileReader fileReader = new FileReader(filePath); - BufferedReader bufferedFileReader = new BufferedReader(fileReader); - try { - String line; - while ((line = bufferedFileReader.readLine()) != null) { - content.add(line); - } - } finally { - safeClose(bufferedFileReader); - safeClose(fileReader); - } - return content; - } - - private void safeClose(final Closeable c) { - try { - c.close(); - } catch (IOException ignored) { - } + return Files.readAllLines(Paths.get(filePath), StandardCharsets.UTF_8); } } diff --git a/domain-management/src/test/java/org/jboss/as/domain/management/security/auditlog/AbstractAuditLogHandlerTestCase.java b/domain-management/src/test/java/org/jboss/as/domain/management/security/auditlog/AbstractAuditLogHandlerTestCase.java index 3e40877cbb4..21dada33ef4 100644 --- a/domain-management/src/test/java/org/jboss/as/domain/management/security/auditlog/AbstractAuditLogHandlerTestCase.java +++ b/domain-management/src/test/java/org/jboss/as/domain/management/security/auditlog/AbstractAuditLogHandlerTestCase.java @@ -35,12 +35,12 @@ import java.io.BufferedReader; import java.io.File; -import java.io.FileReader; import java.io.FilenameFilter; import java.io.IOException; import java.io.StringWriter; import java.net.InetAddress; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; @@ -66,7 +66,6 @@ import org.jboss.logmanager.handlers.SyslogHandler; import org.junit.After; import org.junit.Assert; -import org.xnio.IoUtils; /** * Don't use core-model test for this. It does not support runtime, and more importantly for backwards compatibility the audit logger cannot be used @@ -159,8 +158,8 @@ protected void checkOpsEqual(ModelNode rawDmr, ModelNode fromLog) { protected List readFile(File file, int expectedRecords) throws IOException { List list = new ArrayList(); - final BufferedReader reader = new BufferedReader(new FileReader(file)); - try { + + try (final BufferedReader reader = Files.newBufferedReader(file.toPath(),StandardCharsets.UTF_8)){ StringWriter writer = null; String line = reader.readLine(); while (line != null) { @@ -178,16 +177,13 @@ protected List readFile(File file, int expectedRecords) throws IOExce if (writer != null) { list.add(ModelNode.fromJSONString(writer.getBuffer().toString())); } - } finally { - IoUtils.safeClose(reader); } Assert.assertEquals(list.toString(), expectedRecords, list.size()); return list; } protected String readFullFileRecord(File file) throws IOException { - final BufferedReader reader = new BufferedReader(new FileReader(file)); - try { + try (final BufferedReader reader = Files.newBufferedReader(file.toPath(),StandardCharsets.UTF_8)){ boolean firstLine = true; StringWriter writer = new StringWriter(); String line = reader.readLine(); @@ -201,8 +197,6 @@ protected String readFullFileRecord(File file) throws IOException { line = reader.readLine(); } return writer.toString(); - } finally { - IoUtils.safeClose(reader); } } diff --git a/domain-management/src/test/java/org/jboss/as/domain/management/security/realms/PropertiesAuthenticationDigestedTestCase.java b/domain-management/src/test/java/org/jboss/as/domain/management/security/realms/PropertiesAuthenticationDigestedTestCase.java index 96318b81c84..ca67ff5f77f 100644 --- a/domain-management/src/test/java/org/jboss/as/domain/management/security/realms/PropertiesAuthenticationDigestedTestCase.java +++ b/domain-management/src/test/java/org/jboss/as/domain/management/security/realms/PropertiesAuthenticationDigestedTestCase.java @@ -32,8 +32,9 @@ import java.io.File; import java.io.IOException; -import java.io.PrintWriter; import java.security.Security; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.Set; import javax.security.auth.callback.Callback; @@ -148,12 +149,7 @@ protected void initialiseRealm(SecurityRealmAddBuilder builder) throws Exception } UsernamePasswordHashUtil uph = new UsernamePasswordHashUtil(); - PrintWriter pw = new PrintWriter(propertiesFile); - try { - pw.println(TEST_USERNAME + "=" + uph.generateHashedHexURP(TEST_USERNAME, TEST_REALM, TEST_PASSWORD.toCharArray())); - } finally { - pw.close(); - } + Files.write(propertiesFile.toPath(), (TEST_USERNAME + "=" + uph.generateHashedHexURP(TEST_USERNAME, TEST_REALM, TEST_PASSWORD.toCharArray())).getBytes(StandardCharsets.UTF_8)); builder.authentication().property().setPath(propertiesFile.getAbsolutePath()).build().build(); } diff --git a/host-controller/src/test/java/org/jboss/as/domain/controller/operations/SyncModelServerStateTestCase.java b/host-controller/src/test/java/org/jboss/as/domain/controller/operations/SyncModelServerStateTestCase.java index 4ef06f33988..072415160b9 100644 --- a/host-controller/src/test/java/org/jboss/as/domain/controller/operations/SyncModelServerStateTestCase.java +++ b/host-controller/src/test/java/org/jboss/as/domain/controller/operations/SyncModelServerStateTestCase.java @@ -29,10 +29,10 @@ import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SYSTEM_PROPERTY; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.VALUE; -import java.io.BufferedWriter; import java.io.File; -import java.io.FileWriter; import java.io.PrintWriter; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -932,7 +932,7 @@ void addRolloutPlan(ModelNode dmr) throws Exception { File file = new File(tempDir, "content"); this.vf = VFS.getChild(file.toURI()); - try (final PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(file)));){ + try (final PrintWriter out = new PrintWriter(Files.newBufferedWriter(file.toPath(), StandardCharsets.UTF_8))){ dmr.writeString(out, true); } } diff --git a/jmx/src/test/java/org/jboss/as/jmx/auditlog/JmxAuditLogHandlerTestCase.java b/jmx/src/test/java/org/jboss/as/jmx/auditlog/JmxAuditLogHandlerTestCase.java index 7c5a8a99cc4..df265a06189 100644 --- a/jmx/src/test/java/org/jboss/as/jmx/auditlog/JmxAuditLogHandlerTestCase.java +++ b/jmx/src/test/java/org/jboss/as/jmx/auditlog/JmxAuditLogHandlerTestCase.java @@ -26,9 +26,10 @@ import java.io.BufferedReader; import java.io.File; -import java.io.FileReader; import java.io.IOException; import java.io.StringWriter; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashMap; @@ -588,8 +589,7 @@ private void checkOpsEqual(ModelNode rawDmr, ModelNode fromLog) { private List readFile(File file, int expectedRecords) throws IOException { List list = new ArrayList(); - final BufferedReader reader = new BufferedReader(new FileReader(file)); - try { + try (final BufferedReader reader = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8)){ StringWriter writer = null; String line = reader.readLine(); while (line != null) { @@ -607,8 +607,6 @@ private List readFile(File file, int expectedRecords) throws IOExcept if (writer != null) { list.add(ModelNode.fromJSONString(writer.getBuffer().toString())); } - } finally { - reader.close(); } Assert.assertEquals(list.toString(), expectedRecords, list.size()); return list; diff --git a/logging/src/main/java/org/jboss/as/logging/LogFileResourceDefinition.java b/logging/src/main/java/org/jboss/as/logging/LogFileResourceDefinition.java index bc528364530..bf777940b8c 100644 --- a/logging/src/main/java/org/jboss/as/logging/LogFileResourceDefinition.java +++ b/logging/src/main/java/org/jboss/as/logging/LogFileResourceDefinition.java @@ -257,6 +257,11 @@ private List readLines(final File file, final String encoding, final boo } try ( final InputStream in = (tail ? new LifoFileInputStream(file) : Files.newInputStream(file.toPath())); + /* we should stick with the default here and not use UTF-8. + The encoding on the file handler does not default to UTF-8 but the system default. + I think here we should stick with the system default unless explicitly defined. + I could see a UTF-8 default possibly being problematic on IBM bases systems. + */ final InputStreamReader isr = (encoding == null ? new InputStreamReader(in) : new InputStreamReader(in, encoding)); final BufferedReader reader = new BufferedReader(isr) ) { diff --git a/logging/src/main/java/org/jboss/as/logging/LoggingResourceDefinition.java b/logging/src/main/java/org/jboss/as/logging/LoggingResourceDefinition.java index 51d8d4d1602..7f5f76be8e2 100644 --- a/logging/src/main/java/org/jboss/as/logging/LoggingResourceDefinition.java +++ b/logging/src/main/java/org/jboss/as/logging/LoggingResourceDefinition.java @@ -300,6 +300,7 @@ private List readLines(final File file, final String encoding, final boo in = new FileInputStream(file); } if (encoding == null) { + //system default used on purpose reader = new BufferedReader(new InputStreamReader(in)); } else { reader = new BufferedReader(new InputStreamReader(in, encoding)); diff --git a/logging/src/main/java/org/jboss/as/logging/logmanager/ConfigurationPersistence.java b/logging/src/main/java/org/jboss/as/logging/logmanager/ConfigurationPersistence.java index 46b189d153d..4ee941676a6 100644 --- a/logging/src/main/java/org/jboss/as/logging/logmanager/ConfigurationPersistence.java +++ b/logging/src/main/java/org/jboss/as/logging/logmanager/ConfigurationPersistence.java @@ -28,6 +28,7 @@ import java.io.IOException; import java.io.InputStream; import java.nio.channels.FileLock; +import java.nio.charset.StandardCharsets; import java.util.List; import org.jboss.as.controller.OperationContext; @@ -59,7 +60,7 @@ public class ConfigurationPersistence implements Configurator, LogContextConfigu private static final Object LOCK = new Object(); private static final String PROPERTIES_FILE = "logging.properties"; private static final byte[] NOTE_MESSAGE = String.format("# Note this file has been generated and will be overwritten if a%n" + - "# logging subsystem has been defined in the XML configuration.%n%n").getBytes(); + "# logging subsystem has been defined in the XML configuration.%n%n").getBytes(StandardCharsets.UTF_8); private final PropertyConfigurator config; private final LogContextConfiguration delegate; diff --git a/management-client-content/src/main/java/org/jboss/as/management/client/content/ManagedDMRContentTypeResource.java b/management-client-content/src/main/java/org/jboss/as/management/client/content/ManagedDMRContentTypeResource.java index 493eee5f124..4d774e37402 100644 --- a/management-client-content/src/main/java/org/jboss/as/management/client/content/ManagedDMRContentTypeResource.java +++ b/management-client-content/src/main/java/org/jboss/as/management/client/content/ManagedDMRContentTypeResource.java @@ -29,6 +29,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.nio.charset.StandardCharsets; import java.security.DigestOutputStream; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; @@ -324,7 +325,7 @@ private void storeContent() throws IOException { } } if (hasContent) { - ByteArrayInputStream bais = new ByteArrayInputStream(node.toString().getBytes()); + ByteArrayInputStream bais = new ByteArrayInputStream(node.toString().getBytes(StandardCharsets.UTF_8)); byte[] ourHash = contentRepository.addContent(bais); this.model.get(HASH).set(ourHash); this.contentRepository.addContentReference(new ContentReference(address.toCLIStyleString(), ourHash)); @@ -348,7 +349,7 @@ public void write(int b) throws IOException { messageDigest.reset(); DigestOutputStream dos = new DigestOutputStream(os, messageDigest); - ByteArrayInputStream bis = new ByteArrayInputStream(content.toString().getBytes()); + ByteArrayInputStream bis = new ByteArrayInputStream(content.toString().getBytes(StandardCharsets.UTF_8)); byte[] bytes = new byte[8192]; int read; while ((read = bis.read(bytes)) > -1) { diff --git a/model-test/src/main/java/org/jboss/as/model/test/ModelTestUtils.java b/model-test/src/main/java/org/jboss/as/model/test/ModelTestUtils.java index 83b682db5ea..950a4bb997b 100644 --- a/model-test/src/main/java/org/jboss/as/model/test/ModelTestUtils.java +++ b/model-test/src/main/java/org/jboss/as/model/test/ModelTestUtils.java @@ -36,6 +36,7 @@ import java.io.StringWriter; import java.net.URL; import java.util.ArrayList; +import java.nio.charset.StandardCharsets; import java.util.HashSet; import java.util.List; import java.util.Locale; @@ -84,11 +85,10 @@ public class ModelTestUtils { * @throws IOException */ public static String readResource(final Class clazz, final String name) throws IOException { - URL configURL = clazz.getResource(name); Assert.assertNotNull(name + " url is null", configURL); - BufferedReader reader = new BufferedReader(new InputStreamReader(configURL.openStream())); + BufferedReader reader = new BufferedReader(new InputStreamReader(configURL.openStream(), StandardCharsets.UTF_8)); StringWriter writer = new StringWriter(); try { String line; diff --git a/model-test/src/main/java/org/jboss/as/model/test/StringConfigurationPersister.java b/model-test/src/main/java/org/jboss/as/model/test/StringConfigurationPersister.java index ca78b23ea1c..8d35633d89e 100644 --- a/model-test/src/main/java/org/jboss/as/model/test/StringConfigurationPersister.java +++ b/model-test/src/main/java/org/jboss/as/model/test/StringConfigurationPersister.java @@ -22,6 +22,7 @@ package org.jboss.as.model.test; import java.io.ByteArrayOutputStream; +import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Set; @@ -94,7 +95,7 @@ private class StringPersistenceResource implements PersistenceResource { @Override public void commit() { - marshalled = new String(bytes); + marshalled = new String(bytes, StandardCharsets.UTF_8); } @Override diff --git a/patching/src/main/java/org/jboss/as/patching/runner/PatchUtils.java b/patching/src/main/java/org/jboss/as/patching/runner/PatchUtils.java index ad325cac89f..cf919455b30 100644 --- a/patching/src/main/java/org/jboss/as/patching/runner/PatchUtils.java +++ b/patching/src/main/java/org/jboss/as/patching/runner/PatchUtils.java @@ -175,7 +175,7 @@ static void writeRefs(final OutputStream os, final List refs) throws IOE } static void writeLine(final OutputStream os, final String s) throws IOException { - os.write(s.getBytes()); + os.write(s.getBytes(StandardCharsets.UTF_8)); os.write('\n'); } diff --git a/patching/src/test/java/org/jboss/as/patching/cli/CLIPatchInfoUtil.java b/patching/src/test/java/org/jboss/as/patching/cli/CLIPatchInfoUtil.java index dfd3153f803..3be9d5b7ced 100644 --- a/patching/src/test/java/org/jboss/as/patching/cli/CLIPatchInfoUtil.java +++ b/patching/src/test/java/org/jboss/as/patching/cli/CLIPatchInfoUtil.java @@ -26,6 +26,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -50,8 +51,8 @@ public class CLIPatchInfoUtil { public static void assertPatchInfo(byte[] info, String patchId, String link, boolean oneOff, String targetName, String targetVersion, String description) { try (final ByteArrayInputStream bis = new ByteArrayInputStream(info); - final InputStreamReader reader = new InputStreamReader(bis); - final BufferedReader buf = new BufferedReader(reader)){ + final InputStreamReader reader = new InputStreamReader(bis, StandardCharsets.UTF_8); + final BufferedReader buf = new BufferedReader(reader)){ assertPatchInfo(buf, patchId, link, oneOff, targetName, targetVersion, description); } catch (IOException e) { // @@ -78,7 +79,7 @@ public static void assertPatchInfo(byte[] info, String patchId, String link, boo String description, List> elements) { try (final ByteArrayInputStream bis = new ByteArrayInputStream(info); - final InputStreamReader reader = new InputStreamReader(bis); + final InputStreamReader reader = new InputStreamReader(bis, StandardCharsets.UTF_8); final BufferedReader buf = new BufferedReader(reader)){ assertPatchInfo(buf, patchId, link, oneOff, targetName, targetVersion, description, elements); if (buf.ready()) { @@ -133,7 +134,7 @@ public static void assertPatchInfo(BufferedReader buf, String patchId, String li public static Map parseTable(byte[] table) throws IOException { try (final ByteArrayInputStream bis = new ByteArrayInputStream(table); - final InputStreamReader reader = new InputStreamReader(bis); + final InputStreamReader reader = new InputStreamReader(bis, StandardCharsets.UTF_8); final BufferedReader buf = new BufferedReader(reader)) { return parseTable(buf); } diff --git a/patching/src/test/java/org/jboss/as/patching/cli/PatchInspectUnitTestCase.java b/patching/src/test/java/org/jboss/as/patching/cli/PatchInspectUnitTestCase.java index 2278ee99da9..ceec7a17d6d 100644 --- a/patching/src/test/java/org/jboss/as/patching/cli/PatchInspectUnitTestCase.java +++ b/patching/src/test/java/org/jboss/as/patching/cli/PatchInspectUnitTestCase.java @@ -43,6 +43,7 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -208,7 +209,7 @@ public void testMain() throws Exception { ctx.handle("patch inspect " + zippedBundle); ByteArrayInputStream bis = new ByteArrayInputStream(bytesOs.toByteArray()); - BufferedReader reader = new BufferedReader(new InputStreamReader(bis)); + BufferedReader reader = new BufferedReader(new InputStreamReader(bis, StandardCharsets.UTF_8)); try { assertTrue(reader.ready()); CLIPatchInfoUtil.assertPatchInfo(reader, patchID, "http://test.one", true, productConfig.getProductName(), @@ -225,7 +226,7 @@ public void testMain() throws Exception { ctx.handle("patch inspect " + zippedBundle + " --verbose"); bis = new ByteArrayInputStream(bytesOs.toByteArray()); - reader = new BufferedReader(new InputStreamReader(bis)); + reader = new BufferedReader(new InputStreamReader(bis, StandardCharsets.UTF_8)); try { assertTrue(reader.ready()); assertEquals("CONTENT OF " + zippedOneOff.getName() + ':', reader.readLine()); diff --git a/patching/src/test/java/org/jboss/as/patching/metadata/PatchXmlUnitTestCase.java b/patching/src/test/java/org/jboss/as/patching/metadata/PatchXmlUnitTestCase.java index 6217e0841d0..4e4d06fd4e7 100644 --- a/patching/src/test/java/org/jboss/as/patching/metadata/PatchXmlUnitTestCase.java +++ b/patching/src/test/java/org/jboss/as/patching/metadata/PatchXmlUnitTestCase.java @@ -29,6 +29,7 @@ import java.io.StringReader; import java.io.StringWriter; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.util.Scanner; import javax.xml.stream.XMLStreamException; @@ -82,7 +83,7 @@ public void testParseDuplicateElementPatchId() throws Exception { final StringBuilder buf = new StringBuilder(); BufferedReader reader = null; try { - reader = new BufferedReader(new InputStreamReader(is)); + reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)); String line = reader.readLine(); final String newLine = System.getProperty("line.separator"); while(line != null) { diff --git a/patching/src/test/java/org/jboss/as/patching/runner/RemoveModifiedFileTaskTestCase.java b/patching/src/test/java/org/jboss/as/patching/runner/RemoveModifiedFileTaskTestCase.java index 426a4b58195..0b17c90b542 100644 --- a/patching/src/test/java/org/jboss/as/patching/runner/RemoveModifiedFileTaskTestCase.java +++ b/patching/src/test/java/org/jboss/as/patching/runner/RemoveModifiedFileTaskTestCase.java @@ -37,6 +37,7 @@ import static org.junit.Assert.assertArrayEquals; import java.io.File; +import java.nio.charset.StandardCharsets; import org.jboss.as.patching.ContentConflictsException; import org.jboss.as.patching.metadata.ContentModification; @@ -66,10 +67,10 @@ public void setUp() throws Exception{ File binDir = mkdir(env.getInstalledImage().getJbossHome(), "bin"); String fileName = "standalone.sh"; removedFile = touch(binDir, fileName); - dump(removedFile, "modified script to run standalone AS7"); + dump(removedFile, "modified script to run standalone AS"); expectedModifiedHash = hashFile(removedFile); // let's simulate that the file has been modified by the users by using a hash that is not the file checksum - byte[] unmodifiedHash = randomString().getBytes(); + byte[] unmodifiedHash = randomString().getBytes(StandardCharsets.UTF_8); String patchID = randomString(); File patchDir = mkdir(tempDir, patchID); diff --git a/patching/src/test/java/org/jboss/as/patching/runner/TestUtils.java b/patching/src/test/java/org/jboss/as/patching/runner/TestUtils.java index 92e50fcb7f7..9aea71f76f9 100644 --- a/patching/src/test/java/org/jboss/as/patching/runner/TestUtils.java +++ b/patching/src/test/java/org/jboss/as/patching/runner/TestUtils.java @@ -43,10 +43,12 @@ import java.io.File; import java.io.FileOutputStream; -import java.io.FileWriter; import java.io.IOException; import java.io.OutputStream; +import java.io.Writer; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.List; import java.util.Properties; import java.util.jar.Attributes.Name; @@ -207,21 +209,15 @@ public static void createPatchXMLFile(File dir, Patch patch) throws Exception { } public static void createPatchXMLFile(File dir, Patch patch, boolean logContent) throws Exception { - File patchXMLfile = new File(dir, "patch.xml"); - patchXMLfile.createNewFile(); - FileOutputStream fos = new FileOutputStream(patchXMLfile); - try { + Path patchXMLfile = dir.toPath().resolve("patch.xml"); + try (Writer fos = Files.newBufferedWriter(patchXMLfile, StandardCharsets.UTF_8)){ PatchXml.marshal(fos, patch); - } finally { - safeClose(fos); } if(logContent) { - try (java.io.FileInputStream fis = new java.io.FileInputStream(new java.io.File(dir, "patch.xml"))){ - final byte[] bytes = new byte[fis.available()]; - fis.read(bytes); - System.out.println(new String(bytes)); - } + final byte[] bytes = Files.readAllBytes(dir.toPath().resolve("patch.xml")); + System.out.println(new String(bytes, StandardCharsets.UTF_8)); + } } @@ -267,12 +263,9 @@ public static File createInstalledImage(DirectoryStructure env, String identity, assertTrue("Failed to create product.conf", productConf.createNewFile()); Properties props = new Properties(); props.setProperty("slot", identity); - FileWriter writer = null; - try { - writer = new FileWriter(productConf); + + try (final Writer writer = Files.newBufferedWriter(productConf.toPath(), StandardCharsets.UTF_8)) { props.store(writer, null); - } finally { - StreamUtils.safeClose(writer); } // create the product module diff --git a/patching/src/test/java/org/jboss/as/patching/runner/UpdateModifiedFileTaskTestCase.java b/patching/src/test/java/org/jboss/as/patching/runner/UpdateModifiedFileTaskTestCase.java index 60494cda7db..12459cd2627 100644 --- a/patching/src/test/java/org/jboss/as/patching/runner/UpdateModifiedFileTaskTestCase.java +++ b/patching/src/test/java/org/jboss/as/patching/runner/UpdateModifiedFileTaskTestCase.java @@ -35,6 +35,7 @@ import static org.junit.Assert.assertArrayEquals; import java.io.File; +import java.nio.charset.StandardCharsets; import org.jboss.as.patching.ContentConflictsException; import org.jboss.as.patching.metadata.ContentModification; @@ -68,7 +69,7 @@ public void setUp() throws Exception{ dump(modifiedFile, "modified script to run standalone AS7"); expectedModifiedHash = hashFile(modifiedFile); // let's simulate that the file has been modified by the users by using a hash that is not the file checksum - byte[] unmodifiedHash = randomString().getBytes(); + byte[] unmodifiedHash = randomString().getBytes(StandardCharsets.UTF_8); // build a one-off patch for the base installation // with 1 updated file diff --git a/patching/src/test/java/org/jboss/as/patching/tests/MergingPatchMetadataTestCase.java b/patching/src/test/java/org/jboss/as/patching/tests/MergingPatchMetadataTestCase.java index 8fbba64d576..eb86c0b47d5 100644 --- a/patching/src/test/java/org/jboss/as/patching/tests/MergingPatchMetadataTestCase.java +++ b/patching/src/test/java/org/jboss/as/patching/tests/MergingPatchMetadataTestCase.java @@ -24,6 +24,7 @@ import static org.junit.Assert.assertEquals; +import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Arrays; @@ -66,7 +67,7 @@ public class MergingPatchMetadataTestCase { static byte[] digest(String str) { DIGEST.reset(); - return DIGEST.digest(str.getBytes()); + return DIGEST.digest(str.getBytes(StandardCharsets.UTF_8)); } @Test diff --git a/process-controller/src/main/java/org/jboss/as/process/ManagedProcess.java b/process-controller/src/main/java/org/jboss/as/process/ManagedProcess.java index 0c70129f08b..7251696a2dc 100644 --- a/process-controller/src/main/java/org/jboss/as/process/ManagedProcess.java +++ b/process-controller/src/main/java/org/jboss/as/process/ManagedProcess.java @@ -35,6 +35,7 @@ import java.io.OutputStreamWriter; import java.io.PrintStream; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -418,8 +419,8 @@ public void run() { final InputStream source = this.source; final String processName = ManagedProcess.this.processName; try { - final BufferedReader reader = new BufferedReader(new InputStreamReader(new BufferedInputStream(source))); - final OutputStreamWriter writer = new OutputStreamWriter(target); + final BufferedReader reader = new BufferedReader(new InputStreamReader(new BufferedInputStream(source), StandardCharsets.UTF_8)); + final OutputStreamWriter writer = new OutputStreamWriter(target, StandardCharsets.UTF_8); String s; String prevEscape = ""; while ((s = reader.readLine()) != null) { diff --git a/process-controller/src/main/java/org/jboss/as/process/ProcessUtils.java b/process-controller/src/main/java/org/jboss/as/process/ProcessUtils.java index 9ea7e8de0ca..aafe90706a6 100644 --- a/process-controller/src/main/java/org/jboss/as/process/ProcessUtils.java +++ b/process-controller/src/main/java/org/jboss/as/process/ProcessUtils.java @@ -7,6 +7,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import org.wildfly.security.manager.WildFlySecurityManager; @@ -91,7 +92,7 @@ private int resolveProcessId(final String processName) throws IOException { } final Process p = Runtime.getRuntime().exec(jpsCommand); final List processes = new ArrayList<>(); - final BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); + final BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream(), StandardCharsets.UTF_8)); try { String line; // See if the process contains "jboss-modules.jar" and "-D[Server:server-one]" diff --git a/process-controller/src/main/java/org/jboss/as/process/SynchronizedWriter.java b/process-controller/src/main/java/org/jboss/as/process/SynchronizedWriter.java index 8ac1b250269..d97ce8f04f4 100644 --- a/process-controller/src/main/java/org/jboss/as/process/SynchronizedWriter.java +++ b/process-controller/src/main/java/org/jboss/as/process/SynchronizedWriter.java @@ -26,6 +26,7 @@ import java.io.OutputStreamWriter; import java.io.PrintStream; import java.io.Writer; +import java.nio.charset.StandardCharsets; /** * @author David M. Lloyd @@ -36,7 +37,7 @@ final class SynchronizedWriter extends Writer { SynchronizedWriter(final PrintStream target) { super(target); - delegate = new OutputStreamWriter(target); + delegate = new OutputStreamWriter(target, StandardCharsets.UTF_8); } public void write(final int c) throws IOException { diff --git a/process-controller/src/test/java/org/jboss/as/process/protocol/ChunkyByteInputOutputTest.java b/process-controller/src/test/java/org/jboss/as/process/protocol/ChunkyByteInputOutputTest.java index b8c5a20db85..e5841d72c43 100644 --- a/process-controller/src/test/java/org/jboss/as/process/protocol/ChunkyByteInputOutputTest.java +++ b/process-controller/src/test/java/org/jboss/as/process/protocol/ChunkyByteInputOutputTest.java @@ -24,6 +24,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.nio.charset.StandardCharsets; import org.jboss.marshalling.ByteInput; import org.jboss.marshalling.ByteOutput; @@ -38,7 +39,7 @@ public class ChunkyByteInputOutputTest { @Test public void testEqualBuffer() throws Exception { - final byte[] content = "1234567890".getBytes(); + final byte[] content = "1234567890".getBytes(StandardCharsets.UTF_8); final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); final ByteOutput byteOutput = new ChunkyByteOutput(Marshalling.createByteOutput(byteArrayOutputStream), 10); @@ -60,7 +61,7 @@ public void testEqualBuffer() throws Exception { @Test public void testMultiChunk() throws Exception { - final byte[] content = "12345678901234567890123456789012345678901234567890".getBytes(); + final byte[] content = "12345678901234567890123456789012345678901234567890".getBytes(StandardCharsets.UTF_8); final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); final ByteOutput byteOutput = new ChunkyByteOutput(Marshalling.createByteOutput(byteArrayOutputStream), 10); @@ -82,7 +83,7 @@ public void testMultiChunk() throws Exception { @Test public void testRemainingBytes() throws Exception { - final byte[] content = "1234567890123456789012345678901234567890123".getBytes(); + final byte[] content = "1234567890123456789012345678901234567890123".getBytes(StandardCharsets.UTF_8); final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); final ByteOutput byteOutput = new ChunkyByteOutput(Marshalling.createByteOutput(byteArrayOutputStream), 10); @@ -104,7 +105,7 @@ public void testRemainingBytes() throws Exception { @Test public void testIncompleteRead() throws Exception { - final byte[] content = "1234567890123456789012345678901234567890123".getBytes(); + final byte[] content = "1234567890123456789012345678901234567890123".getBytes(StandardCharsets.UTF_8); final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); final ByteOutput byteOutput = new ChunkyByteOutput(Marshalling.createByteOutput(byteArrayOutputStream), 10); @@ -130,7 +131,7 @@ public void testIncompleteRead() throws Exception { @Test public void testOffsetRead() throws Exception { - final byte[] content = "1234567890123456789012345678901234567890123".getBytes(); + final byte[] content = "1234567890123456789012345678901234567890123".getBytes(StandardCharsets.UTF_8); final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); final ByteOutput byteOutput = new ChunkyByteOutput(Marshalling.createByteOutput(byteArrayOutputStream), 10); diff --git a/process-controller/src/test/java/org/jboss/as/process/support/LoggingTestRunner.java b/process-controller/src/test/java/org/jboss/as/process/support/LoggingTestRunner.java deleted file mode 100644 index e14ace14889..00000000000 --- a/process-controller/src/test/java/org/jboss/as/process/support/LoggingTestRunner.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * JBoss, Home of Professional Open Source. - * Copyright 2010, Red Hat, Inc., and individual contributors - * as indicated by the @author tags. See the copyright.txt file in the - * distribution for a full listing of individual contributors. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package org.jboss.as.process.support; - -import org.junit.runner.notification.RunNotifier; -import org.junit.runners.BlockJUnit4ClassRunner; -import org.junit.runners.model.FrameworkMethod; -import org.junit.runners.model.InitializationError; - -/** - * - * @author Kabir Khan - * @version $Revision: 1.1 $ - */ -public class LoggingTestRunner extends BlockJUnit4ClassRunner{ - - public LoggingTestRunner(Class klass) throws InitializationError { - super(klass); - } - - @Override - protected void runChild(FrameworkMethod method, RunNotifier notifier) { - System.err.println("\n===== Test " + getTestClass().getJavaClass().getSimpleName() + "." + testName(method) + " ==========="); - super.runChild(method, notifier); - } -} diff --git a/process-controller/src/test/java/org/jboss/as/process/support/TestFileUtils.java b/process-controller/src/test/java/org/jboss/as/process/support/TestFileUtils.java deleted file mode 100644 index 03d2ea2d4c3..00000000000 --- a/process-controller/src/test/java/org/jboss/as/process/support/TestFileUtils.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * JBoss, Home of Professional Open Source. - * Copyright 2006, Red Hat Middleware LLC, and individual contributors - * as indicated by the @author tags. See the copyright.txt file in the - * distribution for a full listing of individual contributors. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package org.jboss.as.process.support; - -import static org.junit.Assert.assertEquals; - -import java.io.BufferedReader; -import java.io.Closeable; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * Class to access the files output by the various processes. They will go in - * the target/process-files directory and will have the name of the process - * - * @author Kabir Khan - * @version $Revision: 1.1 $ - */ -public abstract class TestFileUtils { - private static final File DIR = new File(new File("target"), - "process-files"); - static { - // Check that target/process-files is a directory - if (DIR.exists() && !DIR.isDirectory()) - throw new IllegalStateException(DIR.getAbsolutePath() - + " exists and is not a directory"); - DIR.mkdir(); - } - - public static TestFile getOutputFile(String processName) { - return new TestFile(new File(DIR, processName)); - } - - public static void cleanFiles() { - for (File file : getOutputFiles()) { - if (file.isFile()) { - if (!file.delete()) - throw new IllegalStateException("Could not delete " + file); - } - } - } - - static File[] getOutputFiles() { - String[] list = DIR.list(); - List result = new ArrayList(); - - for (String name : list) { - File file = new File(DIR, name); - result.add(file); - } - return result.toArray(new File[result.size()]); - } - - public static int getNumberOutputFiles() { - return getOutputFiles().length; - } - - public static void assertNumberOutputFiles(int expected) { - File[] files = getOutputFiles(); - assertEquals(Arrays.toString(files), expected, files.length); - } - - public static void close(Closeable c) { - if (c != null) { - try { - c.close(); - } catch (Exception e) { - } - } - } - - public static class TestFile { - private File file; - - public TestFile(File file) { - this.file = file; - } - - public void writeToFile(String s) { - FileWriter writer = null; - try { - writer = new FileWriter(file, true); - writer.append(s); - } catch (IOException e) { - throw new RuntimeException(e); - } finally { - close(writer); - } - } - - public List readFile() { - List lines = new ArrayList(); - BufferedReader reader = null; - try { - reader = new BufferedReader(new FileReader(file)); - String line = reader.readLine(); - while (line != null) { - lines.add(line); - line = reader.readLine(); - } - } catch (IOException e) { - throw new RuntimeException(e); - } finally { - close(reader); - } - return lines; - } - - public void checkFile(String... expected) { - List lines = readFile(); - assertEquals(Arrays.toString(expected) + ":" + lines, + expected.length, lines.size()); - - for (int i = 0; i < expected.length; i++) { - assertEquals(expected[i], lines.get(i)); - } - - } - - public boolean exists() { - return file.exists(); - } - } - -} diff --git a/process-controller/src/test/java/org/jboss/as/process/support/TestProcessUtils.java b/process-controller/src/test/java/org/jboss/as/process/support/TestProcessUtils.java deleted file mode 100644 index 7c0b068a485..00000000000 --- a/process-controller/src/test/java/org/jboss/as/process/support/TestProcessUtils.java +++ /dev/null @@ -1,652 +0,0 @@ -/* - * JBoss, Home of Professional Open Source. - * Copyright 2006, Red Hat Middleware LLC, and individual contributors - * as indicated by the @author tags. See the copyright.txt file in the - * distribution for a full listing of individual contributors. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package org.jboss.as.process.support; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.PrintWriter; -import java.net.BindException; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.ServerSocket; -import java.net.Socket; -import java.net.SocketAddress; -import java.net.SocketException; -import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.TimeUnit; - -import org.jboss.as.process.CommandLineConstants; - -/** - * - * @author Kabir Khan - * @version $Revision: 1.1 $ - */ -public abstract class TestProcessUtils { - - private static final int DEFAULT_PORT = 12934; - private static final int PORT; - static { - String s = System.getenv().get("PM_TEST_LISTENER_PORT"); - PORT = s == null ? DEFAULT_PORT : Integer.valueOf(s); - } - - private static final int TIMEOUT_MILLISECONDS = 1000; - - static final Map COMMANDS; - static { - Map map = new HashMap(); - StartCommand start = new StartCommand(); - map.put(start.cmd(), start); - MessageCommand msg = new MessageCommand(); - map.put(msg.cmd(), msg); - StopCommand stop = new StopCommand(); - map.put(stop.cmd(), stop); - COMMANDS = Collections.unmodifiableMap(map); - } - - public static List createCommand(String processName, String classname, int pmPort) throws UnknownHostException { - return createCommand(processName, classname, pmPort, 0, false); - } - - public static List createCommand(String processName, String classname, int pmPort, - int debugPort, boolean suspend) throws UnknownHostException { - List cmd = new ArrayList(); - cmd.add(getJava()); - cmd.add("-cp"); - cmd.add(System.getProperty("java.class.path")); - - if (debugPort > 0) - cmd.add("-agentlib:jdwp=transport=dt_socket,address=" + debugPort - + ",server=y,suspend=" + (suspend ? "y" : "n")); - - cmd.add(classname); - cmd.add(processName); - - //Add the socket parameters - cmd.add(CommandLineConstants.PROCESS_CONTROLLER_BIND_PORT); - cmd.add(String.valueOf(pmPort)); - cmd.add(CommandLineConstants.PROCESS_CONTROLLER_BIND_ADDR); - cmd.add(InetAddress.getLocalHost().getHostAddress()); - - return cmd; - } - - public static TestStreamManager createStreamManager(TestProcessController controller) { - ServerSocketThread serverSocketThread = new ServerSocketThread( - controller); - serverSocketThread.start(); - serverSocketThread.waitForStart(); - return serverSocketThread; - } - - public static TestProcessSenderStream createProcessClient(String processName) { - return new ClientSocketWriter(processName); - } - - private static class ServerSocketThread extends Thread implements TestStreamManager { - TestProcessController controller; - ServerSocket server; - Set listenerThreads = new HashSet(); - CountDownLatch latch = new CountDownLatch(1); - Map listenerThreadsByProcessName = new HashMap(); - - Map startProcessLatches = new HashMap(); - Map stopProcessLatches = new HashMap(); - - ServerSocketThread(TestProcessController controller) { - super("Test Server Socket Thread"); - this.controller = controller; - try { - server = new ServerSocket(); - server.setReuseAddress(true); - SocketAddress addr = new InetSocketAddress(InetAddress.getLocalHost(), PORT); - System.err.println("*Test - " + this.getName() + " attempting to listen on " + PORT); - - //ServerSocket.close() does not seem to always free up the port. I don't really want - //to modify everything to pass ports through to the tests yet, so retry a few times - for (int i = 0 ; ; i++) { - try { - server.bind(addr, 5); - break; - } catch (BindException e) { - if (i == 5) - throw e; - Thread.sleep(100); - } - } - } catch (Exception e) { - throw new RuntimeException("Can't listen on port " + PORT, e); - } - } - - @Override - public void shutdown() { - System.err.println("*Test - " + this.getName() + " closing server"); - - closeServer(); - synchronized (this) { - for (ListenerSocketThread listener : listenerThreads) { - listener.shutdown(); - if (listener.getProcessName() != null) - controller.stopProcess(listener.getProcessName()); - } - - for (ListenerSocketThread listener : listenerThreadsByProcessName.values()) { - listener.shutdown(); - if (listener.getProcessName() != null) - controller.stopProcess(listener.getProcessName()); - } - listenerThreadsByProcessName.clear(); - } - } - - @Override - public TestProcessListenerStream getProcessListener(String name, long timeoutMillis) { - long cutoff = System.currentTimeMillis() + timeoutMillis; - - TestProcessListenerStream stream = null; - do { - synchronized (this) { - stream = listenerThreadsByProcessName.get(name); - } - if (stream == null) { - try { - Thread.sleep(50); - } catch (InterruptedException ignore) { - } - } - }while (stream == null && System.currentTimeMillis() < cutoff); - - return stream; - } - - @Override - public TestProcessListenerStream createProcessListener(String name) { - return createProcessListener(name, null); - } - - @Override - public TestProcessListenerStream createProcessListener(String name, Runnable preWait) { - CountDownLatch processLatch = null; - synchronized (this) { - ListenerSocketThread thread = listenerThreadsByProcessName - .get(name); - if (thread != null) - return thread; - - processLatch = new CountDownLatch(1); - startProcessLatches.put(name, processLatch); - } - - try { - System.err.println("*Test - Starting " + name + " " + processLatch); - controller.startProcess(name); - if (preWait != null) - preWait.run(); - processLatch.await(TIMEOUT_MILLISECONDS, TimeUnit.SECONDS); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - - System.err.println("*Test - Started " + name); - synchronized (this) { - ListenerSocketThread thread = listenerThreadsByProcessName - .get(name); - if (thread == null) - throw new IllegalStateException("No process called " + name); - return thread; - } - } - - - - public void detachProcessListener(String name) { - synchronized (this) { - listenerThreadsByProcessName.remove(name); - } - } - - void processStarted(String name, ListenerSocketThread thread) { - System.err.println("*Test - Start received for " + name + " " + startProcessLatches); - synchronized (this) { - countdownLatch(startProcessLatches, name); - listenerThreadsByProcessName.put(name, thread); - } - } - - @Override - public void stopProcessListener(String name) { - if (name == null) - throw new IllegalArgumentException("Null name"); - CountDownLatch processLatch = null; - - synchronized (this) { - ListenerSocketThread thread = null; - thread = listenerThreadsByProcessName - .get(name); - - if (thread == null) - return; - - processLatch = new CountDownLatch(1); - stopProcessLatches.put(name, processLatch); - System.err.println("*Test - Stopping " + name + " " - + stopProcessLatches); - controller.stopProcess(name); - System.err.println("*Test - Waiting for stop " + name); - } - - try { - processLatch.await(TIMEOUT_MILLISECONDS, TimeUnit.SECONDS); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - System.err.println("*Test - Stopped " + name); - } - - void processStopped(String name, ListenerSocketThread thread) { - System.err.println("*Test - Stop received for " + name + " " + stopProcessLatches); - synchronized (this) { - countdownLatch(stopProcessLatches, name); - listenerThreadsByProcessName.remove(name); - } - } - - void countdownLatch(Map latches, String processName) { - CountDownLatch processLatch = latches.remove(processName); - if (processLatch != null) { - processLatch.countDown(); - } - } - - void waitForStart() { - try { - latch.await(); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } - - @Override - public void run() { - try { - latch.countDown(); - System.err.println("*Test - Server listening on " + server.getLocalPort()); - while (true) { - ListenerSocketThread t = new ListenerSocketThread(this, - server.accept()); - t.start(); - synchronized (this) { - listenerThreads.add(t); - } - } - } catch (SocketException e) { - System.err.println("*Test - " + this.getName() + " server socket closed"); - } catch (Exception e) { - e.printStackTrace(); - } finally { - closeServer(); - } - } - - private synchronized void closeServer() { - try { - if (!server.isClosed()) - server.close(); - System.err.println("*Test - server socket closed " + server.isClosed() + " " + server.isClosed()); - } catch (IOException e) { - e.printStackTrace(); - } - } - - void removeThread(ListenerSocketThread listener) { - synchronized (this) { - listenerThreads.remove(listener); - } - } - } - - private static class ListenerSocketThread extends Thread implements TestProcessListenerStream { - volatile String processName; - final ServerSocketThread serverSocketThread; - final Socket socket; - final BlockingQueue messages = new LinkedBlockingQueue(); - - public ListenerSocketThread(ServerSocketThread serverSocketThread, - Socket socket) { - super("Test Listener Socket Thread"); - this.serverSocketThread = serverSocketThread; - this.socket = socket; - } - - public void exitProcess(int exitCode) throws IOException { - OutputStream out = new BufferedOutputStream(socket.getOutputStream()); - String cmd = "Exit" + exitCode + "\n"; - out.write(cmd.getBytes()); - out.flush(); - } - - public void shutdown() { - closeSocket(socket); - } - - @Override - public String getProcessName() { - return processName; - } - - @Override - public void run() { - try { - System.err.println("*Test - Listener started"); - BufferedReader in = new BufferedReader(new InputStreamReader( - socket.getInputStream())); - boolean done = false; - while (!done) { - String line = in.readLine(); - - System.err.println("*Test - " + processName + " listener got data " + line); - - if (line != null) - TestCommand.receive(this, line.trim()); - else - done = true; - } - } catch (SocketException e) { - System.err.println("*Test - " + this.getName() + " socket closed"); - } catch (Exception e) { - e.printStackTrace(); - } finally { - serverSocketThread.removeThread(this); - closeSocket(socket); - } - } - - void processStarted(String processName) { - // TODO Check we don't get started twice - this.processName = processName; - serverSocketThread.processStarted(processName, this); - } - - void processStopped(String processName) { - serverSocketThread.processStopped(processName, this); - } - - @Override - public String readMessage() { - return readMessage(TIMEOUT_MILLISECONDS); - } - - @Override - public String readMessage(long timeoutMs) { - try { - return messages.poll(timeoutMs, TimeUnit.MILLISECONDS); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } - - void messageReceived(String msg) { - messages.add(msg); - } - } - - public static class ClientSocketWriter implements TestProcessSenderStream { - final String processName; - final Socket socket; - final InputStream socketInput; - final PrintWriter socketOutput; - - public ClientSocketWriter(String processName) { - this.processName = processName; - try { - socket = new Socket(InetAddress.getLocalHost(), PORT); - socketOutput = new PrintWriter(socket.getOutputStream(), true); - socketOutput.println(new StartCommand(processName)); - socketInput = new BufferedInputStream(socket.getInputStream()); - } catch (Exception e) { - e.printStackTrace(System.err); - shutdown(); - throw new RuntimeException(e); - } - - } - - public synchronized void shutdown() { - if (socketOutput != null) { - try { - socketOutput.println(new StopCommand(processName).formatCommandForSend()); - socketOutput.close(); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - closeSocket(socket); - } - - public void writeData(String msg) { - try { - socketOutput.println(new MessageCommand(processName, msg).formatCommandForSend()); - } catch (Exception e) { - shutdown(); - } - } - - @Override - public InputStream getInput() { - return socketInput; - } - } - - static void closeSocket(Socket socket) { - try { - if (!socket.isClosed()) - socket.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - private static String getJava() { - return System.getProperty("java.home") + File.separator + "bin" - + File.separator + "java"; - } - - - private abstract static class TestCommand { - String processName; - - TestCommand() { - } - - TestCommand(String processName) { - this.processName = processName; - } - - static void receive(ListenerSocketThread listener, String cmdString) throws IOException { - String[] elements = cmdString.split(":"); - if (elements.length < 2) - throw new IllegalArgumentException("'" + cmdString - + "' could not be parsed into a command"); - - TestCommand cmd = COMMANDS.get(elements[0]); - if (cmd == null) - throw new IllegalArgumentException("'" + cmdString - + "' is not a known command: " + cmdString); - - elements = Arrays.copyOfRange(elements, 1, elements.length); - cmd.receive(listener, elements); - } - - abstract String cmd(); - - abstract void receive(ListenerSocketThread listener, String[] cmdData) throws IOException; - - public String formatCommandForSend() { - return cmd() + ":" + processName; - } - - @Override - public String toString() { - return cmd() + ":" + processName; - } - - } - - private static class StartCommand extends TestCommand { - StartCommand() { - } - - StartCommand(String processName) { - super(processName); - } - - @Override - String cmd() { - return "START"; - } - - @Override - void receive(ListenerSocketThread listener, String[] cmdData) { - if (cmdData.length != 1) - throw new IllegalArgumentException("Invalid START data " - + Arrays.toString(cmdData)); - listener.processStarted(cmdData[0]); - } - } - - private static class StopCommand extends TestCommand { - StopCommand() { - } - - StopCommand(String processName) { - super(processName); - } - - @Override - String cmd() { - return "STOP"; - } - - @Override - void receive(ListenerSocketThread listener, String[] cmdData) { - if (cmdData.length != 1) - throw new IllegalArgumentException("Invalid START data " - + Arrays.toString(cmdData)); - listener.processStopped(cmdData[0]); - } - } - - private static class MessageCommand extends TestCommand { - String command; - - MessageCommand() { - } - - public MessageCommand(String processName, String command) { - super(processName); - this.command = command; - } - - @Override - String cmd() { - return "MSG"; - } - - @Override - void receive(ListenerSocketThread listener, String[] cmdData) { - if (cmdData.length != 2) - throw new IllegalArgumentException("Invalid MSG data " - + Arrays.toString(cmdData)); - listener.messageReceived(cmdData[1]); - } - - @Override - public String formatCommandForSend() { - return super.toString() + ":" + command; - } - - @Override - public String toString() { - return cmd() + ":" + processName + ":" + command; - } - } - - public interface TestStreamManager { - void shutdown(); - - TestProcessListenerStream createProcessListener(String name, Runnable preWait); - - TestProcessListenerStream createProcessListener(String name); - - TestProcessListenerStream getProcessListener(String name, long timeoutMillis); - - void stopProcessListener(String name); - - void detachProcessListener(String name); - } - - public interface TestProcessListenerStream { - String getProcessName(); - - String readMessage(); - - String readMessage(long timeoutMs); - - void shutdown(); - - void exitProcess(int exitCode) throws IOException; - } - - public interface TestProcessSenderStream { - void shutdown(); - - void writeData(String msg); - - InputStream getInput(); - } - - public interface TestProcessController { - void startProcess(String processName); - - void stopProcess(String processName); - } - -} diff --git a/server/src/main/java/org/jboss/as/server/deployment/module/VFSResourceLoader.java b/server/src/main/java/org/jboss/as/server/deployment/module/VFSResourceLoader.java index 2ec14fd8f62..e60839e2904 100644 --- a/server/src/main/java/org/jboss/as/server/deployment/module/VFSResourceLoader.java +++ b/server/src/main/java/org/jboss/as/server/deployment/module/VFSResourceLoader.java @@ -22,6 +22,8 @@ package org.jboss.as.server.deployment.module; +import static java.security.AccessController.doPrivileged; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -29,6 +31,7 @@ import java.lang.reflect.UndeclaredThrowableException; import java.net.MalformedURLException; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.security.CodeSigner; import java.security.CodeSource; import java.security.PrivilegedAction; @@ -62,8 +65,6 @@ import org.jboss.vfs.util.FilterVirtualFileVisitor; import org.wildfly.security.manager.WildFlySecurityManager; -import static java.security.AccessController.doPrivileged; - /** * Resource loader capable of loading resources from VFS archives. * @@ -224,7 +225,7 @@ public Collection getPaths() { final VirtualFile indexFile = VFS.getChild(root.getPathName() + ".index"); if (indexFile.exists()) { try { - final BufferedReader r = new BufferedReader(new InputStreamReader(indexFile.openStream())); + final BufferedReader r = new BufferedReader(new InputStreamReader(indexFile.openStream(), StandardCharsets.UTF_8)); try { String s; while ((s = r.readLine()) != null) { diff --git a/server/src/main/java/org/jboss/as/server/deploymentoverlay/ReadContentHandler.java b/server/src/main/java/org/jboss/as/server/deploymentoverlay/ReadContentHandler.java index 0ac3ef9b3db..56261517760 100644 --- a/server/src/main/java/org/jboss/as/server/deploymentoverlay/ReadContentHandler.java +++ b/server/src/main/java/org/jboss/as/server/deploymentoverlay/ReadContentHandler.java @@ -27,6 +27,7 @@ import java.io.BufferedInputStream; import java.io.IOException; +import java.nio.charset.StandardCharsets; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; @@ -76,7 +77,7 @@ public static String readFile(VirtualFile file) throws IOException { StringBuilder builder = new StringBuilder(); int read = -1; while ((read = stream.read(buff)) != -1) { - builder.append(new String(buff, 0, read)); + builder.append(new String(buff, 0, read, StandardCharsets.UTF_8)); } return builder.toString(); } finally { diff --git a/server/src/main/java/org/jboss/as/server/operations/DumpServicesHandler.java b/server/src/main/java/org/jboss/as/server/operations/DumpServicesHandler.java index 9e5d3e17302..0ff671e60d6 100644 --- a/server/src/main/java/org/jboss/as/server/operations/DumpServicesHandler.java +++ b/server/src/main/java/org/jboss/as/server/operations/DumpServicesHandler.java @@ -24,6 +24,7 @@ import java.io.ByteArrayOutputStream; import java.io.PrintStream; +import java.nio.charset.StandardCharsets; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; @@ -74,7 +75,7 @@ public void execute(OperationContext context, ModelNode operation) throws Operat PrintStream print = new PrintStream(out); service.getServiceContainer().dumpServices(print); print.flush(); - context.getResult().set(new String(out.toByteArray())); + context.getResult().set(new String(out.toByteArray(), StandardCharsets.UTF_8)); } }, OperationContext.Stage.RUNTIME); } diff --git a/server/src/test/java/org/jboss/as/server/test/InterfaceManagementUnitTestCase.java b/server/src/test/java/org/jboss/as/server/test/InterfaceManagementUnitTestCase.java index 98deb7b98d9..016a3ce506c 100644 --- a/server/src/test/java/org/jboss/as/server/test/InterfaceManagementUnitTestCase.java +++ b/server/src/test/java/org/jboss/as/server/test/InterfaceManagementUnitTestCase.java @@ -29,6 +29,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -390,7 +391,7 @@ private class StringPersistenceResource implements PersistenceResource { @Override public void commit() { - StringConfigurationPersister.this.marshalled = new String(bytes); + StringConfigurationPersister.this.marshalled = new String(bytes, StandardCharsets.UTF_8); } @Override diff --git a/subsystem-test/framework/src/main/java/org/jboss/as/subsystem/test/SubsystemTestDelegate.java b/subsystem-test/framework/src/main/java/org/jboss/as/subsystem/test/SubsystemTestDelegate.java index 5b15597da0c..1708d36f8ea 100644 --- a/subsystem-test/framework/src/main/java/org/jboss/as/subsystem/test/SubsystemTestDelegate.java +++ b/subsystem-test/framework/src/main/java/org/jboss/as/subsystem/test/SubsystemTestDelegate.java @@ -35,6 +35,8 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -112,7 +114,6 @@ import org.junit.Assert; import org.junit.Assume; import org.wildfly.legacy.test.spi.Version; -import org.xnio.IoUtils; /** * @@ -466,14 +467,11 @@ File generateLegacySubsystemResourceRegistrationDmr(KernelServices kernelService PathAddress pathAddress = PathAddress.pathAddress(PathElement.pathElement(SUBSYSTEM, mainSubsystemName)); ModelNode desc = ((KernelServicesInternal)legacy).readFullModelDescription(pathAddress.toModelNode()); File dmrFile = getDmrFile(kernelServices, modelVersion); - PrintWriter pw = new PrintWriter(dmrFile); - try { + try (PrintWriter pw = new PrintWriter(Files.newBufferedWriter(dmrFile.toPath(), StandardCharsets.UTF_8))){ desc.writeString(pw, false); //Leave this println - it only gets executed when people generate the legacy dmr files, and is useful to know where it has been written. System.out.println("Legacy resource definition dmr written to: " + dmrFile.getAbsolutePath()); return dmrFile; - } finally { - IoUtils.safeClose(pw); } } diff --git a/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/DefaultInterfaceOveridingDomainTestCase.java b/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/DefaultInterfaceOveridingDomainTestCase.java index e6004d313b1..6d97d3f905d 100644 --- a/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/DefaultInterfaceOveridingDomainTestCase.java +++ b/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/DefaultInterfaceOveridingDomainTestCase.java @@ -28,10 +28,10 @@ import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SOCKET_BINDING_GROUP; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; -import java.io.PrintWriter; import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.Set; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.PathElement; @@ -116,11 +116,8 @@ private static WildFlyManagedConfiguration getHostConfiguration() throws Excepti hostConfig.setStartupTimeoutInSeconds(120); hostConfig.setBackupDC(true); File usersFile = new File(hostConfigDir, "mgmt-users.properties"); - FileOutputStream fos = new FileOutputStream(usersFile); - PrintWriter pw = new PrintWriter(fos); - pw.println("slave=" + new UsernamePasswordHashUtil().generateHashedHexURP("slave", "ManagementRealm", "slave_user_password".toCharArray())); - pw.close(); - fos.close(); + Files.write(usersFile.toPath(), + ("slave=" + new UsernamePasswordHashUtil().generateHashedHexURP("slave", "ManagementRealm", "slave_user_password".toCharArray())+"\n").getBytes(StandardCharsets.UTF_8)); return hostConfig; } diff --git a/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/DomainControllerMigrationTestCase.java b/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/DomainControllerMigrationTestCase.java index 5404ad9c9fd..e3f2c2d05a8 100644 --- a/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/DomainControllerMigrationTestCase.java +++ b/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/DomainControllerMigrationTestCase.java @@ -27,10 +27,10 @@ import java.io.File; import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; -import java.io.PrintWriter; import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.Set; import java.util.concurrent.TimeoutException; @@ -139,13 +139,8 @@ private static WildFlyManagedConfiguration getHostConfiguration(int host) throws hostConfig.setStartupTimeoutInSeconds(120); hostConfig.setBackupDC(true); File usersFile = new File(hostConfigDir, "mgmt-users.properties"); - FileOutputStream fos = new FileOutputStream(usersFile); - PrintWriter pw = new PrintWriter(fos); - pw.println("slave=" + new UsernamePasswordHashUtil().generateHashedHexURP("slave", "ManagementRealm", "slave_user_password".toCharArray())); - pw.close(); - fos.close(); - - + Files.write(usersFile.toPath(), + ("slave=" + new UsernamePasswordHashUtil().generateHashedHexURP("slave", "ManagementRealm", "slave_user_password".toCharArray())+"\n").getBytes(StandardCharsets.UTF_8)); return hostConfig; } diff --git a/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/SimpleDomainControllerMigrationTestCase.java b/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/SimpleDomainControllerMigrationTestCase.java index 45a02f444f8..5fcda2ef97b 100644 --- a/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/SimpleDomainControllerMigrationTestCase.java +++ b/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/SimpleDomainControllerMigrationTestCase.java @@ -27,10 +27,10 @@ import java.io.File; import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; -import java.io.PrintWriter; import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.Set; import java.util.concurrent.TimeoutException; @@ -137,13 +137,8 @@ private static WildFlyManagedConfiguration getHostConfiguration(int host) throws hostConfig.setStartupTimeoutInSeconds(120); hostConfig.setBackupDC(true); File usersFile = new File(hostConfigDir, "mgmt-users.properties"); - FileOutputStream fos = new FileOutputStream(usersFile); - PrintWriter pw = new PrintWriter(fos); - pw.println("slave=" + new UsernamePasswordHashUtil().generateHashedHexURP("slave", "ManagementRealm", "slave_user_password".toCharArray())); - pw.close(); - fos.close(); - - + Files.write(usersFile.toPath(), + ("slave=" + new UsernamePasswordHashUtil().generateHashedHexURP("slave", "ManagementRealm", "slave_user_password".toCharArray())+"\n").getBytes(StandardCharsets.UTF_8)); return hostConfig; } diff --git a/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/autoignore/TestClass.java b/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/autoignore/TestClass.java index 08837c719ef..a510f3e2bf4 100644 --- a/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/autoignore/TestClass.java +++ b/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/autoignore/TestClass.java @@ -22,15 +22,12 @@ package org.jboss.as.test.integration.domain.autoignore; -import java.io.BufferedOutputStream; -import java.io.BufferedWriter; import java.io.File; -import java.io.FileOutputStream; -import java.io.FileWriter; -import java.io.OutputStream; +import java.io.Writer; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; /** - * * @author Kabir Khan */ public class TestClass implements TestClassMBean { @@ -45,19 +42,9 @@ public void setPath(String path) { @Override public void start() { final File file = new File(path); - try { - final BufferedWriter writer = new BufferedWriter(new FileWriter(file)); - final OutputStream out = new BufferedOutputStream(new FileOutputStream(file)); - try { - System.out.println("--- writing"); - writer.write("Test\n"); - } finally { - try { - writer.close(); - System.out.println("--- written"); - } catch (Exception ignore) { - } - } + try (final Writer writer = Files.newBufferedWriter(file.toPath(), StandardCharsets.UTF_8)) { + System.out.println("--- writing"); + writer.write("Test\n"); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); diff --git a/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/slavereconnect/deployment/ServiceActivatorBaseDeployment.java b/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/slavereconnect/deployment/ServiceActivatorBaseDeployment.java index 7a318bea81b..a9491272d74 100644 --- a/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/slavereconnect/deployment/ServiceActivatorBaseDeployment.java +++ b/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/slavereconnect/deployment/ServiceActivatorBaseDeployment.java @@ -26,6 +26,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import org.jboss.msc.service.Service; import org.jboss.msc.service.ServiceActivator; @@ -65,7 +66,7 @@ public synchronized void start(StartContext context) throws StartException { InputStream in = getClass().getResourceAsStream("overlay"); if (in != null) { try { - try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))){ + try (BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))){ String s = reader.readLine(); System.setProperty(overridePropertyName, s); System.out.println("===> " + this.getClass() + " setting property " + overridePropertyName + "=" + s); diff --git a/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/suites/AuditLogTestCase.java b/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/suites/AuditLogTestCase.java index 228945889d8..6725ec6fe34 100644 --- a/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/suites/AuditLogTestCase.java +++ b/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/suites/AuditLogTestCase.java @@ -48,10 +48,10 @@ import java.io.BufferedReader; import java.io.File; -import java.io.FileReader; import java.io.IOException; import java.io.StringWriter; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; @@ -489,8 +489,8 @@ private void compareOpsWithoutHeaders(ModelNode expected, ModelNode actual, Stri private final Pattern DATE_STAMP_PATTERN = Pattern.compile("\\d\\d\\d\\d-\\d\\d-\\d\\d \\d\\d:\\d\\d:\\d\\d - \\{"); private List readFile(File file, int expectedRecords) throws IOException { - List list = new ArrayList(); - final BufferedReader reader = new BufferedReader(new FileReader(file)); + List list = new ArrayList<>(); + final BufferedReader reader = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8); try { StringWriter writer = null; String line = reader.readLine(); diff --git a/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/suites/ResponseStreamTestCase.java b/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/suites/ResponseStreamTestCase.java index e8324287ef7..73cbf85d49b 100644 --- a/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/suites/ResponseStreamTestCase.java +++ b/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/suites/ResponseStreamTestCase.java @@ -43,6 +43,7 @@ import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.util.List; import org.apache.http.HttpEntity; @@ -513,7 +514,7 @@ private void processResponseStream(OperationResponse response, String streamUUID private void readLogStream(InputStream stream, boolean forServer, boolean forMaster) throws IOException { - LineNumberReader reader = new LineNumberReader(new InputStreamReader(stream)); + LineNumberReader reader = new LineNumberReader(new InputStreamReader(stream, StandardCharsets.UTF_8)); String expected = LogStreamExtension.getLogMessage(logMessageContent); boolean readRegisteredServer = false; diff --git a/testsuite/domain/src/test/java/org/jboss/as/test/integration/respawn/RespawnHttpTestCase.java b/testsuite/domain/src/test/java/org/jboss/as/test/integration/respawn/RespawnHttpTestCase.java index c16cce268a1..9543b0b8096 100644 --- a/testsuite/domain/src/test/java/org/jboss/as/test/integration/respawn/RespawnHttpTestCase.java +++ b/testsuite/domain/src/test/java/org/jboss/as/test/integration/respawn/RespawnHttpTestCase.java @@ -21,19 +21,29 @@ */ package org.jboss.as.test.integration.respawn; -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.HOST; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.MASTER; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OUTCOME; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.READ_RESOURCE_OPERATION; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RESTART; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RESULT; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RUNNING_SERVER; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SERVER_CONFIG; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SHUTDOWN; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUCCESS; +import static org.jboss.as.test.integration.domain.management.util.Authentication.getCallbackHandler; + import java.io.BufferedReader; import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; -import java.io.InputStream; import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.PrintWriter; import java.net.URISyntaxException; import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.Arrays; @@ -42,7 +52,6 @@ import java.util.List; import java.util.Set; -import org.junit.Assert; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; @@ -54,26 +63,12 @@ import org.jboss.dmr.ModelNode; import org.jboss.logging.Logger; import org.junit.AfterClass; +import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import org.wildfly.security.sasl.util.UsernamePasswordHashUtil; import org.xnio.IoUtils; -import static org.jboss.as.test.integration.domain.management.util.Authentication.getCallbackHandler; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.HOST; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.MASTER; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OUTCOME; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.READ_RESOURCE_OPERATION; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RESTART; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RESULT; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RUNNING_SERVER; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SERVER_CONFIG; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SHUTDOWN; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUCCESS; - /** * RespawnTestCase @@ -139,11 +134,8 @@ public static void createProcessController() throws IOException, URISyntaxExcept // No point backing up the file in a test scenario, just write what we need. File usersFile = new File(domainConfigDir, "mgmt-users.properties"); - FileOutputStream fos = new FileOutputStream(usersFile); - PrintWriter pw = new PrintWriter(fos); - pw.println("slave=" + new UsernamePasswordHashUtil().generateHashedHexURP("slave", "ManagementRealm", "slave_user_password".toCharArray())); - pw.close(); - fos.close(); + Files.write(usersFile.toPath(), + ("slave=" + new UsernamePasswordHashUtil().generateHashedHexURP("slave", "ManagementRealm", "slave_user_password".toCharArray())+"\n").getBytes(StandardCharsets.UTF_8)); String localRepo = System.getProperty("settings.localRepository"); @@ -345,15 +337,7 @@ public void testHCReloadAbortPreservesServers() throws Exception { try { // Replace host.xml with an invalid doc File toBreak = new File(domainConfigDir, hostXml.getName()); - PrintWriter pw = null; - try { - pw = new PrintWriter(toBreak); - pw.println(""); - } finally { - if (pw != null) { - pw.close(); - } - } + Files.write(toBreak.toPath(), "\n".getBytes(StandardCharsets.UTF_8)); // Execute reload w/ restart-servers=false, admin-only=false // The reload should abort the HC due to bad xml @@ -549,21 +533,7 @@ private static void copyFile(File file, File directory) throws IOException{ throw new IllegalStateException("Could not delete file " + tgt.getAbsolutePath()); } } - final InputStream in = new BufferedInputStream(new FileInputStream(file)); - try { - final OutputStream out = new BufferedOutputStream(new FileOutputStream(tgt)); - try { - int i = in.read(); - while (i != -1) { - out.write(i); - i = in.read(); - } - } finally { - IoUtils.safeClose(out); - } - } finally { - IoUtils.safeClose(in); - } + Files.copy(file.toPath(), tgt.toPath()); } static TestControllerClient getControllerClient() throws IOException { @@ -621,7 +591,7 @@ List listProcesses() { } List processes = new ArrayList(); - BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); + BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream(), StandardCharsets.UTF_8)); try { String line; while ((line = input.readLine()) != null) { diff --git a/testsuite/domain/src/test/java/org/jboss/as/test/integration/respawn/RespawnTestCase.java b/testsuite/domain/src/test/java/org/jboss/as/test/integration/respawn/RespawnTestCase.java index 524a213f733..ce3b457da4c 100644 --- a/testsuite/domain/src/test/java/org/jboss/as/test/integration/respawn/RespawnTestCase.java +++ b/testsuite/domain/src/test/java/org/jboss/as/test/integration/respawn/RespawnTestCase.java @@ -21,6 +21,21 @@ */ package org.jboss.as.test.integration.respawn; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.HOST; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.MASTER; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OUTCOME; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.READ_RESOURCE_OPERATION; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RESTART; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RESULT; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RUNNING_SERVER; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SERVER_CONFIG; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SHUTDOWN; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUCCESS; +import static org.jboss.as.test.integration.domain.management.util.Authentication.getCallbackHandler; + import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.BufferedReader; @@ -31,9 +46,10 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; -import java.io.PrintWriter; import java.net.URISyntaxException; import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.Arrays; @@ -42,38 +58,22 @@ import java.util.List; import java.util.Set; -import org.junit.Assert; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.process.Main; import org.jboss.as.process.ProcessController; -import org.jboss.as.protocol.StreamUtils; import org.jboss.as.test.integration.domain.management.util.DomainTestSupport; import org.jboss.as.test.shared.TestSuiteEnvironment; import org.jboss.dmr.ModelNode; import org.jboss.logging.Logger; import org.junit.AfterClass; +import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import org.wildfly.security.sasl.util.UsernamePasswordHashUtil; import org.xnio.IoUtils; -import static org.jboss.as.test.integration.domain.management.util.Authentication.getCallbackHandler; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.HOST; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.MASTER; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OUTCOME; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.READ_RESOURCE_OPERATION; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RESTART; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RESULT; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RUNNING_SERVER; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SERVER_CONFIG; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SHUTDOWN; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUCCESS; - /** * RespawnTestCase * @@ -138,12 +138,9 @@ public static void createProcessController() throws IOException, URISyntaxExcept // No point backing up the file in a test scenario, just write what we need. File usersFile = new File(domainConfigDir, "mgmt-users.properties"); - FileOutputStream fos = new FileOutputStream(usersFile); - PrintWriter pw = new PrintWriter(fos); - pw.println("slave=" + new UsernamePasswordHashUtil().generateHashedHexURP("slave", "ManagementRealm", "slave_user_password".toCharArray())); - pw.close(); - fos.close(); - + Files.write(usersFile.toPath(), + ("slave=" + new UsernamePasswordHashUtil().generateHashedHexURP("slave", "ManagementRealm", "slave_user_password".toCharArray())+"\n") + .getBytes(StandardCharsets.UTF_8)); String localRepo = System.getProperty("settings.localRepository"); final String address = System.getProperty("jboss.test.host.master.address", "127.0.0.1"); @@ -346,15 +343,7 @@ public void testHCReloadAbortPreservesServers() throws Exception { try { // Replace host.xml with an invalid doc File toBreak = new File(domainConfigDir, hostXml.getName()); - PrintWriter pw = null; - try { - pw = new PrintWriter(toBreak); - pw.println(""); - } finally { - if (pw != null) { - pw.close(); - } - } + Files.write(toBreak.toPath(), "\n".getBytes(StandardCharsets.UTF_8)); // Execute reload w/ restart-servers=false, admin-only=false // The reload should abort the HC due to bad xml @@ -626,7 +615,7 @@ List listProcesses() { try { String line; while ((line = input.readLine()) != null) { - if (line.contains("jboss-modules.jar")){ + if (line.contains("jboss-modules.jar")) { processes.add(line); } @@ -634,7 +623,7 @@ List listProcesses() { } catch (IOException e) { throw new RuntimeException(e); } finally { - StreamUtils.safeClose(input); + IoUtils.safeClose(input); } return processes; } diff --git a/testsuite/manualmode/src/test/java/org/jboss/as/test/manualmode/auditlog/AuditLogFieldsOfLogTestCase.java b/testsuite/manualmode/src/test/java/org/jboss/as/test/manualmode/auditlog/AuditLogFieldsOfLogTestCase.java index 011a02200c9..cb4d10cfb04 100644 --- a/testsuite/manualmode/src/test/java/org/jboss/as/test/manualmode/auditlog/AuditLogFieldsOfLogTestCase.java +++ b/testsuite/manualmode/src/test/java/org/jboss/as/test/manualmode/auditlog/AuditLogFieldsOfLogTestCase.java @@ -29,9 +29,10 @@ import java.io.BufferedReader; import java.io.File; -import java.io.FileReader; import java.io.IOException; import java.io.StringWriter; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.ArrayList; import java.util.List; import java.util.concurrent.BlockingQueue; @@ -209,8 +210,8 @@ public void afterTest() throws Exception { } protected List readFile(File file, int expectedRecords) throws IOException { - List list = new ArrayList(); - final BufferedReader reader = new BufferedReader(new FileReader(file)); + List list = new ArrayList<>(); + final BufferedReader reader = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8); try { StringWriter writer = null; String line = reader.readLine(); diff --git a/testsuite/manualmode/src/test/java/org/jboss/as/test/manualmode/auditlog/JmxAuditLogFieldsOfLogTestCase.java b/testsuite/manualmode/src/test/java/org/jboss/as/test/manualmode/auditlog/JmxAuditLogFieldsOfLogTestCase.java index 830483ba45b..bf805c2b391 100644 --- a/testsuite/manualmode/src/test/java/org/jboss/as/test/manualmode/auditlog/JmxAuditLogFieldsOfLogTestCase.java +++ b/testsuite/manualmode/src/test/java/org/jboss/as/test/manualmode/auditlog/JmxAuditLogFieldsOfLogTestCase.java @@ -13,9 +13,10 @@ import java.io.BufferedReader; import java.io.File; -import java.io.FileReader; import java.io.IOException; import java.io.StringWriter; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; @@ -184,7 +185,7 @@ private MBeanServerConnection setupAndGetConnection() throws Exception { protected List readFile(File file, int expectedRecords) throws IOException { List list = new ArrayList(); - final BufferedReader reader = new BufferedReader(new FileReader(file)); + final BufferedReader reader = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8); try { StringWriter writer = null; String line = reader.readLine(); diff --git a/testsuite/manualmode/src/test/java/org/jboss/as/test/manualmode/management/cli/CLIEmbedServerTestCase.java b/testsuite/manualmode/src/test/java/org/jboss/as/test/manualmode/management/cli/CLIEmbedServerTestCase.java index e7c8d14af2d..4bc70ef7b10 100644 --- a/testsuite/manualmode/src/test/java/org/jboss/as/test/manualmode/management/cli/CLIEmbedServerTestCase.java +++ b/testsuite/manualmode/src/test/java/org/jboss/as/test/manualmode/management/cli/CLIEmbedServerTestCase.java @@ -47,6 +47,7 @@ import java.io.InputStream; import java.io.PrintStream; import java.io.StringReader; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.StandardCopyOption; import java.util.ArrayList; @@ -577,7 +578,7 @@ private void checkNoLogging(String line) throws IOException { private String readLogOut() { if (logOut.size() > 0) { - String output = new String(logOut.toByteArray()).trim(); + String output = new String(logOut.toByteArray(), StandardCharsets.UTF_8).trim(); logOut.reset(); return output; } diff --git a/testsuite/manualmode/src/test/java/org/jboss/as/test/manualmode/vault/TestVaultSession.java b/testsuite/manualmode/src/test/java/org/jboss/as/test/manualmode/vault/TestVaultSession.java index e9b14359f0f..9ae46efa5af 100644 --- a/testsuite/manualmode/src/test/java/org/jboss/as/test/manualmode/vault/TestVaultSession.java +++ b/testsuite/manualmode/src/test/java/org/jboss/as/test/manualmode/vault/TestVaultSession.java @@ -19,6 +19,7 @@ package org.jboss.as.test.manualmode.vault; import java.io.File; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; import javax.crypto.SecretKey; @@ -135,11 +136,11 @@ private String computeMaskedPassword() throws Exception { SecretKeyFactory factory = SecretKeyFactory.getInstance(VAULT_ENC_ALGORITHM); char[] password = "somearbitrarycrazystringthatdoesnotmatter".toCharArray(); - PBEParameterSpec cipherSpec = new PBEParameterSpec(salt.getBytes(), iterationCount); + PBEParameterSpec cipherSpec = new PBEParameterSpec(salt.getBytes(StandardCharsets.UTF_8), iterationCount); PBEKeySpec keySpec = new PBEKeySpec(password); SecretKey cipherKey = factory.generateSecret(keySpec); - String maskedPass = PBEUtils.encode64(keystorePassword.getBytes(), VAULT_ENC_ALGORITHM, cipherKey, cipherSpec); + String maskedPass = PBEUtils.encode64(keystorePassword.getBytes(StandardCharsets.UTF_8), VAULT_ENC_ALGORITHM, cipherKey, cipherSpec); return PicketBoxSecurityVault.PASS_MASK_PREFIX + maskedPass; } diff --git a/testsuite/patching/src/test/java/org/jboss/as/test/patching/AgeOutHistoryUnitTestCase.java b/testsuite/patching/src/test/java/org/jboss/as/test/patching/AgeOutHistoryUnitTestCase.java index 53e0109a398..9b4b2573121 100644 --- a/testsuite/patching/src/test/java/org/jboss/as/test/patching/AgeOutHistoryUnitTestCase.java +++ b/testsuite/patching/src/test/java/org/jboss/as/test/patching/AgeOutHistoryUnitTestCase.java @@ -34,6 +34,7 @@ import java.io.File; import java.io.IOException; import java.net.UnknownHostException; +import java.nio.charset.StandardCharsets; import java.util.List; import org.jboss.as.controller.client.ModelControllerClient; @@ -101,7 +102,7 @@ public void testUnpatched() throws Exception { public void testOneCP() throws Exception { Module module = new Module.Builder("module-test"). - miscFile(new ResourceItem("resource-test", ("module resource").getBytes())). + miscFile(new ResourceItem("resource-test", ("module resource").getBytes(StandardCharsets.UTF_8))). build(); File moduleDir = module.writeToDisk(new File(MODULES_PATH)); @@ -123,7 +124,7 @@ public void testOneCP() throws Exception { public void testOneOffsOnly() throws Exception { Module module = new Module.Builder("module-test"). - miscFile(new ResourceItem("resource-test", ("module resource").getBytes())). + miscFile(new ResourceItem("resource-test", ("module resource").getBytes(StandardCharsets.UTF_8))). build(); File moduleDir = module.writeToDisk(new File(MODULES_PATH)); @@ -146,7 +147,7 @@ public void testOneOffsOnly() throws Exception { public void testCPWithOneOffs() throws Exception { Module module = new Module.Builder("module-test"). - miscFile(new ResourceItem("resource-test", ("module resource").getBytes())). + miscFile(new ResourceItem("resource-test", ("module resource").getBytes(StandardCharsets.UTF_8))). build(); File moduleDir = module.writeToDisk(new File(MODULES_PATH)); @@ -170,7 +171,7 @@ public void testCPWithOneOffs() throws Exception { public void testCPBeforeCPWithOneOffs() throws Exception { Module module = new Module.Builder("module-test"). - miscFile(new ResourceItem("resource-test", ("module resource").getBytes())). + miscFile(new ResourceItem("resource-test", ("module resource").getBytes(StandardCharsets.UTF_8))). build(); File moduleDir = module.writeToDisk(new File(MODULES_PATH)); @@ -200,7 +201,7 @@ public void testCPBeforeCPWithOneOffs() throws Exception { public void testCPWithOneOffsBeforeCPWithOneOffs() throws Exception { Module module = new Module.Builder("module-test"). - miscFile(new ResourceItem("resource-test", ("module resource").getBytes())). + miscFile(new ResourceItem("resource-test", ("module resource").getBytes(StandardCharsets.UTF_8))). build(); File moduleDir = module.writeToDisk(new File(MODULES_PATH)); @@ -292,7 +293,7 @@ protected byte[] applyPatch(String patchID, byte[] targetHash, boolean cp) throw File patchDir = mkdir(tempDir, patchID); Module module = new Module.Builder(moduleName). - miscFile(new ResourceItem("resource-test", ("resource patch " + patchID).getBytes())). + miscFile(new ResourceItem("resource-test", ("resource patch " + patchID).getBytes(StandardCharsets.UTF_8))). build(); // create the patch with the updated module diff --git a/testsuite/patching/src/test/java/org/jboss/as/test/patching/BasicOneOffPatchingScenariosTestCase.java b/testsuite/patching/src/test/java/org/jboss/as/test/patching/BasicOneOffPatchingScenariosTestCase.java index 935c229440e..4cd39ea1141 100644 --- a/testsuite/patching/src/test/java/org/jboss/as/test/patching/BasicOneOffPatchingScenariosTestCase.java +++ b/testsuite/patching/src/test/java/org/jboss/as/test/patching/BasicOneOffPatchingScenariosTestCase.java @@ -38,6 +38,7 @@ import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; @@ -961,8 +962,8 @@ public void testOneOffPatchAddingAModule() throws Exception { final String moduleName = "org.wildfly.test." + randomString(); final String modulePath = PATCHES_PATH + FILE_SEPARATOR + layerPatchID + FILE_SEPARATOR + moduleName.replace(".", FILE_SEPARATOR) + FILE_SEPARATOR + "main"; - final ResourceItem resourceItem1 = new ResourceItem("testFile1", "content1".getBytes()); - final ResourceItem resourceItem2 = new ResourceItem("testFile2", "content2".getBytes()); + final ResourceItem resourceItem1 = new ResourceItem("testFile1", "content1".getBytes(StandardCharsets.UTF_8)); + final ResourceItem resourceItem2 = new ResourceItem("testFile2", "content2".getBytes(StandardCharsets.UTF_8)); Module newModule = new Module.Builder(moduleName) .miscFile(resourceItem1) @@ -1084,8 +1085,8 @@ public void testOneOffPatchAddingMultipleModules() throws Exception { final String moduleName2 = "org.wildfly.test." + randomString(); final String modulePath2 = PATCHES_PATH + FILE_SEPARATOR + layerPatchID + FILE_SEPARATOR + moduleName2.replace(".", FILE_SEPARATOR) + FILE_SEPARATOR + "main"; - final ResourceItem resourceItem1 = new ResourceItem("testFile1", "content1".getBytes()); - final ResourceItem resourceItem2 = new ResourceItem("testFile2", "content2".getBytes()); + final ResourceItem resourceItem1 = new ResourceItem("testFile1", "content1".getBytes(StandardCharsets.UTF_8)); + final ResourceItem resourceItem2 = new ResourceItem("testFile2", "content2".getBytes(StandardCharsets.UTF_8)); Module newModule1 = new Module.Builder(moduleName1) .miscFile(resourceItem1) @@ -1205,7 +1206,7 @@ public void testModifyAModule() throws Exception { File patchDir = mkdir(tempDir, patchID); Module updatedModule = new Module.Builder(moduleName) - .miscFile(new ResourceItem("res1", "new resource in the module".getBytes())) + .miscFile(new ResourceItem("res1", "new resource in the module".getBytes(StandardCharsets.UTF_8))) .build(); // Also see if we can update jboss-modules diff --git a/testsuite/patching/src/test/java/org/jboss/as/test/patching/CPRollingbackOneOffTestCase.java b/testsuite/patching/src/test/java/org/jboss/as/test/patching/CPRollingbackOneOffTestCase.java index 4b591ca3d18..4e7f5d64436 100644 --- a/testsuite/patching/src/test/java/org/jboss/as/test/patching/CPRollingbackOneOffTestCase.java +++ b/testsuite/patching/src/test/java/org/jboss/as/test/patching/CPRollingbackOneOffTestCase.java @@ -36,6 +36,7 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; +import java.nio.charset.StandardCharsets; import org.jboss.as.cli.CommandContext; import org.jboss.as.cli.CommandLineException; @@ -148,18 +149,18 @@ public void testOneOffCP() throws Exception { String moduleAName = "org.a.module-a"; Module moduleA = new Module.Builder(moduleAName) .resourceRoot(new ResourceItem(jarA.getName(), jarABytes)) - .miscFile(new ResourceItem("resource-a", "resource a in the module".getBytes())) + .miscFile(new ResourceItem("resource-a", "resource a in the module".getBytes(StandardCharsets.UTF_8))) .build(); File moduleADir = moduleA.writeToDisk(new File(MODULES_PATH)); String moduleBName = "org.b.module-b"; Module moduleB = new Module.Builder(moduleBName) .resourceRoot(new ResourceItem(jarB.getName(), jarBBytes)) - .miscFile(new ResourceItem("resource-b", "resource b in the module".getBytes())) + .miscFile(new ResourceItem("resource-b", "resource b in the module".getBytes(StandardCharsets.UTF_8))) .build(); File moduleBDir = moduleB.writeToDisk(new File(MODULES_PATH)); - moduleA = new Module.Builder(moduleAName).miscFile(new ResourceItem("resource-a", "resource a one-off".getBytes())).build(); + moduleA = new Module.Builder(moduleAName).miscFile(new ResourceItem("resource-a", "resource a one-off".getBytes(StandardCharsets.UTF_8))).build(); // create the patch with the updated module ContentModification moduleAModified = ContentModificationUtils.modifyModule(patchDir, patchElement1Id, HashUtils.hashFile(moduleADir), moduleA); @@ -187,7 +188,7 @@ public void testOneOffCP() throws Exception { final String patchElement2Id = randomString(); patchDir = mkdir(tempDir, patchID); - moduleB = new Module.Builder(moduleBName).miscFile(new ResourceItem("resource-b", "resource b cp".getBytes())).build(); + moduleB = new Module.Builder(moduleBName).miscFile(new ResourceItem("resource-b", "resource b cp".getBytes(StandardCharsets.UTF_8))).build(); // create the patch with the updated module ContentModification moduleBModified = ContentModificationUtils.modifyModule(patchDir, patchElement2Id, HashUtils.hashFile(moduleBDir), moduleB); @@ -237,17 +238,17 @@ public void testCPOneOffCP() throws Exception { String moduleAName = "org.a.module-a"; Module moduleA = new Module.Builder(moduleAName) .resourceRoot(new ResourceItem(jarA.getName(), jarABytes)) - .miscFile(new ResourceItem("resource-a", "resource a in the module".getBytes())) + .miscFile(new ResourceItem("resource-a", "resource a in the module".getBytes(StandardCharsets.UTF_8))) .build(); File moduleADir = moduleA.writeToDisk(new File(MODULES_PATH)); String moduleBName = "org.b.module-b"; Module moduleB = new Module.Builder(moduleBName) .resourceRoot(new ResourceItem(jarB.getName(), jarBBytes)) - .miscFile(new ResourceItem("resource-b", "resource b in the module".getBytes())) + .miscFile(new ResourceItem("resource-b", "resource b in the module".getBytes(StandardCharsets.UTF_8))) .build(); File moduleBDir = moduleB.writeToDisk(new File(MODULES_PATH)); - moduleA = new Module.Builder(moduleAName).miscFile(new ResourceItem("resource-a", "resource cp1".getBytes())).build(); + moduleA = new Module.Builder(moduleAName).miscFile(new ResourceItem("resource-a", "resource cp1".getBytes(StandardCharsets.UTF_8))).build(); // create the patch with the updated module ContentModification moduleAModified = ContentModificationUtils.modifyModule(patchDir, patchElement1Id, HashUtils.hashFile(moduleADir), moduleA); @@ -275,7 +276,7 @@ public void testCPOneOffCP() throws Exception { final String patchElement2Id = randomString(); patchDir = mkdir(tempDir, patchID); - moduleA = new Module.Builder(moduleAName).miscFile(new ResourceItem("resource-a", "resource oneoff1".getBytes())).build(); + moduleA = new Module.Builder(moduleAName).miscFile(new ResourceItem("resource-a", "resource oneoff1".getBytes(StandardCharsets.UTF_8))).build(); // create the patch with the updated module moduleAModified = ContentModificationUtils.modifyModule(patchDir, patchElement2Id, moduleAModified.getItem().getContentHash(), moduleA); @@ -301,7 +302,7 @@ public void testCPOneOffCP() throws Exception { final String patchElement3Id = randomString(); patchDir = mkdir(tempDir, patchID); - moduleB = new Module.Builder(moduleBName).miscFile(new ResourceItem("resource-b", "resource b cp".getBytes())).build(); + moduleB = new Module.Builder(moduleBName).miscFile(new ResourceItem("resource-b", "resource b cp".getBytes(StandardCharsets.UTF_8))).build(); // create the patch with the updated module ContentModification moduleBModified = ContentModificationUtils.modifyModule(patchDir, patchElement3Id, HashUtils.hashFile(moduleBDir), moduleB); @@ -356,11 +357,11 @@ public void testCPOneOffCPOneOff() throws Exception { String moduleAName = "org.a.module-a"; Module moduleA = new Module.Builder(moduleAName) .resourceRoot(new ResourceItem(jarA.getName(), jarABytes)) - .miscFile(new ResourceItem("resource-a", "resource a in the module".getBytes())) + .miscFile(new ResourceItem("resource-a", "resource a in the module".getBytes(StandardCharsets.UTF_8))) .build(); File moduleADir = moduleA.writeToDisk(new File(MODULES_PATH)); - moduleA = new Module.Builder(moduleAName).miscFile(new ResourceItem("resource-a", "resource cp1".getBytes())).build(); + moduleA = new Module.Builder(moduleAName).miscFile(new ResourceItem("resource-a", "resource cp1".getBytes(StandardCharsets.UTF_8))).build(); // create the patch with the updated module ContentModification moduleAModified = ContentModificationUtils.modifyModule(patchDir, patchElement1Id, HashUtils.hashFile(moduleADir), moduleA); @@ -388,7 +389,7 @@ public void testCPOneOffCPOneOff() throws Exception { final String patchElement2Id = randomString(); patchDir = mkdir(tempDir, patchID); - moduleA = new Module.Builder(moduleAName).miscFile(new ResourceItem("resource-a", "resource oneoff1".getBytes())).build(); + moduleA = new Module.Builder(moduleAName).miscFile(new ResourceItem("resource-a", "resource oneoff1".getBytes(StandardCharsets.UTF_8))).build(); // create the patch with the updated module moduleAModified = ContentModificationUtils.modifyModule(patchDir, patchElement2Id, moduleAModified.getItem().getContentHash(), moduleA); @@ -414,7 +415,7 @@ public void testCPOneOffCPOneOff() throws Exception { final String patchElement3Id = randomString(); patchDir = mkdir(tempDir, patchID); - moduleA = new Module.Builder(moduleAName).miscFile(new ResourceItem("resource-a", "resource oneoff1".getBytes())).build(); + moduleA = new Module.Builder(moduleAName).miscFile(new ResourceItem("resource-a", "resource oneoff1".getBytes(StandardCharsets.UTF_8))).build(); // create the patch with the updated module moduleAModified = ContentModificationUtils.modifyModule(patchDir, patchElement3Id, moduleAModified.getItem().getContentHash(), moduleA); @@ -439,7 +440,7 @@ public void testCPOneOffCPOneOff() throws Exception { final String patchElement4Id = randomString(); patchDir = mkdir(tempDir, patchID); - moduleA = new Module.Builder(moduleAName).miscFile(new ResourceItem("resource-a", "resource oneoff2".getBytes())).build(); + moduleA = new Module.Builder(moduleAName).miscFile(new ResourceItem("resource-a", "resource oneoff2".getBytes(StandardCharsets.UTF_8))).build(); // create the patch with the updated module moduleAModified = ContentModificationUtils.modifyModule(patchDir, patchElement4Id, moduleAModified.getItem().getContentHash(), moduleA); @@ -498,23 +499,23 @@ public void testCPAOneOffBCPC() throws Exception { final String moduleAName = "org.a.module-a"; Module moduleA = new Module.Builder(moduleAName) .resourceRoot(new ResourceItem(jarA.getName(), jarABytes)) - .miscFile(new ResourceItem("resource-a", "resource a in the module".getBytes())) + .miscFile(new ResourceItem("resource-a", "resource a in the module".getBytes(StandardCharsets.UTF_8))) .build(); final File moduleADir = moduleA.writeToDisk(new File(MODULES_PATH)); final String moduleBName = "org.b.module-b"; Module moduleB = new Module.Builder(moduleBName) .resourceRoot(new ResourceItem(jarB.getName(), jarBBytes)) - .miscFile(new ResourceItem("resource-b", "resource b in the module".getBytes())) + .miscFile(new ResourceItem("resource-b", "resource b in the module".getBytes(StandardCharsets.UTF_8))) .build(); final File moduleBDir = moduleB.writeToDisk(new File(MODULES_PATH)); final String moduleCName = "org.c.module-c"; Module moduleC = new Module.Builder(moduleCName) .resourceRoot(new ResourceItem(jarC.getName(), jarCBytes)) - .miscFile(new ResourceItem("resource-c", "resource c in the module".getBytes())) + .miscFile(new ResourceItem("resource-c", "resource c in the module".getBytes(StandardCharsets.UTF_8))) .build(); File moduleCDir = moduleC.writeToDisk(new File(MODULES_PATH)); - moduleA = new Module.Builder(moduleAName).miscFile(new ResourceItem("resource-a", "resource cp1".getBytes())).build(); + moduleA = new Module.Builder(moduleAName).miscFile(new ResourceItem("resource-a", "resource cp1".getBytes(StandardCharsets.UTF_8))).build(); final ContentModification moduleAModified = ContentModificationUtils.modifyModule(patchDir, patchElement1Id, HashUtils.hashFile(moduleADir), moduleA); Patch patch = PatchBuilder.create() @@ -541,7 +542,7 @@ public void testCPAOneOffBCPC() throws Exception { final String patchElement2Id = randomString(); patchDir = mkdir(tempDir, patchID); - moduleB = new Module.Builder(moduleBName).miscFile(new ResourceItem("resource-b", "resource oneoff1".getBytes())).build(); + moduleB = new Module.Builder(moduleBName).miscFile(new ResourceItem("resource-b", "resource oneoff1".getBytes(StandardCharsets.UTF_8))).build(); final ContentModification moduleBModified = ContentModificationUtils.modifyModule(patchDir, patchElement2Id, HashUtils.hashFile(moduleBDir), moduleB); patch = PatchBuilder.create() @@ -566,7 +567,7 @@ public void testCPAOneOffBCPC() throws Exception { final String patchElement3Id = randomString(); patchDir = mkdir(tempDir, patchID); - moduleC = new Module.Builder(moduleCName).miscFile(new ResourceItem("resource-c", "resource c cp".getBytes())).build(); + moduleC = new Module.Builder(moduleCName).miscFile(new ResourceItem("resource-c", "resource c cp".getBytes(StandardCharsets.UTF_8))).build(); final ContentModification moduleCModified = ContentModificationUtils.modifyModule(patchDir, patchElement3Id, HashUtils.hashFile(moduleCDir), moduleC); patch = PatchBuilder.create() diff --git a/testsuite/patching/src/test/java/org/jboss/as/test/patching/CumulativePatchingScenariosTestCase.java b/testsuite/patching/src/test/java/org/jboss/as/test/patching/CumulativePatchingScenariosTestCase.java index 2b9bcc10fc1..0f5d6fe1a61 100644 --- a/testsuite/patching/src/test/java/org/jboss/as/test/patching/CumulativePatchingScenariosTestCase.java +++ b/testsuite/patching/src/test/java/org/jboss/as/test/patching/CumulativePatchingScenariosTestCase.java @@ -36,6 +36,8 @@ import java.io.File; +import java.nio.charset.StandardCharsets; + import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.OutputKeys; @@ -89,8 +91,8 @@ private File createOneOffPatchAddingAModule(String patchID, String asVersion) th final String moduleName = "org.wildfly.test." + randomString(); - final ResourceItem resourceItem1 = new ResourceItem("testFile1", "content1".getBytes()); - final ResourceItem resourceItem2 = new ResourceItem("testFile2", "content2".getBytes()); + final ResourceItem resourceItem1 = new ResourceItem("testFile1", "content1".getBytes(StandardCharsets.UTF_8)); + final ResourceItem resourceItem2 = new ResourceItem("testFile2", "content2".getBytes(StandardCharsets.UTF_8)); Module newModule = new Module.Builder(moduleName) .miscFile(resourceItem1) @@ -118,8 +120,8 @@ private File createCumulativePatch(String patchID, String asVersion, final Strin final String moduleName = "org.wildfly.test." + randomString(); - final ResourceItem resourceItem1 = new ResourceItem("testFile1", "content1".getBytes()); - final ResourceItem resourceItem2 = new ResourceItem("testFile2", "content2".getBytes()); + final ResourceItem resourceItem1 = new ResourceItem("testFile1", "content1".getBytes(StandardCharsets.UTF_8)); + final ResourceItem resourceItem2 = new ResourceItem("testFile2", "content2".getBytes(StandardCharsets.UTF_8)); // Also see if we can update jboss-modules final File installation = new File(AS_DISTRIBUTION); diff --git a/testsuite/patching/src/test/java/org/jboss/as/test/patching/MergedPatchesTestCase.java b/testsuite/patching/src/test/java/org/jboss/as/test/patching/MergedPatchesTestCase.java index f53f3ae1e2f..1b4dcd38e84 100644 --- a/testsuite/patching/src/test/java/org/jboss/as/test/patching/MergedPatchesTestCase.java +++ b/testsuite/patching/src/test/java/org/jboss/as/test/patching/MergedPatchesTestCase.java @@ -33,6 +33,7 @@ import static org.jboss.as.test.patching.PatchingTestUtil.randomString; import java.io.File; +import java.nio.charset.StandardCharsets; import org.jboss.as.patching.Constants; import org.jboss.as.patching.HashUtils; @@ -255,8 +256,8 @@ private File createCP1(String patchID, String asVersion, final String targetAsVe cp1AddedModuleName = "org.wildfly.test." + randomString("cp1"); - cp1ResourceItem1 = new ResourceItem("testFile1", "content1".getBytes()); - cp1ResourceItem2 = new ResourceItem("testFile2", "content2".getBytes()); + cp1ResourceItem1 = new ResourceItem("testFile1", "content1".getBytes(StandardCharsets.UTF_8)); + cp1ResourceItem2 = new ResourceItem("testFile2", "content2".getBytes(StandardCharsets.UTF_8)); Module newModule = new Module.Builder(cp1AddedModuleName) .miscFile(cp1ResourceItem1) @@ -310,8 +311,8 @@ private File createCP2(String patchID, String asVersion, final String currentPat byte[] patchedAsVersionHash = HashUtils.hashFile(originalVersionModulePath); assert patchedAsVersionHash != null; - final ResourceItem resourceItem1 = new ResourceItem("testFile1", "content1".getBytes()); - final ResourceItem resourceItem2 = new ResourceItem("testFile2", "content2".getBytes()); + final ResourceItem resourceItem1 = new ResourceItem("testFile1", "content1".getBytes(StandardCharsets.UTF_8)); + final ResourceItem resourceItem2 = new ResourceItem("testFile2", "content2".getBytes(StandardCharsets.UTF_8)); Module newModule = new Module.Builder(moduleName) .miscFile(resourceItem1) diff --git a/testsuite/patching/src/test/java/org/jboss/as/test/patching/OverridePreserveTestCase.java b/testsuite/patching/src/test/java/org/jboss/as/test/patching/OverridePreserveTestCase.java index 5df2cfa6a88..f75d76aae9e 100644 --- a/testsuite/patching/src/test/java/org/jboss/as/test/patching/OverridePreserveTestCase.java +++ b/testsuite/patching/src/test/java/org/jboss/as/test/patching/OverridePreserveTestCase.java @@ -35,6 +35,7 @@ import static org.jboss.as.test.patching.PatchingTestUtil.randomString; import java.io.File; +import java.nio.charset.StandardCharsets; import org.jboss.as.patching.HashUtils; import org.jboss.as.patching.metadata.ContentModification; @@ -394,7 +395,7 @@ public void testOverrideModules() throws Exception { File patchDir = mkdir(tempDir, patchID); Module updatedModule = new Module.Builder(moduleName) - .miscFile(new ResourceItem("res1", "new resource in the module".getBytes())) + .miscFile(new ResourceItem("res1", "new resource in the module".getBytes(StandardCharsets.UTF_8))) .build(); // create the patch with the updated module diff --git a/testsuite/patching/src/test/java/org/jboss/as/test/patching/PatchBundleTestCase.java b/testsuite/patching/src/test/java/org/jboss/as/test/patching/PatchBundleTestCase.java index 1c0d8413d46..3d36301bef8 100644 --- a/testsuite/patching/src/test/java/org/jboss/as/test/patching/PatchBundleTestCase.java +++ b/testsuite/patching/src/test/java/org/jboss/as/test/patching/PatchBundleTestCase.java @@ -13,6 +13,7 @@ import static org.jboss.as.test.patching.PatchingTestUtil.randomString; import java.io.File; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; @@ -259,8 +260,8 @@ private File createCumulativePatchAddingARandomModule(String patchID, String asV final String moduleName = "org.wildfly.test." + randomString(); - final ResourceItem resourceItem1 = new ResourceItem("testFile1", "content1".getBytes()); - final ResourceItem resourceItem2 = new ResourceItem("testFile2", "content2".getBytes()); + final ResourceItem resourceItem1 = new ResourceItem("testFile1", "content1".getBytes(StandardCharsets.UTF_8)); + final ResourceItem resourceItem2 = new ResourceItem("testFile2", "content2".getBytes(StandardCharsets.UTF_8)); Module newModule = new Module.Builder(moduleName) .miscFile(resourceItem1) @@ -309,8 +310,8 @@ private File createNextCumulativePatchAddingRandomModule(String patchID, String byte[] patchedAsVersionHash = HashUtils.hashFile(originalVersionModulePath); assert patchedAsVersionHash != null; - final ResourceItem resourceItem1 = new ResourceItem("testFile1", "content1".getBytes()); - final ResourceItem resourceItem2 = new ResourceItem("testFile2", "content2".getBytes()); + final ResourceItem resourceItem1 = new ResourceItem("testFile1", "content1".getBytes(StandardCharsets.UTF_8)); + final ResourceItem resourceItem2 = new ResourceItem("testFile2", "content2".getBytes(StandardCharsets.UTF_8)); Module newModule = new Module.Builder(moduleName) .miscFile(resourceItem1) diff --git a/testsuite/patching/src/test/java/org/jboss/as/test/patching/PatchInfoTestBase.java b/testsuite/patching/src/test/java/org/jboss/as/test/patching/PatchInfoTestBase.java index 08b364843a7..eca7d676456 100644 --- a/testsuite/patching/src/test/java/org/jboss/as/test/patching/PatchInfoTestBase.java +++ b/testsuite/patching/src/test/java/org/jboss/as/test/patching/PatchInfoTestBase.java @@ -28,6 +28,7 @@ import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; import org.jboss.as.patching.metadata.ContentModification; import org.jboss.as.patching.metadata.Patch; @@ -81,7 +82,7 @@ protected byte[] applyPatch(String product, String version, String newVersion, S final File patchDir = mkdir(tempDir, patchID); final Module module = new Module.Builder("module-test"). - miscFile(new ResourceItem("resource-test", ("resource patch " + patchID).getBytes())). + miscFile(new ResourceItem("resource-test", ("resource patch " + patchID).getBytes(StandardCharsets.UTF_8))). build(); // create the patch with the updated module diff --git a/testsuite/patching/src/test/java/org/jboss/as/test/patching/PatchInfoTestCase.java b/testsuite/patching/src/test/java/org/jboss/as/test/patching/PatchInfoTestCase.java index e115b858993..4837903da64 100644 --- a/testsuite/patching/src/test/java/org/jboss/as/test/patching/PatchInfoTestCase.java +++ b/testsuite/patching/src/test/java/org/jboss/as/test/patching/PatchInfoTestCase.java @@ -33,6 +33,7 @@ import java.io.File; import java.io.IOException; import java.io.StringReader; +import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -74,7 +75,7 @@ public class PatchInfoTestCase extends PatchInfoTestBase { public void setup() throws Exception { bytesOs = new ByteArrayOutputStream(); final Module module = new Module.Builder("module-test"). - miscFile(new ResourceItem("resource-test", ("module resource").getBytes())). + miscFile(new ResourceItem("resource-test", ("module resource").getBytes(StandardCharsets.UTF_8))). build(); moduleDir = module.writeToDisk(new File(MODULES_PATH)); } @@ -265,7 +266,7 @@ class CLIOutputReader { void refresh() { if(bytesOs.size() > 0) { - reader = new BufferedReader(new StringReader(new String(bytesOs.toByteArray()))); + reader = new BufferedReader(new StringReader(new String(bytesOs.toByteArray(), StandardCharsets.UTF_8))); } else { reader = null; } diff --git a/testsuite/patching/src/test/java/org/jboss/as/test/patching/PatchStreamsUnitTestCase.java b/testsuite/patching/src/test/java/org/jboss/as/test/patching/PatchStreamsUnitTestCase.java index 3b8741da410..816c46f5d93 100644 --- a/testsuite/patching/src/test/java/org/jboss/as/test/patching/PatchStreamsUnitTestCase.java +++ b/testsuite/patching/src/test/java/org/jboss/as/test/patching/PatchStreamsUnitTestCase.java @@ -33,6 +33,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.StringReader; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -265,7 +266,7 @@ protected void cliHandle(String line) throws CommandLineException { protected File createModule(String targetLayer) throws IOException { final Module module = new Module.Builder("module-test"). - miscFile(new ResourceItem("resource-test", ("module resource").getBytes())). + miscFile(new ResourceItem("resource-test", ("module resource").getBytes(StandardCharsets.UTF_8))). build(); return module.writeToDisk(new File(PatchingTestUtil.LAYERS_DIRECTORY, targetLayer)); } @@ -333,14 +334,14 @@ class CLIOutputReader { void refresh() { if(bytesOs.size() > 0) { - reader = new BufferedReader(new StringReader(new String(bytesOs.toByteArray()))); + reader = new BufferedReader(new StringReader(new String(bytesOs.toByteArray(), StandardCharsets.UTF_8))); } else { reader = null; } } protected String readOutput() { - return new String(bytesOs.toByteArray()); + return new String(bytesOs.toByteArray(), StandardCharsets.UTF_8); } protected Map readTable() throws IOException { diff --git a/testsuite/patching/src/test/java/org/jboss/as/test/patching/PatchingTestUtil.java b/testsuite/patching/src/test/java/org/jboss/as/test/patching/PatchingTestUtil.java index 920d1f39100..85ee5c8c305 100644 --- a/testsuite/patching/src/test/java/org/jboss/as/test/patching/PatchingTestUtil.java +++ b/testsuite/patching/src/test/java/org/jboss/as/test/patching/PatchingTestUtil.java @@ -38,15 +38,15 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileFilter; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.Arrays; import java.util.List; -import java.util.Scanner; import java.util.UUID; import java.util.concurrent.ThreadLocalRandom; @@ -69,7 +69,6 @@ import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.exporter.ZipExporter; import org.jboss.shrinkwrap.api.spec.JavaArchive; -import org.junit.Assert; import com.google.common.base.Joiner; @@ -112,28 +111,12 @@ public static String randomString(String prefix) { * @return * @throws java.io.FileNotFoundException */ - public static String readFile(String filePath) throws FileNotFoundException { - Scanner scanner = null; - try { - scanner = new Scanner(new File(filePath)).useDelimiter("\\A"); - return scanner.next(); - } finally { - if (scanner != null) { scanner.close(); } - } + public static String readFile(String filePath) throws IOException { + return new String(Files.readAllBytes(Paths.get(filePath)), StandardCharsets.UTF_8); } public static void setFileContent(String filePath, String content) throws IOException { - OutputStream os = null; - try { - File file = new File(filePath); - file.delete(); - Assert.assertTrue("Cannot create new file", file.createNewFile()); - os = new FileOutputStream(file); - os.write(content.getBytes()); - os.flush(); - } finally { - if (os != null) { os.close(); } - } + Files.write(Paths.get(filePath), content.getBytes(StandardCharsets.UTF_8)); } public static void tree(File dir) { @@ -326,7 +309,7 @@ public static ResourceItem createVersionItem(final String targetVersion) { final Asset newManifest = new Asset() { @Override public InputStream openStream() { - return new ByteArrayInputStream(ProductInfo.createVersionString(targetVersion).getBytes()); + return new ByteArrayInputStream(ProductInfo.createVersionString(targetVersion).getBytes(StandardCharsets.UTF_8)); } }; diff --git a/testsuite/patching/src/test/java/org/jboss/as/test/patching/RemotePatchInfoPatchIdUnitTestCase.java b/testsuite/patching/src/test/java/org/jboss/as/test/patching/RemotePatchInfoPatchIdUnitTestCase.java index 6c3015ae276..f5c6fed9516 100644 --- a/testsuite/patching/src/test/java/org/jboss/as/test/patching/RemotePatchInfoPatchIdUnitTestCase.java +++ b/testsuite/patching/src/test/java/org/jboss/as/test/patching/RemotePatchInfoPatchIdUnitTestCase.java @@ -35,6 +35,7 @@ import java.io.ByteArrayOutputStream; import java.io.File; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -245,6 +246,6 @@ private String handle(final String line) throws CommandLineException { bytesOs.reset(); ctx.handle(line); controller.stop(); - return new String(bytesOs.toByteArray()); + return new String(bytesOs.toByteArray(), StandardCharsets.UTF_8); } } diff --git a/testsuite/patching/src/test/java/org/jboss/as/test/patching/RemotePatchInfoUnitTestCase.java b/testsuite/patching/src/test/java/org/jboss/as/test/patching/RemotePatchInfoUnitTestCase.java index c1a50a7ebee..985de2c4f12 100644 --- a/testsuite/patching/src/test/java/org/jboss/as/test/patching/RemotePatchInfoUnitTestCase.java +++ b/testsuite/patching/src/test/java/org/jboss/as/test/patching/RemotePatchInfoUnitTestCase.java @@ -27,6 +27,7 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -135,7 +136,7 @@ public void testMain() throws Exception { handle("patch info --verbose"); final ByteArrayInputStream bis = new ByteArrayInputStream(bytesOs.toByteArray()); - final InputStreamReader reader = new InputStreamReader(bis); + final InputStreamReader reader = new InputStreamReader(bis, StandardCharsets.UTF_8); final BufferedReader buf = new BufferedReader(reader); try { table = CLIPatchInfoUtil.parseTable(buf); @@ -291,7 +292,7 @@ private String handle(final String line) throws CommandLineException { bytesOs.reset(); ctx.handle(line); controller.stop(); - return new String(bytesOs.toByteArray()); + return new String(bytesOs.toByteArray(), StandardCharsets.UTF_8); } private static String descriptionFor(String patchId) { diff --git a/testsuite/patching/src/test/java/org/jboss/as/test/patching/RollbackLastUnitTestCase.java b/testsuite/patching/src/test/java/org/jboss/as/test/patching/RollbackLastUnitTestCase.java index 5ca8bb0974e..a0c4780aaf9 100644 --- a/testsuite/patching/src/test/java/org/jboss/as/test/patching/RollbackLastUnitTestCase.java +++ b/testsuite/patching/src/test/java/org/jboss/as/test/patching/RollbackLastUnitTestCase.java @@ -39,6 +39,7 @@ import static org.junit.Assert.fail; import java.io.File; +import java.nio.charset.StandardCharsets; import org.jboss.as.cli.CommandContext; import org.jboss.as.patching.HashUtils; @@ -82,7 +83,7 @@ public void testMain() throws Exception { File baseModuleDir = newFile(new File(PatchingTestUtil.AS_DISTRIBUTION), MODULES, SYSTEM, LAYERS, BASE); String moduleName = "module-test"; Module module = new Module.Builder(moduleName) - .miscFile(new ResourceItem("resource-test", "new resource in the module".getBytes())) + .miscFile(new ResourceItem("resource-test", "new resource in the module".getBytes(StandardCharsets.UTF_8))) .build(); File moduleDir = module.writeToDisk(new File(MODULES_PATH)); @@ -143,7 +144,7 @@ public void testMain() throws Exception { final File patchedModule = newFile(baseModuleDir, ".overlays", patchElementId, moduleName); Module modifiedModule = new Module.Builder(moduleName) - .miscFile(new ResourceItem("resource-test", "another module update".getBytes())) + .miscFile(new ResourceItem("resource-test", "another module update".getBytes(StandardCharsets.UTF_8))) .build(); ContentModification fileModified2 = ContentModificationUtils.modifyMisc(patchDir, patchID2, "another file update", miscFile, "bin", fileName); diff --git a/testsuite/patching/src/test/java/org/jboss/as/test/patching/ShowHistoryUnitTestCase.java b/testsuite/patching/src/test/java/org/jboss/as/test/patching/ShowHistoryUnitTestCase.java index 35a80db8664..2a8e3dc27e9 100644 --- a/testsuite/patching/src/test/java/org/jboss/as/test/patching/ShowHistoryUnitTestCase.java +++ b/testsuite/patching/src/test/java/org/jboss/as/test/patching/ShowHistoryUnitTestCase.java @@ -29,6 +29,7 @@ import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.List; import org.jboss.as.controller.client.ModelControllerClient; @@ -75,7 +76,7 @@ public void testUnpatched() throws Exception { @Test public void testCP() throws Exception { Module module = new Module.Builder("module-test"). - miscFile(new ResourceItem("resource-test", ("module resource").getBytes())). + miscFile(new ResourceItem("resource-test", ("module resource").getBytes(StandardCharsets.UTF_8))). build(); File moduleDir = module.writeToDisk(new File(MODULES_PATH)); @@ -97,7 +98,7 @@ public void testCP() throws Exception { @Test public void testOneOff() throws Exception { Module module = new Module.Builder("module-test"). - miscFile(new ResourceItem("resource-test", ("module resource").getBytes())). + miscFile(new ResourceItem("resource-test", ("module resource").getBytes(StandardCharsets.UTF_8))). build(); File moduleDir = module.writeToDisk(new File(MODULES_PATH)); @@ -119,7 +120,7 @@ public void testOneOff() throws Exception { @Test public void testOneOffAndCP() throws Exception { Module module = new Module.Builder("module-test"). - miscFile(new ResourceItem("resource-test", ("module resource").getBytes())). + miscFile(new ResourceItem("resource-test", ("module resource").getBytes(StandardCharsets.UTF_8))). build(); File moduleDir = module.writeToDisk(new File(MODULES_PATH)); @@ -147,7 +148,7 @@ public void testMain() throws Exception { // create a module Module module = new Module.Builder("module-test"). - miscFile(new ResourceItem("resource-test", ("module resource").getBytes())). + miscFile(new ResourceItem("resource-test", ("module resource").getBytes(StandardCharsets.UTF_8))). build(); File moduleDir = module.writeToDisk(new File(MODULES_PATH)); diff --git a/testsuite/patching/src/test/java/org/jboss/as/test/patching/util/module/Module.java b/testsuite/patching/src/test/java/org/jboss/as/test/patching/util/module/Module.java index aeae9e7f7cd..f2047feb30c 100644 --- a/testsuite/patching/src/test/java/org/jboss/as/test/patching/util/module/Module.java +++ b/testsuite/patching/src/test/java/org/jboss/as/test/patching/util/module/Module.java @@ -2,6 +2,7 @@ import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.Properties; @@ -84,7 +85,7 @@ public String generateXml() { public File writeToDisk(File baseDir) throws IOException { File mainDir = IoUtils.mkdir(baseDir, (name + "." + slot).split("\\.")); File moduleXml = PatchingTestUtil.touch(mainDir, "module.xml"); - PatchingTestUtil.dump(moduleXml, generateXml().getBytes()); + PatchingTestUtil.dump(moduleXml, generateXml().getBytes(StandardCharsets.UTF_8)); for (ResourceItem resourceRoot : resourceRoots) { File f = PatchingTestUtil.touch(mainDir, resourceRoot.getItemName()); PatchingTestUtil.dump(f, resourceRoot.getContent()); diff --git a/testsuite/shared/src/main/java/org/jboss/as/test/integration/common/HttpRequest.java b/testsuite/shared/src/main/java/org/jboss/as/test/integration/common/HttpRequest.java index 6f8af7fa41b..a3e18551095 100644 --- a/testsuite/shared/src/main/java/org/jboss/as/test/integration/common/HttpRequest.java +++ b/testsuite/shared/src/main/java/org/jboss/as/test/integration/common/HttpRequest.java @@ -28,6 +28,7 @@ import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.util.Base64; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; @@ -128,7 +129,7 @@ public String call() throws IOException { final HttpURLConnection conn = (HttpURLConnection) url.openConnection(); if (username != null) { final String userpassword = username + ":" + password; - final String basicAuthorization = Base64.getEncoder().encodeToString(userpassword.getBytes()); + final String basicAuthorization = Base64.getEncoder().encodeToString(userpassword.getBytes(StandardCharsets.UTF_8)); conn.setRequestProperty("Authorization", "Basic " + basicAuthorization); } conn.setDoInput(true); @@ -231,7 +232,7 @@ public static String head(final String spec, final String message, final long ti } private static void write(OutputStream out, String message) throws IOException { - final OutputStreamWriter writer = new OutputStreamWriter(out); + final OutputStreamWriter writer = new OutputStreamWriter(out, StandardCharsets.UTF_8); writer.write(message); writer.flush(); } diff --git a/testsuite/shared/src/main/java/org/jboss/as/test/integration/management/base/AbstractMgmtTestBase.java b/testsuite/shared/src/main/java/org/jboss/as/test/integration/management/base/AbstractMgmtTestBase.java index 0751edf98b0..6f0e1c0ceec 100644 --- a/testsuite/shared/src/main/java/org/jboss/as/test/integration/management/base/AbstractMgmtTestBase.java +++ b/testsuite/shared/src/main/java/org/jboss/as/test/integration/management/base/AbstractMgmtTestBase.java @@ -21,12 +21,20 @@ */ package org.jboss.as.test.integration.management.base; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RECURSIVE; +import static org.jboss.as.test.integration.management.util.ModelUtil.createCompositeNode; +import static org.jboss.as.test.integration.management.util.ModelUtil.createOpNode; + import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -55,12 +63,6 @@ import org.jboss.staxmapper.XMLMapper; import org.junit.Assert; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RECURSIVE; -import static org.jboss.as.test.integration.management.util.ModelUtil.createCompositeNode; -import static org.jboss.as.test.integration.management.util.ModelUtil.createOpNode; - /** * @author Dominik Pospisil */ @@ -197,14 +199,15 @@ public static ModelNode operationListToCompositeOperation(List operat } public static String readXmlResource(final String name) throws IOException { - File f = new File(name); - BufferedReader reader = new BufferedReader(new FileReader(f)); - StringWriter writer = new StringWriter(); - String line; - while ((line = reader.readLine()) != null) { - writer.write(line); + Path f = Paths.get(name); + try (BufferedReader reader = Files.newBufferedReader(f, StandardCharsets.UTF_8); + StringWriter writer = new StringWriter()) { + String line; + while ((line = reader.readLine()) != null) { + writer.write(line); + } + return writer.toString(); } - return writer.toString(); } protected void takeSnapShot() throws Exception{ diff --git a/testsuite/shared/src/main/java/org/jboss/as/test/integration/management/cli/CliProcessWrapper.java b/testsuite/shared/src/main/java/org/jboss/as/test/integration/management/cli/CliProcessWrapper.java index 7e27cc24616..10e241988b8 100644 --- a/testsuite/shared/src/main/java/org/jboss/as/test/integration/management/cli/CliProcessWrapper.java +++ b/testsuite/shared/src/main/java/org/jboss/as/test/integration/management/cli/CliProcessWrapper.java @@ -26,6 +26,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; +import java.nio.charset.StandardCharsets; import static org.junit.Assert.fail; @@ -85,7 +86,7 @@ public boolean executeInteractive(String prompt) { cliProcess = createProcess(); new Thread(new CliResultsReader(cliProcess.getInputStream())).start(); new Thread(new CliResultsReader(cliProcess.getErrorStream())).start(); - bufferedWriter = new BufferedWriter(new OutputStreamWriter(cliProcess.getOutputStream())); + bufferedWriter = new BufferedWriter(new OutputStreamWriter(cliProcess.getOutputStream(), StandardCharsets.UTF_8)); return waitForPrompt(prompt); } @@ -301,7 +302,7 @@ public CliResultsReader(InputStream inputStream){ @Override public void run() { - try(java.io.BufferedReader br = new java.io.BufferedReader(new java.io.InputStreamReader(cliStream))){ + try(java.io.BufferedReader br = new java.io.BufferedReader(new java.io.InputStreamReader(cliStream, StandardCharsets.UTF_8))){ int intCharacter = 0; Character character; // While the next character is a valid character and isn't null diff --git a/testsuite/shared/src/main/java/org/jboss/as/test/integration/management/util/CLIWrapper.java b/testsuite/shared/src/main/java/org/jboss/as/test/integration/management/util/CLIWrapper.java index dc8100e603e..9020fd2f171 100644 --- a/testsuite/shared/src/main/java/org/jboss/as/test/integration/management/util/CLIWrapper.java +++ b/testsuite/shared/src/main/java/org/jboss/as/test/integration/management/util/CLIWrapper.java @@ -28,6 +28,7 @@ import java.io.InputStream; import java.net.URI; import java.net.URISyntaxException; +import java.nio.charset.StandardCharsets; import org.jboss.as.cli.CliInitializationException; import org.jboss.as.cli.CommandContext; @@ -196,7 +197,7 @@ public String readOutput() { if(consoleOut.size() <= 0) { return null; } - return new String(consoleOut.toByteArray()).trim(); + return new String(consoleOut.toByteArray(), StandardCharsets.UTF_8).trim(); } /** diff --git a/testsuite/shared/src/main/java/org/jboss/as/test/integration/security/common/CoreUtils.java b/testsuite/shared/src/main/java/org/jboss/as/test/integration/security/common/CoreUtils.java index ac5bf000a50..3843d8b9d57 100644 --- a/testsuite/shared/src/main/java/org/jboss/as/test/integration/security/common/CoreUtils.java +++ b/testsuite/shared/src/main/java/org/jboss/as/test/integration/security/common/CoreUtils.java @@ -35,6 +35,7 @@ import java.net.URL; import java.net.URLEncoder; import java.net.UnknownHostException; +import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.util.ArrayList; import java.util.Base64; @@ -103,7 +104,7 @@ public static String hash(String target, String algorithm, Coding coding) { } catch (Exception e) { e.printStackTrace(); } - byte[] bytes = target.getBytes(); + byte[] bytes = target.getBytes(StandardCharsets.UTF_8); byte[] byteHash = md.digest(bytes); String encodedHash = null; diff --git a/testsuite/shared/src/main/java/org/jboss/as/test/module/util/TestModule.java b/testsuite/shared/src/main/java/org/jboss/as/test/module/util/TestModule.java index 4d51a81b010..62555440c4c 100644 --- a/testsuite/shared/src/main/java/org/jboss/as/test/module/util/TestModule.java +++ b/testsuite/shared/src/main/java/org/jboss/as/test/module/util/TestModule.java @@ -22,14 +22,15 @@ package org.jboss.as.test.module.util; import java.io.BufferedOutputStream; -import java.io.BufferedWriter; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; -import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; +import java.io.Writer; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.ArrayList; import java.util.List; @@ -306,8 +307,7 @@ public String getName() { } private void generateModuleXml(File mainDirectory) throws IOException { - BufferedWriter writer = new BufferedWriter(new FileWriter(new File(mainDirectory, "module.xml"))); - try { + try (Writer writer = Files.newBufferedWriter(new File(mainDirectory, "module.xml").toPath(), StandardCharsets.UTF_8)){ writer.write(""); writer.write(""); for (JavaArchive jar : resources) { @@ -320,8 +320,6 @@ private void generateModuleXml(File mainDirectory) throws IOException { } writer.write(""); writer.write(""); - } finally { - writer.close(); } } diff --git a/testsuite/shared/src/main/java/org/jboss/as/test/shared/FileUtils.java b/testsuite/shared/src/main/java/org/jboss/as/test/shared/FileUtils.java index ef665420dc1..ad55b2dc45c 100644 --- a/testsuite/shared/src/main/java/org/jboss/as/test/shared/FileUtils.java +++ b/testsuite/shared/src/main/java/org/jboss/as/test/shared/FileUtils.java @@ -7,6 +7,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.StandardCopyOption; @@ -36,7 +37,7 @@ public static String readFile(URL url) { StringBuilder builder = new StringBuilder(); int read = -1; while ((read = stream.read(buff)) != -1) { - builder.append(new String(buff, 0, read)); + builder.append(new String(buff, 0, read, StandardCharsets.UTF_8)); } return builder.toString(); } catch (IOException e) { diff --git a/testsuite/shared/src/main/java/org/wildfly/test/security/VaultSession.java b/testsuite/shared/src/main/java/org/wildfly/test/security/VaultSession.java index a19f0c62006..741618580bd 100644 --- a/testsuite/shared/src/main/java/org/wildfly/test/security/VaultSession.java +++ b/testsuite/shared/src/main/java/org/wildfly/test/security/VaultSession.java @@ -153,11 +153,11 @@ private String computeMaskedPassword() throws Exception { SecretKeyFactory factory = SecretKeyFactory.getInstance(VAULT_ENC_ALGORITHM); char[] password = "somearbitrarycrazystringthatdoesnotmatter".toCharArray(); - PBEParameterSpec cipherSpec = new PBEParameterSpec(salt.getBytes(), iterationCount); + PBEParameterSpec cipherSpec = new PBEParameterSpec(salt.getBytes(StandardCharsets.UTF_8), iterationCount); PBEKeySpec keySpec = new PBEKeySpec(password); SecretKey cipherKey = factory.generateSecret(keySpec); - String maskedPass = PBEUtils.encode64(keystorePassword.getBytes(), VAULT_ENC_ALGORITHM, cipherKey, cipherSpec); + String maskedPass = PBEUtils.encode64(keystorePassword.getBytes(StandardCharsets.UTF_8), VAULT_ENC_ALGORITHM, cipherKey, cipherSpec); return PicketBoxSecurityVault.PASS_MASK_PREFIX + maskedPass; } diff --git a/testsuite/standalone/src/test/java/org/jboss/as/test/integration/management/cli/BatchFileTestCase.java b/testsuite/standalone/src/test/java/org/jboss/as/test/integration/management/cli/BatchFileTestCase.java index 054df10c06a..17d67a58cd7 100644 --- a/testsuite/standalone/src/test/java/org/jboss/as/test/integration/management/cli/BatchFileTestCase.java +++ b/testsuite/standalone/src/test/java/org/jboss/as/test/integration/management/cli/BatchFileTestCase.java @@ -27,8 +27,10 @@ import static org.junit.Assert.fail; import java.io.File; -import java.io.FileWriter; import java.io.IOException; +import java.io.Writer; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.List; import org.jboss.as.cli.CommandContext; @@ -149,22 +151,13 @@ protected void createFile(String[] cmd) { } } - FileWriter writer = null; - try { - writer = new FileWriter(TMP_FILE); + try (Writer writer = Files.newBufferedWriter(TMP_FILE.toPath(), StandardCharsets.UTF_8)){ for(String line : cmd) { writer.write(line); writer.write('\n'); } } catch (IOException e) { fail("Failed to write to " + TMP_FILE.getAbsolutePath() + ": " + e.getLocalizedMessage()); - } finally { - if(writer != null) { - try { - writer.close(); - } catch (IOException e) { - } - } } } } diff --git a/testsuite/standalone/src/test/java/org/jboss/as/test/integration/management/cli/EchoTestCase.java b/testsuite/standalone/src/test/java/org/jboss/as/test/integration/management/cli/EchoTestCase.java index a92d3b9d899..50ecac17f5e 100644 --- a/testsuite/standalone/src/test/java/org/jboss/as/test/integration/management/cli/EchoTestCase.java +++ b/testsuite/standalone/src/test/java/org/jboss/as/test/integration/management/cli/EchoTestCase.java @@ -25,6 +25,7 @@ import static org.junit.Assert.assertEquals; import java.io.ByteArrayOutputStream; +import java.nio.charset.StandardCharsets; import org.jboss.as.cli.CommandContext; import org.jboss.as.test.integration.management.util.CLITestUtil; @@ -61,7 +62,7 @@ public void testMain() throws Exception { ctx.setVariable("a", "aa"); try { ctx.handle("echo \\$a is resolved to $a"); - assertEquals("$a is resolved to aa", new String(cliOut.toByteArray()).trim()); + assertEquals("$a is resolved to aa", new String(cliOut.toByteArray(), StandardCharsets.UTF_8).trim()); } finally { ctx.terminateSession(); cliOut.reset(); diff --git a/testsuite/standalone/src/test/java/org/jboss/as/test/integration/management/cli/FileArgumentTestCase.java b/testsuite/standalone/src/test/java/org/jboss/as/test/integration/management/cli/FileArgumentTestCase.java index a5dc32c6610..dcd2e60e104 100644 --- a/testsuite/standalone/src/test/java/org/jboss/as/test/integration/management/cli/FileArgumentTestCase.java +++ b/testsuite/standalone/src/test/java/org/jboss/as/test/integration/management/cli/FileArgumentTestCase.java @@ -26,9 +26,11 @@ import static org.junit.Assert.fail; import java.io.File; -import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; +import java.io.Writer; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; @@ -140,22 +142,13 @@ protected void createFile(String[] cmd) { } } - FileWriter writer = null; - try { - writer = new FileWriter(TMP_FILE); + try (final Writer writer = Files.newBufferedWriter(TMP_FILE.toPath(),StandardCharsets.UTF_8)){ for(String line : cmd) { writer.write(line); writer.write('\n'); } } catch (IOException e) { fail("Failed to write to " + TMP_FILE.getAbsolutePath() + ": " + e.getLocalizedMessage()); - } finally { - if(writer != null) { - try { - writer.close(); - } catch (IOException e) { - } - } } } @@ -226,7 +219,7 @@ protected int execute(File f, boolean logFailure) { if (bytesTotal > 0) { final byte[] bytes = new byte[bytesTotal]; cliProc.getErrorStream().read(bytes); - System.out.println("Command's error log: '" + new String(bytes) + "'"); + System.out.println("Command's error log: '" + new String(bytes, StandardCharsets.UTF_8) + "'"); } else { System.out.println("No output data for the command."); } @@ -243,7 +236,7 @@ protected void readStream(final StringBuilder cliOutBuf, InputStream cliStream) if (bytesTotal > 0) { final byte[] bytes = new byte[bytesTotal]; cliStream.read(bytes); - cliOutBuf.append(new String(bytes)); + cliOutBuf.append(new String(bytes, StandardCharsets.UTF_8)); } } catch (IOException e) { fail("Failed to read command's output: " + e.getLocalizedMessage()); diff --git a/testsuite/standalone/src/test/java/org/jboss/as/test/integration/management/cli/FileWithPropertiesTestCase.java b/testsuite/standalone/src/test/java/org/jboss/as/test/integration/management/cli/FileWithPropertiesTestCase.java index dc120b9e684..1d881f59c3c 100644 --- a/testsuite/standalone/src/test/java/org/jboss/as/test/integration/management/cli/FileWithPropertiesTestCase.java +++ b/testsuite/standalone/src/test/java/org/jboss/as/test/integration/management/cli/FileWithPropertiesTestCase.java @@ -29,10 +29,10 @@ import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; @@ -95,8 +95,8 @@ public static void setup() { BufferedReader reader = null; BufferedWriter writer = null; try { - reader = new BufferedReader(new FileReader(jbossCliXml)); - writer = new BufferedWriter(new FileWriter(TMP_JBOSS_CLI_FILE)); + reader = Files.newBufferedReader(jbossCliXml.toPath(), StandardCharsets.UTF_8); + writer = Files.newBufferedWriter(TMP_JBOSS_CLI_FILE.toPath(), StandardCharsets.UTF_8); String line = reader.readLine(); boolean replaced = false; while(line != null) { @@ -133,7 +133,7 @@ public static void setup() { ensureRemoved(SCRIPT_FILE); ensureRemoved(PROPS_FILE); try { - writer = new BufferedWriter(new FileWriter(SCRIPT_FILE)); + writer = Files.newBufferedWriter(SCRIPT_FILE.toPath(), StandardCharsets.UTF_8); writer.write(CONNECT_COMMAND); writer.newLine(); writer.write(SET_PROP_COMMAND); @@ -155,7 +155,7 @@ public static void setup() { writer = null; try { - writer = new BufferedWriter(new FileWriter(PROPS_FILE)); + writer = Files.newBufferedWriter(PROPS_FILE.toPath(), StandardCharsets.UTF_8); writer.write(CLI_PROP_NAME); writer.write('='); writer.write(CLI_PROP_VALUE); writer.newLine(); writer.write(HOST_PROP_NAME); writer.write('='); writer.write(HOST_PROP_VALUE); writer.newLine(); writer.write(PORT_PROP_NAME); writer.write('='); writer.write(PORT_PROP_VALUE); writer.newLine(); @@ -301,7 +301,7 @@ protected int execute(boolean resolveProps, boolean logFailure) { if (bytesTotal > 0) { final byte[] bytes = new byte[bytesTotal]; cliProc.getErrorStream().read(bytes); - System.out.println("Command's error log: '" + new String(bytes) + "'"); + System.out.println("Command's error log: '" + new String(bytes, StandardCharsets.UTF_8) + "'"); } else { System.out.println("No output data for the command."); } @@ -319,7 +319,7 @@ protected void readStream(final StringBuilder cliOutBuf, InputStream cliStream) if (bytesTotal > 0) { final byte[] bytes = new byte[bytesTotal]; cliStream.read(bytes); - cliOutBuf.append(new String(bytes)); + cliOutBuf.append(new String(bytes, StandardCharsets.UTF_8)); } } catch (IOException e) { fail("Failed to read command's output: " + e.getLocalizedMessage()); diff --git a/testsuite/standalone/src/test/java/org/jboss/as/test/integration/management/cli/RcFileTestCase.java b/testsuite/standalone/src/test/java/org/jboss/as/test/integration/management/cli/RcFileTestCase.java index 033a17d90a8..ee4230211c6 100644 --- a/testsuite/standalone/src/test/java/org/jboss/as/test/integration/management/cli/RcFileTestCase.java +++ b/testsuite/standalone/src/test/java/org/jboss/as/test/integration/management/cli/RcFileTestCase.java @@ -28,8 +28,9 @@ import java.io.BufferedWriter; import java.io.File; -import java.io.FileWriter; import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import org.jboss.as.cli.CommandContext; import org.jboss.as.cli.CommandContextFactory; @@ -61,7 +62,7 @@ public static void setup() { ensureRemoved(TMP_JBOSS_CLI_RC); BufferedWriter writer = null; try { - writer = new BufferedWriter(new FileWriter(TMP_JBOSS_CLI_RC)); + writer = Files.newBufferedWriter(TMP_JBOSS_CLI_RC.toPath(), StandardCharsets.UTF_8); writer.write("set " + VAR_NAME + "=" + VAR_VALUE); writer.newLine(); } catch(IOException e) { diff --git a/testsuite/standalone/src/test/java/org/jboss/as/test/integration/management/cli/extensions/CliExtCommandHandler.java b/testsuite/standalone/src/test/java/org/jboss/as/test/integration/management/cli/extensions/CliExtCommandHandler.java index 7abb84f599b..e5f3c3e66dc 100644 --- a/testsuite/standalone/src/test/java/org/jboss/as/test/integration/management/cli/extensions/CliExtCommandHandler.java +++ b/testsuite/standalone/src/test/java/org/jboss/as/test/integration/management/cli/extensions/CliExtCommandHandler.java @@ -27,12 +27,12 @@ import org.jboss.as.cli.CommandLineException; import org.jboss.as.cli.handlers.CommandHandlerWithHelp; import org.jboss.as.cli.util.HelpFormatter; -import org.jboss.as.protocol.StreamUtils; import org.wildfly.security.manager.WildFlySecurityManager; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; /** * @@ -58,14 +58,11 @@ protected void printHelp(CommandContext ctx) throws CommandLineException { ClassLoader cl = WildFlySecurityManager.getClassLoaderPrivileged(CliExtCommandHandler.class); InputStream helpInput = cl.getResourceAsStream(filename); if (helpInput != null) { - BufferedReader reader = new BufferedReader(new InputStreamReader(helpInput)); - try { + try (final BufferedReader reader = new BufferedReader(new InputStreamReader(helpInput, StandardCharsets.UTF_8))){ System.setProperty("aesh.terminal","org.jboss.aesh.terminal.TestTerminal"); HelpFormatter.format(ctx, reader); } catch (java.io.IOException e) { throw new CommandFormatException("Failed to read help/help.txt: " + e.getLocalizedMessage()); - } finally { - StreamUtils.safeClose(reader); } } else { throw new CommandFormatException("Failed to locate command description " + filename); diff --git a/testsuite/standalone/src/test/java/org/jboss/as/test/integration/management/cli/extensions/DuplicateExtCommandTestCase.java b/testsuite/standalone/src/test/java/org/jboss/as/test/integration/management/cli/extensions/DuplicateExtCommandTestCase.java index 323adda53e5..447a9f2f667 100644 --- a/testsuite/standalone/src/test/java/org/jboss/as/test/integration/management/cli/extensions/DuplicateExtCommandTestCase.java +++ b/testsuite/standalone/src/test/java/org/jboss/as/test/integration/management/cli/extensions/DuplicateExtCommandTestCase.java @@ -30,6 +30,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.nio.charset.StandardCharsets; import javax.inject.Inject; @@ -130,7 +131,7 @@ private static Asset getResource(Class clazz) { public InputStream openStream() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { - baos.write(clazz.getName().getBytes()); + baos.write(clazz.getName().getBytes(StandardCharsets.UTF_8)); } catch (IOException e) { e.printStackTrace(); } diff --git a/testsuite/standalone/src/test/java/org/jboss/as/test/integration/management/http/HttpDeploymentUploadUnitTestCase.java b/testsuite/standalone/src/test/java/org/jboss/as/test/integration/management/http/HttpDeploymentUploadUnitTestCase.java index ddc7d8aadcf..d810053be04 100644 --- a/testsuite/standalone/src/test/java/org/jboss/as/test/integration/management/http/HttpDeploymentUploadUnitTestCase.java +++ b/testsuite/standalone/src/test/java/org/jboss/as/test/integration/management/http/HttpDeploymentUploadUnitTestCase.java @@ -160,7 +160,7 @@ private void writeAddRequest(BufferedOutputStream os, byte[] hash) throws IOExce op.get("content").get(0).get("hash").set(hash); op.get("enabled").set(true); - os.write(op.toJSONString(true).getBytes()); + os.write(op.toJSONString(true).getBytes(StandardCharsets.UTF_8)); os.flush(); } @@ -170,7 +170,7 @@ private void writeRemoveRequest(BufferedOutputStream os) throws IOException { op.get("operation").set("remove"); op.get("address").add("deployment", "test-http-deployment.sar"); - os.write(op.toJSONString(true).getBytes()); + os.write(op.toJSONString(true).getBytes(StandardCharsets.UTF_8)); os.flush(); } @@ -187,7 +187,7 @@ private byte[] buildUploadPostRequestHeader() { builder.append(CRLF); builder.append(buildPostRequestHeaderSection("form-data; name=\"file\"; filename=\"test.war\"", "application/octet-stream", "")); - return builder.toString().getBytes(); + return builder.toString().getBytes(StandardCharsets.UTF_8); } private String buildPostRequestHeaderSection(final String contentDisposition, final String contentType, final String content) { diff --git a/testsuite/standalone/src/test/java/org/wildfly/core/test/standalone/mgmt/api/DeploymentTestCase.java b/testsuite/standalone/src/test/java/org/wildfly/core/test/standalone/mgmt/api/DeploymentTestCase.java index f83541a20c3..70cd819c136 100644 --- a/testsuite/standalone/src/test/java/org/wildfly/core/test/standalone/mgmt/api/DeploymentTestCase.java +++ b/testsuite/standalone/src/test/java/org/wildfly/core/test/standalone/mgmt/api/DeploymentTestCase.java @@ -36,6 +36,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.HashMap; @@ -279,9 +280,7 @@ public void initialDeploy() throws IOException { } // Create the .dodeploy file final File dodeploy = new File(deployDir, "test-deployment.jar.dodeploy"); - try (final OutputStream out = new BufferedOutputStream(new FileOutputStream(dodeploy))){ - out.write("test-deployment.jar".getBytes()); - } + Files.write(dodeploy.toPath(), "test-deployment.jar".getBytes(StandardCharsets.UTF_8)); Assert.assertTrue(dodeploy.exists()); for (int i = 0; i < TIMEOUT / BACKOFF; i++) { if (deployed.exists()) { @@ -571,12 +570,7 @@ public void initialDeploy() throws IOException { // Create the .dodeploy file final File dodeploy = new File(deployDir, "test-deployment.jar.dodeploy"); - final OutputStream out = new BufferedOutputStream(new FileOutputStream(dodeploy)); - try { - out.write("test-deployment.jar".getBytes()); - } finally { - StreamUtils.safeClose(out); - } + Files.write(dodeploy.toPath(), "test-deployment.jar".getBytes(StandardCharsets.UTF_8)); Assert.assertTrue(dodeploy.exists()); for (int i = 0; i < TIMEOUT / BACKOFF; i++) { if (deployed.exists()) { diff --git a/testsuite/standalone/src/test/java/org/wildfly/core/test/standalone/mgmt/api/core/ResponseAttachmentTestCase.java b/testsuite/standalone/src/test/java/org/wildfly/core/test/standalone/mgmt/api/core/ResponseAttachmentTestCase.java index 647ae338234..4825ebc9877 100644 --- a/testsuite/standalone/src/test/java/org/wildfly/core/test/standalone/mgmt/api/core/ResponseAttachmentTestCase.java +++ b/testsuite/standalone/src/test/java/org/wildfly/core/test/standalone/mgmt/api/core/ResponseAttachmentTestCase.java @@ -37,6 +37,7 @@ import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.util.List; import org.apache.http.HttpEntity; @@ -404,7 +405,7 @@ private void readLogFile(ModelNode opNode) throws IOException { } private void readLogStream(InputStream stream) throws IOException { - LineNumberReader reader = new LineNumberReader(new InputStreamReader(stream)); + LineNumberReader reader = new LineNumberReader(new InputStreamReader(stream, StandardCharsets.UTF_8)); String read; boolean readMessage = false; String expected = LogStreamExtension.getLogMessage(logMessageContent); diff --git a/version/src/main/java/org/jboss/as/version/ProductConfig.java b/version/src/main/java/org/jboss/as/version/ProductConfig.java index 7cc0e53b96d..d4a009559ea 100644 --- a/version/src/main/java/org/jboss/as/version/ProductConfig.java +++ b/version/src/main/java/org/jboss/as/version/ProductConfig.java @@ -22,11 +22,14 @@ package org.jboss.as.version; +import java.io.BufferedReader; import java.io.Closeable; import java.io.File; -import java.io.FileReader; import java.io.InputStream; import java.io.Serializable; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.Map; @@ -115,9 +118,9 @@ public String run() { private static ProductConfProps getProductConfProperties(String home) { Properties props = new Properties(); - FileReader reader = null; + BufferedReader reader = null; try { - reader = new FileReader(getProductConf(home)); + reader = Files.newBufferedReader(Paths.get(getProductConf(home)), StandardCharsets.UTF_8); props.load(reader); } catch (Exception e) { // Don't care