This commit is contained in:
@@ -89,8 +89,8 @@ public class ArrayDecoder<T> implements Decodeable<Reader, T[]> {
|
|||||||
boolean first = true;
|
boolean first = true;
|
||||||
if (len == Reader.SIGN_NOLENGTH) {
|
if (len == Reader.SIGN_NOLENGTH) {
|
||||||
int startPosition = in.position();
|
int startPosition = in.position();
|
||||||
while (in.hasNext(this, member, startPosition, contentLength)) {
|
while (hasNext(in, member, startPosition, contentLength, first)) {
|
||||||
Reader itemReader = getArrayItemReader(in, member, first);
|
Reader itemReader = getItemReader(in, member, first);
|
||||||
result.add(readMemberValue(itemReader, member, first));
|
result.add(readMemberValue(itemReader, member, first));
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
@@ -104,7 +104,11 @@ public class ArrayDecoder<T> implements Decodeable<Reader, T[]> {
|
|||||||
return result.toArray(rs);
|
return result.toArray(rs);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Reader getArrayItemReader(Reader in, DeMember member, boolean first) {
|
protected boolean hasNext(Reader in, DeMember member, int startPosition, int contentLength, boolean first) {
|
||||||
|
return in.hasNext(startPosition, contentLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Reader getItemReader(Reader in, DeMember member, boolean first) {
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -89,8 +89,9 @@ public class CollectionDecoder<T> implements Decodeable<Reader, Collection<T>> {
|
|||||||
boolean first = true;
|
boolean first = true;
|
||||||
if (len == Reader.SIGN_NOLENGTH) {
|
if (len == Reader.SIGN_NOLENGTH) {
|
||||||
int startPosition = in.position();
|
int startPosition = in.position();
|
||||||
while (in.hasNext(this, member, startPosition, contentLength)) {
|
while (hasNext(in, member, startPosition, contentLength, first)) {
|
||||||
result.add(readMemberValue(in, member, first));
|
Reader itemReader = getItemReader(in, member, first);
|
||||||
|
result.add(readMemberValue(itemReader, member, first));
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -102,6 +103,14 @@ public class CollectionDecoder<T> implements Decodeable<Reader, Collection<T>> {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean hasNext(Reader in, DeMember member, int startPosition, int contentLength, boolean first) {
|
||||||
|
return in.hasNext(startPosition, contentLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Reader getItemReader(Reader in, DeMember member, boolean first) {
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
|
||||||
protected T readMemberValue(Reader in, DeMember member, boolean first) {
|
protected T readMemberValue(Reader in, DeMember member, boolean first) {
|
||||||
return this.decoder.convertFrom(in);
|
return this.decoder.convertFrom(in);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,8 +102,8 @@ public class MapDecoder<K, V> implements Decodeable<Reader, Map<K, V>> {
|
|||||||
boolean first = true;
|
boolean first = true;
|
||||||
if (len == Reader.SIGN_NOLENGTH) {
|
if (len == Reader.SIGN_NOLENGTH) {
|
||||||
int startPosition = in.position();
|
int startPosition = in.position();
|
||||||
while (in.hasNext(this, member, startPosition, contentLength)) {
|
while (hasNext(in, member, startPosition, contentLength, first)) {
|
||||||
Reader entryReader = getMapEntryReader(in, member, first);
|
Reader entryReader = getEntryReader(in, member, first);
|
||||||
K key = readKeyMember(entryReader, member, first);
|
K key = readKeyMember(entryReader, member, first);
|
||||||
entryReader.readBlank();
|
entryReader.readBlank();
|
||||||
V value = readValueMember(entryReader, member, first);
|
V value = readValueMember(entryReader, member, first);
|
||||||
@@ -123,7 +123,11 @@ public class MapDecoder<K, V> implements Decodeable<Reader, Map<K, V>> {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Reader getMapEntryReader(Reader in, DeMember member, boolean first) {
|
protected boolean hasNext(Reader in, DeMember member, int startPosition, int contentLength, boolean first) {
|
||||||
|
return in.hasNext(startPosition, contentLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Reader getEntryReader(Reader in, DeMember member, boolean first) {
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -222,7 +222,7 @@ public class ObjectDecoder<R extends Reader, T> implements Decodeable<R, T> {
|
|||||||
if (this.creatorConstructorMembers == null) { //空构造函数
|
if (this.creatorConstructorMembers == null) { //空构造函数
|
||||||
final T result = this.creator.create();
|
final T result = this.creator.create();
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
while (hasNext(in)) {
|
while (hasNext(in, first)) {
|
||||||
DeMember member = in.readFieldName(members);
|
DeMember member = in.readFieldName(members);
|
||||||
in.readBlank();
|
in.readBlank();
|
||||||
if (member == null) {
|
if (member == null) {
|
||||||
@@ -230,8 +230,8 @@ public class ObjectDecoder<R extends Reader, T> implements Decodeable<R, T> {
|
|||||||
} else {
|
} else {
|
||||||
readMemberValue(in, member, result, first);
|
readMemberValue(in, member, result, first);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
first = false;
|
first = false;
|
||||||
|
}
|
||||||
in.readObjectE(typeClass);
|
in.readObjectE(typeClass);
|
||||||
return result;
|
return result;
|
||||||
} else { //带参数的构造函数
|
} else { //带参数的构造函数
|
||||||
@@ -240,7 +240,7 @@ public class ObjectDecoder<R extends Reader, T> implements Decodeable<R, T> {
|
|||||||
final Object[][] otherParams = new Object[this.members.length][2];
|
final Object[][] otherParams = new Object[this.members.length][2];
|
||||||
int oc = 0;
|
int oc = 0;
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
while (hasNext(in)) {
|
while (hasNext(in, first)) {
|
||||||
DeMember member = in.readFieldName(members);
|
DeMember member = in.readFieldName(members);
|
||||||
in.readBlank();
|
in.readBlank();
|
||||||
if (member == null) {
|
if (member == null) {
|
||||||
@@ -269,7 +269,7 @@ public class ObjectDecoder<R extends Reader, T> implements Decodeable<R, T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean hasNext(R in) {
|
protected boolean hasNext(R in, boolean first) {
|
||||||
return in.hasNext();
|
return in.hasNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,14 +28,12 @@ public abstract class Reader {
|
|||||||
* 是否还存在下个元素或字段 <br>
|
* 是否还存在下个元素或字段 <br>
|
||||||
* 注意: 主要用于Array、Collection、Stream或Map等集合对象
|
* 注意: 主要用于Array、Collection、Stream或Map等集合对象
|
||||||
*
|
*
|
||||||
* @param self Decodeable
|
|
||||||
* @param member DeMember
|
|
||||||
* @param startPosition 起始位置
|
* @param startPosition 起始位置
|
||||||
* @param contentLength 内容大小, 不确定的传-1
|
* @param contentLength 内容大小, 不确定的传-1
|
||||||
*
|
*
|
||||||
* @return 是否还存在下个元素或字段
|
* @return 是否还存在下个元素或字段
|
||||||
*/
|
*/
|
||||||
public abstract boolean hasNext(Decodeable self, DeMember member, int startPosition, int contentLength);
|
public abstract boolean hasNext(int startPosition, int contentLength);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否还存在下个元素或字段
|
* 是否还存在下个元素或字段
|
||||||
@@ -44,7 +42,7 @@ public abstract class Reader {
|
|||||||
* @return 是否还存在下个元素或字段
|
* @return 是否还存在下个元素或字段
|
||||||
*/
|
*/
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
return hasNext(null, null, -1, -1);
|
return hasNext(-1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -85,8 +85,9 @@ public class StreamDecoder<T> implements Decodeable<Reader, Stream<T>> {
|
|||||||
boolean first = true;
|
boolean first = true;
|
||||||
if (len == Reader.SIGN_NOLENGTH) {
|
if (len == Reader.SIGN_NOLENGTH) {
|
||||||
int startPosition = in.position();
|
int startPosition = in.position();
|
||||||
while (in.hasNext(this, member, startPosition, contentLength)) {
|
while (hasNext(in, member, startPosition, contentLength, first)) {
|
||||||
result.add(readMemberValue(in, member, first));
|
Reader itemReader = getItemReader(in, member, first);
|
||||||
|
result.add(readMemberValue(itemReader, member, first));
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -98,6 +99,14 @@ public class StreamDecoder<T> implements Decodeable<Reader, Stream<T>> {
|
|||||||
return result.stream();
|
return result.stream();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean hasNext(Reader in, DeMember member, int startPosition, int contentLength, boolean first) {
|
||||||
|
return in.hasNext(startPosition, contentLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Reader getItemReader(Reader in, DeMember member, boolean first) {
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
|
||||||
protected T readMemberValue(Reader in, DeMember member, boolean first) {
|
protected T readMemberValue(Reader in, DeMember member, boolean first) {
|
||||||
return this.decoder.convertFrom(in);
|
return this.decoder.convertFrom(in);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -215,15 +215,13 @@ public class BsonReader extends Reader {
|
|||||||
/**
|
/**
|
||||||
* 判断对象是否存在下一个属性或者数组是否存在下一个元素
|
* 判断对象是否存在下一个属性或者数组是否存在下一个元素
|
||||||
*
|
*
|
||||||
* @param self Decodeable
|
|
||||||
* @param member DeMember
|
|
||||||
* @param startPosition 起始位置
|
* @param startPosition 起始位置
|
||||||
* @param contentLength 内容大小, 不确定的传-1
|
* @param contentLength 内容大小, 不确定的传-1
|
||||||
*
|
*
|
||||||
* @return 是否存在
|
* @return 是否存在
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNext(Decodeable self, DeMember member, int startPosition, int contentLength) {
|
public boolean hasNext(int startPosition, int contentLength) {
|
||||||
byte b = readByte();
|
byte b = readByte();
|
||||||
if (b == SIGN_HASNEXT) return true;
|
if (b == SIGN_HASNEXT) return true;
|
||||||
if (b != SIGN_NONEXT) throw new ConvertException("hasNext option must be (" + (SIGN_HASNEXT)
|
if (b != SIGN_NONEXT) throw new ConvertException("hasNext option must be (" + (SIGN_HASNEXT)
|
||||||
@@ -276,7 +274,7 @@ public class BsonReader extends Reader {
|
|||||||
int size = 0;
|
int size = 0;
|
||||||
byte[] data = new byte[8];
|
byte[] data = new byte[8];
|
||||||
int startPosition = position();
|
int startPosition = position();
|
||||||
while (hasNext(null, null, startPosition, contentLength)) {
|
while (hasNext(startPosition, contentLength)) {
|
||||||
if (size >= data.length) {
|
if (size >= data.length) {
|
||||||
byte[] newdata = new byte[data.length + 4];
|
byte[] newdata = new byte[data.length + 4];
|
||||||
System.arraycopy(data, 0, newdata, 0, size);
|
System.arraycopy(data, 0, newdata, 0, size);
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public final class BoolArraySimpledCoder<R extends Reader, W extends Writer> ext
|
|||||||
int size = 0;
|
int size = 0;
|
||||||
boolean[] data = new boolean[8];
|
boolean[] data = new boolean[8];
|
||||||
int startPosition = in.position();
|
int startPosition = in.position();
|
||||||
while (in.hasNext(this, null, startPosition, contentLength)) {
|
while (in.hasNext(startPosition, contentLength)) {
|
||||||
if (size >= data.length) {
|
if (size >= data.length) {
|
||||||
boolean[] newdata = new boolean[data.length + 4];
|
boolean[] newdata = new boolean[data.length + 4];
|
||||||
System.arraycopy(data, 0, newdata, 0, size);
|
System.arraycopy(data, 0, newdata, 0, size);
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public final class ByteBufferSimpledCoder<R extends Reader, W extends Writer> ex
|
|||||||
int size = 0;
|
int size = 0;
|
||||||
byte[] data = new byte[8];
|
byte[] data = new byte[8];
|
||||||
int startPosition = in.position();
|
int startPosition = in.position();
|
||||||
while (in.hasNext(this, null, startPosition, contentLength)) {
|
while (in.hasNext(startPosition, contentLength)) {
|
||||||
if (size >= data.length) {
|
if (size >= data.length) {
|
||||||
byte[] newdata = new byte[data.length + 4];
|
byte[] newdata = new byte[data.length + 4];
|
||||||
System.arraycopy(data, 0, newdata, 0, size);
|
System.arraycopy(data, 0, newdata, 0, size);
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public final class CharArraySimpledCoder<R extends Reader, W extends Writer> ext
|
|||||||
int size = 0;
|
int size = 0;
|
||||||
char[] data = new char[8];
|
char[] data = new char[8];
|
||||||
int startPosition = in.position();
|
int startPosition = in.position();
|
||||||
while (in.hasNext(this, null, startPosition, contentLength)) {
|
while (in.hasNext(startPosition, contentLength)) {
|
||||||
if (size >= data.length) {
|
if (size >= data.length) {
|
||||||
char[] newdata = new char[data.length + 4];
|
char[] newdata = new char[data.length + 4];
|
||||||
System.arraycopy(data, 0, newdata, 0, size);
|
System.arraycopy(data, 0, newdata, 0, size);
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public final class DoubleArraySimpledCoder<R extends Reader, W extends Writer> e
|
|||||||
int size = 0;
|
int size = 0;
|
||||||
double[] data = new double[8];
|
double[] data = new double[8];
|
||||||
int startPosition = in.position();
|
int startPosition = in.position();
|
||||||
while (in.hasNext(this, null, startPosition, contentLength)) {
|
while (in.hasNext(startPosition, contentLength)) {
|
||||||
if (size >= data.length) {
|
if (size >= data.length) {
|
||||||
double[] newdata = new double[data.length + 4];
|
double[] newdata = new double[data.length + 4];
|
||||||
System.arraycopy(data, 0, newdata, 0, size);
|
System.arraycopy(data, 0, newdata, 0, size);
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public final class FloatArraySimpledCoder<R extends Reader, W extends Writer> ex
|
|||||||
int size = 0;
|
int size = 0;
|
||||||
float[] data = new float[8];
|
float[] data = new float[8];
|
||||||
int startPosition = in.position();
|
int startPosition = in.position();
|
||||||
while (in.hasNext(this, null, startPosition, contentLength)) {
|
while (in.hasNext(startPosition, contentLength)) {
|
||||||
if (size >= data.length) {
|
if (size >= data.length) {
|
||||||
float[] newdata = new float[data.length + 4];
|
float[] newdata = new float[data.length + 4];
|
||||||
System.arraycopy(data, 0, newdata, 0, size);
|
System.arraycopy(data, 0, newdata, 0, size);
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public final class IntArraySimpledCoder<R extends Reader, W extends Writer> exte
|
|||||||
int size = 0;
|
int size = 0;
|
||||||
int[] data = new int[8];
|
int[] data = new int[8];
|
||||||
int startPosition = in.position();
|
int startPosition = in.position();
|
||||||
while (in.hasNext(this, null, startPosition, contentLength)) {
|
while (in.hasNext(startPosition, contentLength)) {
|
||||||
if (size >= data.length) {
|
if (size >= data.length) {
|
||||||
int[] newdata = new int[data.length + 4];
|
int[] newdata = new int[data.length + 4];
|
||||||
System.arraycopy(data, 0, newdata, 0, size);
|
System.arraycopy(data, 0, newdata, 0, size);
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public final class LongArraySimpledCoder<R extends Reader, W extends Writer> ext
|
|||||||
int size = 0;
|
int size = 0;
|
||||||
long[] data = new long[8];
|
long[] data = new long[8];
|
||||||
int startPosition = in.position();
|
int startPosition = in.position();
|
||||||
while (in.hasNext(this, null, startPosition, contentLength)) {
|
while (in.hasNext(startPosition, contentLength)) {
|
||||||
if (size >= data.length) {
|
if (size >= data.length) {
|
||||||
long[] newdata = new long[data.length + 4];
|
long[] newdata = new long[data.length + 4];
|
||||||
System.arraycopy(data, 0, newdata, 0, size);
|
System.arraycopy(data, 0, newdata, 0, size);
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public final class ShortArraySimpledCoder<R extends Reader, W extends Writer> ex
|
|||||||
int size = 0;
|
int size = 0;
|
||||||
short[] data = new short[8];
|
short[] data = new short[8];
|
||||||
int startPosition = in.position();
|
int startPosition = in.position();
|
||||||
while (in.hasNext(this, null, startPosition, contentLength)) {
|
while (in.hasNext(startPosition, contentLength)) {
|
||||||
if (size >= data.length) {
|
if (size >= data.length) {
|
||||||
short[] newdata = new short[data.length + 4];
|
short[] newdata = new short[data.length + 4];
|
||||||
System.arraycopy(data, 0, newdata, 0, size);
|
System.arraycopy(data, 0, newdata, 0, size);
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public final class StringArraySimpledCoder<R extends Reader, W extends Writer> e
|
|||||||
int size = 0;
|
int size = 0;
|
||||||
String[] data = new String[8];
|
String[] data = new String[8];
|
||||||
int startPosition = in.position();
|
int startPosition = in.position();
|
||||||
while (in.hasNext(this, member, startPosition, contentLength)) {
|
while (in.hasNext(startPosition, contentLength)) {
|
||||||
if (size >= data.length) {
|
if (size >= data.length) {
|
||||||
String[] newdata = new String[data.length + 4];
|
String[] newdata = new String[data.length + 4];
|
||||||
System.arraycopy(data, 0, newdata, 0, size);
|
System.arraycopy(data, 0, newdata, 0, size);
|
||||||
|
|||||||
@@ -159,15 +159,13 @@ public class JsonByteBufferReader extends JsonReader {
|
|||||||
/**
|
/**
|
||||||
* 判断对象是否存在下一个属性或者数组是否存在下一个元素
|
* 判断对象是否存在下一个属性或者数组是否存在下一个元素
|
||||||
*
|
*
|
||||||
* @param self Decodeable
|
|
||||||
* @param member DeMember
|
|
||||||
* @param startPosition 起始位置
|
* @param startPosition 起始位置
|
||||||
* @param contentLength 内容大小, 不确定的传-1
|
* @param contentLength 内容大小, 不确定的传-1
|
||||||
*
|
*
|
||||||
* @return 是否存在
|
* @return 是否存在
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNext(Decodeable self, DeMember member, int startPosition, int contentLength) {
|
public boolean hasNext(int startPosition, int contentLength) {
|
||||||
char ch = nextGoodChar();
|
char ch = nextGoodChar();
|
||||||
if (ch == ',') return true;
|
if (ch == ',') return true;
|
||||||
if (ch == '}' || ch == ']' || ch == 0) return false;
|
if (ch == '}' || ch == ']' || ch == 0) return false;
|
||||||
|
|||||||
@@ -263,15 +263,13 @@ public class JsonReader extends Reader {
|
|||||||
/**
|
/**
|
||||||
* 判断对象是否存在下一个属性或者数组是否存在下一个元素
|
* 判断对象是否存在下一个属性或者数组是否存在下一个元素
|
||||||
*
|
*
|
||||||
* @param self Decodeable
|
|
||||||
* @param member DeMember
|
|
||||||
* @param startPosition 起始位置
|
* @param startPosition 起始位置
|
||||||
* @param contentLength 内容大小, 不确定的传-1
|
* @param contentLength 内容大小, 不确定的传-1
|
||||||
*
|
*
|
||||||
* @return 是否存在
|
* @return 是否存在
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNext(Decodeable self, DeMember member, int startPosition, int contentLength) {
|
public boolean hasNext(int startPosition, int contentLength) {
|
||||||
char ch = this.text[++this.position];
|
char ch = this.text[++this.position];
|
||||||
if (ch == ',') return true;
|
if (ch == ',') return true;
|
||||||
if (ch == '}' || ch == ']') return false;
|
if (ch == '}' || ch == ']') return false;
|
||||||
@@ -487,7 +485,7 @@ public class JsonReader extends Reader {
|
|||||||
int size = 0;
|
int size = 0;
|
||||||
byte[] data = new byte[8];
|
byte[] data = new byte[8];
|
||||||
int startPosition = position();
|
int startPosition = position();
|
||||||
while (hasNext(null, null, startPosition, contentLength)) {
|
while (hasNext(startPosition, contentLength)) {
|
||||||
if (size >= data.length) {
|
if (size >= data.length) {
|
||||||
byte[] newdata = new byte[data.length + 4];
|
byte[] newdata = new byte[data.length + 4];
|
||||||
System.arraycopy(data, 0, newdata, 0, size);
|
System.arraycopy(data, 0, newdata, 0, size);
|
||||||
|
|||||||
Reference in New Issue
Block a user