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;
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) {
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
*/
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),
byte[] stringBytes = new byte[length];
buffer.get(stringBytes);
- return new String(stringBytes).trim();
+ return new String(stringBytes, SESSIOND_PROTOCOL_CHARSET).trim();
}
}
}
ByteBuffer buf = ByteBuffer.wrap(data);
buf.order(ByteOrder.BIG_ENDIAN);
- eventName = new String(data).trim();
+ eventName = new String(data, SESSIOND_PROTOCOL_CHARSET).trim();
}
@Override
/* 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);
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);
}