Specify UTF-8 encoding for all Java agent commands
authorAlexandre Montplaisir <alexmonthy@efficios.com>
Thu, 19 May 2016 18:31:20 +0000 (14:31 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 19 May 2016 19:52:20 +0000 (15:52 -0400)
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 <alexmonthy@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/LttngTcpSessiondClient.java
liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondCommand.java
liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondDisableEventCommand.java
liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondEnableEventCommand.java
liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondListLoggersCommand.java

index e9b52f1de9bdd91bec480fe3abd86820936801e6..333dd5b02a7234256d1908499f0f6615a7c4a390 100644 (file)
@@ -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) {
index fd5bb1de89030579734d158b7e577acb028c6aa7..7cde4a3598a516c5cbcd1beb4562e03ce4ea9475 100644 (file)
@@ -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();
        }
 }
index 4a19c22ea91d3e6743119737dc828a4672b434e9..43ff4026346fa62a8a18ef5d402eda6272d17c8f 100644 (file)
@@ -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
index 5b36ac5d10a006c0e2ed1365a83b628f7dd631fe..54fcb4c0042821a21f50a08564971f2b57ff8881 100644 (file)
@@ -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);
index c1bdaf407007ccf686c5a060ee1e510b0bf5dd49..1c7ef9b400f019e7611c36b5bb349c99cc628b5d 100644 (file)
@@ -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);
                        }
This page took 0.02754 seconds and 4 git commands to generate.