From: Alexandre Montplaisir Date: Thu, 19 May 2016 18:31:20 +0000 (-0400) Subject: Specify UTF-8 encoding for all Java agent commands X-Git-Tag: v2.9.0-rc1~101 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=22191ffd5680d377e6f92f783c9b2302708732ab;p=lttng-ust.git Specify UTF-8 encoding for all Java agent commands Context info was already set to UTF-8, but agent enabled/disabled and list-loggers commands should also specify the UTF-8 encoding. Signed-off-by: Alexandre Montplaisir Signed-off-by: Mathieu Desnoyers --- diff --git a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/LttngTcpSessiondClient.java b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/LttngTcpSessiondClient.java index e9b52f1d..333dd5b0 100644 --- a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/LttngTcpSessiondClient.java +++ b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/LttngTcpSessiondClient.java @@ -21,6 +21,7 @@ package org.lttng.ust.agent.client; import java.io.BufferedReader; import java.io.DataInputStream; import java.io.DataOutputStream; +import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; @@ -199,9 +200,10 @@ public class LttngTcpSessiondClient implements Runnable { private static int getPortFromFile(String path) throws IOException { int port; BufferedReader br = null; + File file = new File(path); try { - br = new BufferedReader(new FileReader(path)); + br = new BufferedReader(new FileReader(file)); String line = br.readLine(); port = Integer.parseInt(line, 10); if (port < 0 || port > 65535) { diff --git a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondCommand.java b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondCommand.java index fd5bb1de..7cde4a35 100644 --- a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondCommand.java +++ b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondCommand.java @@ -19,6 +19,7 @@ package org.lttng.ust.agent.client; import java.nio.ByteBuffer; +import java.nio.charset.Charset; /** * Base class to represent all commands sent from the session daemon to the Java @@ -29,6 +30,12 @@ import java.nio.ByteBuffer; */ abstract class SessiondCommand { + /** + * Encoding that should be used for the strings in the sessiond agent + * protocol on the socket. + */ + protected static final Charset SESSIOND_PROTOCOL_CHARSET = Charset.forName("UTF-8"); + enum CommandType { /** List logger(s). */ CMD_LIST(1), @@ -87,6 +94,6 @@ abstract class SessiondCommand { byte[] stringBytes = new byte[length]; buffer.get(stringBytes); - return new String(stringBytes).trim(); + return new String(stringBytes, SESSIOND_PROTOCOL_CHARSET).trim(); } } diff --git a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondDisableEventCommand.java b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondDisableEventCommand.java index 4a19c22e..43ff4026 100644 --- a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondDisableEventCommand.java +++ b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondDisableEventCommand.java @@ -39,7 +39,7 @@ class SessiondDisableEventCommand extends SessiondCommand { } ByteBuffer buf = ByteBuffer.wrap(data); buf.order(ByteOrder.BIG_ENDIAN); - eventName = new String(data).trim(); + eventName = new String(data, SESSIOND_PROTOCOL_CHARSET).trim(); } @Override diff --git a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondEnableEventCommand.java b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondEnableEventCommand.java index 5b36ac5d..54fcb4c0 100644 --- a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondEnableEventCommand.java +++ b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondEnableEventCommand.java @@ -56,7 +56,7 @@ class SessiondEnableEventCommand extends SessiondCommand { /* Read the event name */ byte[] eventNameBytes = new byte[EVENT_NAME_LENGTH]; buf.get(eventNameBytes); - eventName = new String(eventNameBytes).trim(); + eventName = new String(eventNameBytes, SESSIOND_PROTOCOL_CHARSET).trim(); /* Read the filter string */ filterString = readNextString(buf); diff --git a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondListLoggersCommand.java b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondListLoggersCommand.java index c1bdaf40..1c7ef9b4 100644 --- a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondListLoggersCommand.java +++ b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondListLoggersCommand.java @@ -73,7 +73,7 @@ class SessiondListLoggersCommand extends SessiondCommand { buf.putInt(loggers.size()); for (String logger : loggers) { - buf.put(logger.getBytes()); + buf.put(logger.getBytes(SESSIOND_PROTOCOL_CHARSET)); /* NULL terminated byte after the logger name. */ buf.put((byte) 0x0); }