Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,16 @@ public ContinueToken(String lastKey, String lastDir) {
public String encodeToString() {
if (this.lastKey != null) {

ByteBuffer buffer = ByteBuffer
.allocate(4 + lastKey.length()
+ (lastDir == null ? 0 : lastDir.length()));
buffer.putInt(lastKey.length());
buffer.put(lastKey.getBytes(StandardCharsets.UTF_8));
byte[] rawLastKey = lastKey.getBytes(StandardCharsets.UTF_8);
byte[] rawLastDir = (lastDir == null ? new byte[0] :
lastDir.getBytes(StandardCharsets.UTF_8));

ByteBuffer buffer = ByteBuffer.allocate(
4 + rawLastKey.length + rawLastDir.length);
buffer.putInt(rawLastKey.length);
buffer.put(rawLastKey);
if (lastDir != null) {
buffer.put(lastDir.getBytes(StandardCharsets.UTF_8));
buffer.put(rawLastDir);
}

String hex = Hex.encodeHexString(buffer.array());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,26 @@ public void encodeDecode() throws OS3Exception {
Assert.assertEquals(ct, parsedToken);
}

@Test
public void encodeDecodeWithNonEnglishOne() throws OS3Exception {
ContinueToken ct = new ContinueToken("你好", null);

ContinueToken parsedToken =
ContinueToken.decodeFromString(ct.encodeToString());

Assert.assertEquals(ct, parsedToken);
}

@Test
public void encodeDecodeWithNonEnglishTwo() throws OS3Exception {
ContinueToken ct = new ContinueToken("你好", "上海");

ContinueToken parsedToken =
ContinueToken.decodeFromString(ct.encodeToString());

Assert.assertEquals(ct, parsedToken);
}

@Test
public void encodeDecodeNullDir() throws OS3Exception {
ContinueToken ct = new ContinueToken("key1", null);
Expand Down