From a6230a82bff891b406c34aee475ff32506ab12e4 Mon Sep 17 00:00:00 2001 From: Gideon le Grange Date: Sat, 8 Oct 2016 19:05:09 +0200 Subject: [PATCH] Fix #40. Changed string encoding to UTF8 when sending bytes accross the network --- src/main/java/examples/Issue4.java | 30 +++++++++++++++++++ .../java/me/legrange/mikrotik/impl/Util.java | 3 +- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/main/java/examples/Issue4.java diff --git a/src/main/java/examples/Issue4.java b/src/main/java/examples/Issue4.java new file mode 100644 index 0000000..b041bb1 --- /dev/null +++ b/src/main/java/examples/Issue4.java @@ -0,0 +1,30 @@ +package examples; + +import java.util.List; +import java.util.Map; +import me.legrange.mikrotik.MikrotikApiException; + +/** + * Example 7: Dump your complete config + * + * @author gideon + */ +public class DownloadConfig extends Example { + + public static void main(String... args) throws Exception { + DownloadConfig ex = new DownloadConfig(); + ex.connect(); + ex.test(); + ex.disconnect(); + } + + private void test() throws MikrotikApiException, InterruptedException { + con.execute("/export file=conf"); + List> res = con.execute("/file/print detail where name=conf.rsc"); + con.execute("/file/remove .id=conf.rsc"); + String text = res.get(0).get("contents"); + for (String line : text.split("\r")) { + System.out.println(line); + } + } +} diff --git a/src/main/java/me/legrange/mikrotik/impl/Util.java b/src/main/java/me/legrange/mikrotik/impl/Util.java index 606273c..4979929 100644 --- a/src/main/java/me/legrange/mikrotik/impl/Util.java +++ b/src/main/java/me/legrange/mikrotik/impl/Util.java @@ -133,7 +133,8 @@ final class Util { * stream. */ private static void encode(String word, OutputStream out) throws UnsupportedEncodingException, IOException { - byte bytes[] = word.getBytes("US-ASCII"); +// byte bytes[] = word.getBytes("US-ASCII"); + byte bytes[] = word.getBytes("UTF-8"); int len = bytes.length; if (len < 0x80) { out.write(len);