Skip to content

Commit

Permalink
Fix for UTF8 Windows errors
Browse files Browse the repository at this point in the history
  • Loading branch information
eduard93 committed Feb 2, 2018
1 parent 08661f8 commit 97bb62e
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/isc/rabbitmq/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

import java.io.IOException;

import java.nio.file.*;

import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.HashMap;

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

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

Expand All @@ -89,7 +87,19 @@ public String[] readMessageString() throws Exception {
if (response == null) {
// No message retrieved.
} else {
result[15] = new String(response.getBody());
result[15] = new String(response.getBody(), StandardCharsets.UTF_8);
}
return result;
}

public String readMessageBodyString() throws Exception {
String result;
boolean autoAck = true;
GetResponse response = _channel.basicGet(_queue, autoAck);
if (response == null) {
result = "";
} else {
result = new String(response.getBody(), StandardCharsets.UTF_8);
}
return result;
}
Expand Down Expand Up @@ -120,18 +130,11 @@ private GetResponse readMessage(String[] msg) throws IOException {
msg[12] = props.getDeliveryMode() != null ? Integer.toString(props.getDeliveryMode()) : null;
msg[13] = props.getPriority() != null ? Integer.toString(props.getPriority()) : null;
msg[14] = props.getTimestamp() != null ? props.getTimestamp().toString() : null;

//log(response.getBody());
}
return response;

}

private void log(byte[] msg) throws IOException {
Path path = Paths.get("C:\\InterSystems\\java.log");
Files.write(path, msg);
}

public void close()throws Exception {
_channel.close();
_connection.close();
Expand Down

0 comments on commit 97bb62e

Please sign in to comment.