Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
RuedigerMoeller committed May 29, 2015
1 parent 4c597a3 commit 3a0f0a1
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 22 deletions.
12 changes: 10 additions & 2 deletions src/main/java/org/nustaq/serialization/coders/FSTJsonDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,10 @@ public void resetToCopyOf(byte[] bytes, int off, int len) {
throw new RuntimeException("not supported");
byte b[] = new byte[len];
System.arraycopy(bytes,off,b,0,len);
fstInput = new FSTInputStream(b);
if ( fstInput == null )
fstInput = new FSTInputStream(b);
else
fstInput.resetForReuse(bytes,len);
try {
createParser();
} catch (IOException e) {
Expand All @@ -244,7 +247,12 @@ public void createParser() throws IOException {

@Override
public void resetWith(byte[] bytes, int len) {
fstInput = new FSTInputStream(bytes,0,len);
if ( fstInput == null ) {
fstInput = new FSTInputStream(bytes,0,len);
}
else {
fstInput.resetForReuse(bytes,len);
}
try {
createParser();
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,14 +354,15 @@ protected String classToString(Class clz) {
@Override
public void writeAttributeName(FSTClazzInfo.FSTFieldInfo subInfo) {
try {
if ( gen.getOutputContext().inArray() )
gen.writeString(subInfo.getName());
SerializedString bufferedName = (SerializedString) subInfo.getBufferedName();
if ( bufferedName == null ) {
bufferedName = new SerializedString(subInfo.getName());
subInfo.setBufferedName(bufferedName);
}
if ( gen.getOutputContext().inArray() ) {
gen.writeString(bufferedName);
}
else {
SerializedString bufferedName = (SerializedString) subInfo.getBufferedName();
if ( bufferedName == null ) {
bufferedName = new SerializedString(subInfo.getName());
subInfo.setBufferedName(bufferedName);
}
gen.writeFieldName(bufferedName);
}
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,11 +448,12 @@ public void resetToCopyOf(byte[] bytes, int off, int len) {
@Override
public void resetWith(byte[] bytes, int len) {
clnames.clear();
input.reset();
input.count = len;
input.buf = bytes;
input.pos = 0;
input.byteBacked = true;
input.resetForReuse(bytes,len);
// input.reset();
// input.count = len;
// input.buf = bytes;
// input.pos = 0;
// input.byteBacked = true;
}

@Override
Expand Down
19 changes: 13 additions & 6 deletions src/main/java/org/nustaq/serialization/util/FSTInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,22 @@ public final class FSTInputStream extends InputStream {
public int pos;
public int count; // avaiable valid read bytes
InputStream in;
boolean fullyRead = false;
boolean fullyRead = false; // true if input source has been read til end
public boolean byteBacked = false;

public FSTInputStream(InputStream in) {
initFromStream(in);
}

public void resetForReuse( byte b[], int length ) {
reset();
count = length;
buf = b;
pos = 0;
byteBacked = true;
fullyRead = true;
}

public void initFromStream(InputStream in) {
fullyRead = false;
byteBacked = false;
Expand Down Expand Up @@ -77,7 +86,7 @@ public void readNextChunk(InputStream in) {
}

public void ensureCapacity(int siz) {
if (buf.length < siz) {
if (buf.length < siz && ! fullyRead) {
byte newBuf[] = new byte[siz];
System.arraycopy(buf, 0, newBuf, 0, buf.length);
buf = newBuf;
Expand Down Expand Up @@ -110,12 +119,10 @@ public int read() {
}

public int read(byte b[], int off, int len) {
if (fullyRead)
if (isFullyRead())
return -1;
while (pos + len >= count) {
while (! fullyRead && pos + len >= count) {
readNextChunk(in);
if (fullyRead)
break;
}
int avail = count - pos;
if (len > avail) {
Expand Down
4 changes: 2 additions & 2 deletions src/test/ser/Play.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public static void main(String[] args) {
byte[] bytes = conf.asByteArray(p);
Object deser = conf.asObject(bytes);
System.out.println(DeepEquals.deepEquals(p,deser));
// while( true )
// sb(conf);
while( true )
sb(conf);
}

protected static void sb(FSTConfiguration conf) {
Expand Down

0 comments on commit 3a0f0a1

Please sign in to comment.