Skip to content

Commit 97bb62e

Browse files
committed
Fix for UTF8 Windows errors
1 parent 08661f8 commit 97bb62e

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/isc/rabbitmq/API.java

+14-11
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
import java.io.IOException;
66

7-
import java.nio.file.*;
8-
7+
import java.nio.charset.StandardCharsets;
98
import java.util.Date;
109
import java.util.HashMap;
1110

@@ -65,7 +64,6 @@ public void sendMessage(byte[] msg) throws Exception {
6564
}
6665

6766
public void sendMessageToQueue(String queue, byte[] msg) throws Exception {
68-
//log(msg);
6967
_channel.basicPublish("", queue, null, msg);
7068
}
7169

@@ -89,7 +87,19 @@ public String[] readMessageString() throws Exception {
8987
if (response == null) {
9088
// No message retrieved.
9189
} else {
92-
result[15] = new String(response.getBody());
90+
result[15] = new String(response.getBody(), StandardCharsets.UTF_8);
91+
}
92+
return result;
93+
}
94+
95+
public String readMessageBodyString() throws Exception {
96+
String result;
97+
boolean autoAck = true;
98+
GetResponse response = _channel.basicGet(_queue, autoAck);
99+
if (response == null) {
100+
result = "";
101+
} else {
102+
result = new String(response.getBody(), StandardCharsets.UTF_8);
93103
}
94104
return result;
95105
}
@@ -120,18 +130,11 @@ private GetResponse readMessage(String[] msg) throws IOException {
120130
msg[12] = props.getDeliveryMode() != null ? Integer.toString(props.getDeliveryMode()) : null;
121131
msg[13] = props.getPriority() != null ? Integer.toString(props.getPriority()) : null;
122132
msg[14] = props.getTimestamp() != null ? props.getTimestamp().toString() : null;
123-
124-
//log(response.getBody());
125133
}
126134
return response;
127135

128136
}
129137

130-
private void log(byte[] msg) throws IOException {
131-
Path path = Paths.get("C:\\InterSystems\\java.log");
132-
Files.write(path, msg);
133-
}
134-
135138
public void close()throws Exception {
136139
_channel.close();
137140
_connection.close();

0 commit comments

Comments
 (0)