Skip to content

Commit

Permalink
Fix chinese string are truncated in ConcunrrentDiskUtil (alibaba#3883)
Browse files Browse the repository at this point in the history
  • Loading branch information
ljhrot committed Sep 22, 2020
1 parent 5df146e commit 7902b22
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Expand Up @@ -143,11 +143,12 @@ public static Boolean writeFileContent(File file, String content, String charset
}
} while (null == lock);

ByteBuffer sendBuffer = ByteBuffer.wrap(content.getBytes(charsetName));
byte[] contentBytes = content.getBytes(charsetName);
ByteBuffer sendBuffer = ByteBuffer.wrap(contentBytes);
while (sendBuffer.hasRemaining()) {
channel.write(sendBuffer);
}
channel.truncate(content.length());
channel.truncate(contentBytes.length);
} catch (FileNotFoundException e) {
throw new IOException("file not exist");
} finally {
Expand Down
Expand Up @@ -47,6 +47,7 @@ public void setUp() throws Exception {
instance.setIp("1.1.1.1");
instance.setPort(1234);
instance.setServiceName("testName");
instance.addMetadata("chinese", "中文");
serviceInfo.setHosts(Collections.singletonList(instance));
}

Expand Down Expand Up @@ -87,9 +88,10 @@ private void assertHosts(List<Instance> actual, List<Instance> expected) {
}

private void assertInstance(Instance actual, Instance expected) {
assertEquals(actual.getServiceName(), actual.getServiceName());
assertEquals(actual.getClusterName(), actual.getClusterName());
assertEquals(actual.getIp(), actual.getIp());
assertEquals(actual.getPort(), actual.getPort());
assertEquals(actual.getServiceName(), expected.getServiceName());
assertEquals(actual.getClusterName(), expected.getClusterName());
assertEquals(actual.getIp(), expected.getIp());
assertEquals(actual.getPort(), expected.getPort());
assertEquals(actual.getMetadata(), expected.getMetadata());
}
}

0 comments on commit 7902b22

Please sign in to comment.