修复JsonByteBuffer解析bug

This commit is contained in:
redkale
2023-05-09 14:45:25 +08:00
parent 454e6b60d7
commit 2202465e31
4 changed files with 224 additions and 9 deletions

View File

@@ -164,6 +164,7 @@ public class JsonByteBufferReader extends JsonReader {
if (ch == 'N' && nextChar() == 'U' && nextChar() == 'L' && nextChar() == 'L') {
return SIGN_NULL;
}
int pos = this.position;
StringBuilder sb = new StringBuilder();
sb.append(ch);
char one;
@@ -171,7 +172,7 @@ public class JsonByteBufferReader extends JsonReader {
while ((one = nextChar()) != 0) sb.append(one);
} catch (Exception e) {
}
throw new ConvertException("a json array text must begin with '[' (position = " + position + ") but '" + ch + "' in (" + sb + ")");
throw new ConvertException("a json array text must begin with '[' (position = " + pos + ") but '" + ch + "' in (" + sb + ")");
}
/**
@@ -183,6 +184,7 @@ public class JsonByteBufferReader extends JsonReader {
if (ch == ':') {
return;
}
int pos = this.position;
StringBuilder sb = new StringBuilder();
sb.append(ch);
char one;
@@ -190,7 +192,7 @@ public class JsonByteBufferReader extends JsonReader {
while ((one = nextChar()) != 0) sb.append(one);
} catch (Exception e) {
}
throw new ConvertException("expected a ':' but '" + ch + "'(position = " + position + ") in (" + sb + ")");
throw new ConvertException("expected a ':' but '" + ch + "'(position = " + pos + ") in (" + sb + ")");
}
/**

View File

@@ -365,7 +365,7 @@ public class JsonReader extends Reader {
if (nt == '}' || nt == ']') {
return false;
}
backChar(ch);
backChar(nt);
return true;
}
if (ch == '}' || ch == ']') {

View File

@@ -9,7 +9,7 @@ import java.io.*;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
import java.nio.charset.*;
import java.util.Arrays;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
/**
@@ -31,17 +31,18 @@ public final class ByteArray implements ByteTuple {
}
public ByteArray(int size) {
content = new byte[Math.max(1, size)];
this.content = new byte[Math.max(1, size)];
}
public ByteArray(ByteTuple tuple) {
content = tuple.content();
count = tuple.length();
this.content = tuple.content();
this.count = tuple.length();
}
public ByteArray(byte[] bs) {
content = bs;
count = 0;
Objects.requireNonNull(bs);
this.content = bs;
this.count = bs.length;
}
/**