diff --git a/build.gradle b/build.gradle
index 1c1bcd5d..96e8db20 100644
--- a/build.gradle
+++ b/build.gradle
@@ -2,7 +2,7 @@ import java.util.zip.ZipFile
apply plugin: 'java'
apply plugin: 'maven'
-version="2.23"
+version="2.24"
targetCompatibility = 1.7
sourceCompatibility = 1.7
diff --git a/pom.xml b/pom.xml
index 93216ff6..ec667ed0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
4.0.0
de.ruedigermoeller
fst
- 2.23
+ 2.24
a fast java serialization drop in-replacement + some serialization based utils (Structs, OffHeap Memory)
https://code.google.com/p/fast-serialization/
diff --git a/src/main/java/org/nustaq/serialization/FSTDecoder.java b/src/main/java/org/nustaq/serialization/FSTDecoder.java
index 5214427c..23de6fb1 100644
--- a/src/main/java/org/nustaq/serialization/FSTDecoder.java
+++ b/src/main/java/org/nustaq/serialization/FSTDecoder.java
@@ -31,6 +31,7 @@ public interface FSTDecoder {
double readFDouble() throws IOException;
float readFFloat() throws IOException;
byte readFByte() throws IOException;
+ int readIntByte() throws IOException;
long readFLong() throws IOException;
char readFChar() throws IOException;
short readFShort() throws IOException;
@@ -40,7 +41,7 @@ public interface FSTDecoder {
int getInputPos();
void moveTo(int position);
void setInputStream(InputStream in);
- void ensureReadAhead(int bytes);
+ int ensureReadAhead(int bytes); // might signal eof by returning -1, depends on decoder impl though
void reset();
void resetToCopyOf(byte[] bytes, int off, int len);
diff --git a/src/main/java/org/nustaq/serialization/FSTObjectInput.java b/src/main/java/org/nustaq/serialization/FSTObjectInput.java
index 337f43a5..5fde7611 100644
--- a/src/main/java/org/nustaq/serialization/FSTObjectInput.java
+++ b/src/main/java/org/nustaq/serialization/FSTObjectInput.java
@@ -243,7 +243,7 @@ public Object readObject() throws ClassNotFoundException, IOException {
@Override
public int read() throws IOException {
- return getCodec().readFByte();
+ return getCodec().readIntByte();
}
@Override
diff --git a/src/main/java/org/nustaq/serialization/coders/FSTBytezDecoder.java b/src/main/java/org/nustaq/serialization/coders/FSTBytezDecoder.java
index 019602fc..d28a380e 100644
--- a/src/main/java/org/nustaq/serialization/coders/FSTBytezDecoder.java
+++ b/src/main/java/org/nustaq/serialization/coders/FSTBytezDecoder.java
@@ -61,17 +61,18 @@ public FSTBytezDecoder(FSTConfiguration conf) {
}
byte tmp[];
- public void ensureReadAhead(int bytes) {
+ public int ensureReadAhead(int bytes) {
if ( inputStream != null ) {
if ( pos+bytes > readUntil ) {
- readNextInputChunk(bytes);
+ return readNextInputChunk(bytes);
}
} else if ( pos+bytes > input.length() ) {
-// throw FSTBufferTooSmallException.Instance;
+ return -1;
}
+ return 0;
}
- protected void readNextInputChunk(int bytes) {
+ protected int readNextInputChunk(int bytes) {
try {
int toRead = Math.max(Integer.MAX_VALUE, bytes);
if ( inputStream instanceof ByteArrayInputStream ) {
@@ -89,10 +90,14 @@ protected void readNextInputChunk(int bytes) {
}
input.set(pos,tmp,0,read);
readUntil = pos+read;
- }
+ return read;
+ } else if ( read == -1 )
+ return -1;
+ // fixme: should loop in case read == 0
} catch (IOException e) {
throw FSTUtil.rethrow(e);
}
+ return 0;
}
char chBufS[];
@@ -237,6 +242,14 @@ public final byte readFByte() throws IOException {
return input.get(pos++);
}
+ @Override
+ public int readIntByte() throws IOException {
+ final int res = ensureReadAhead(1);
+ if ( res == -1 )
+ return -1;
+ return input.get(pos++) & 0xff;
+ }
+
@Override
public long readFLong() throws IOException {
return readPlainLong();
diff --git a/src/main/java/org/nustaq/serialization/coders/FSTMinBinDecoder.java b/src/main/java/org/nustaq/serialization/coders/FSTMinBinDecoder.java
index 5ae54791..ccc617c5 100644
--- a/src/main/java/org/nustaq/serialization/coders/FSTMinBinDecoder.java
+++ b/src/main/java/org/nustaq/serialization/coders/FSTMinBinDecoder.java
@@ -131,6 +131,11 @@ public byte readFByte() throws IOException {
return (byte) input.readInt();
}
+ @Override
+ public int readIntByte() throws IOException {
+ return (int) input.readInt();
+ }
+
@Override
public long readFLong() throws IOException {
return input.readInt();
@@ -202,7 +207,8 @@ public void setInputStream(InputStream in) {
}
@Override
- public void ensureReadAhead(int bytes) {
+ public int ensureReadAhead(int bytes) {
+ return 0;
}
@Override
diff --git a/src/main/java/org/nustaq/serialization/coders/FSTStreamDecoder.java b/src/main/java/org/nustaq/serialization/coders/FSTStreamDecoder.java
index 97a78e76..234f10c1 100644
--- a/src/main/java/org/nustaq/serialization/coders/FSTStreamDecoder.java
+++ b/src/main/java/org/nustaq/serialization/coders/FSTStreamDecoder.java
@@ -45,8 +45,9 @@ public FSTStreamDecoder(FSTConfiguration conf) {
}
}
- public void ensureReadAhead(int bytes) {
+ public int ensureReadAhead(int bytes) {
input.ensureReadAhead(bytes);
+ return 0; // checking for eof too expensive ..
}
char chBufS[];
@@ -249,6 +250,14 @@ public final byte readFByte() throws IOException {
return input.buf[input.pos++];
}
+ @Override
+ public final int readIntByte() throws IOException {
+ input.ensureReadAhead(1);
+ if ( input.isFullyRead() )
+ return -1;
+ return input.buf[input.pos++] & 0xff;
+ }
+
@Override
public long readFLong() throws IOException {
input.ensureReadAhead(9);
diff --git a/src/main/java/org/nustaq/serialization/util/FSTInputStream.java b/src/main/java/org/nustaq/serialization/util/FSTInputStream.java
index 4d5ff2ee..7b98edd2 100644
--- a/src/main/java/org/nustaq/serialization/util/FSTInputStream.java
+++ b/src/main/java/org/nustaq/serialization/util/FSTInputStream.java
@@ -55,6 +55,10 @@ public void initFromStream(InputStream in) {
readNextChunk(in);
}
+ public boolean isFullyRead() {
+ return fullyRead && pos >= count;
+ }
+
public void readNextChunk(InputStream in) {
int read;
try {
diff --git a/src/test/ser/SpecialsTest.java b/src/test/ser/SpecialsTest.java
index 5149f723..36ed5cea 100644
--- a/src/test/ser/SpecialsTest.java
+++ b/src/test/ser/SpecialsTest.java
@@ -9,11 +9,8 @@
import javax.security.auth.Subject;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
-import java.io.File;
-import java.io.IOException;
-import java.io.Serializable;
+import java.io.*;
import java.math.BigDecimal;
-import java.net.Inet6Address;
import java.net.InetAddress;
import java.util.Collections;
import java.util.HashSet;
@@ -85,6 +82,36 @@ public void test( FSTConfiguration conf, Serializable toTest ) {
}
+ @Test
+ public void testReadByte() throws IOException {
+
+ final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ final ByteArrayOutputStream fstbaos = new ByteArrayOutputStream();
+
+ ObjectOutputStream oout = new ObjectOutputStream(baos);
+ writebytes(baos,oout);
+
+ FSTObjectOutput fsto = new FSTObjectOutput(fstbaos);
+ writebytes(fstbaos,fsto);
+
+ ObjectInputStream oin = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
+ FSTObjectInput fstin = new FSTObjectInput(new ByteArrayInputStream(fstbaos.toByteArray()));
+ int rd;
+ while( (rd=oin.read()) != -1 ) {
+ Assert.assertTrue(rd == fstin.read() );
+ }
+ Assert.assertTrue( fstin.read() == -1 );
+ }
+
+ private void writebytes(ByteArrayOutputStream baos, ObjectOutput oout) throws IOException {
+ int written[] = { 1, -13, 13, 127, 128, 129, -127, -128, -129, -1, 99, 199, };
+ for (int i = 0; i < written.length; i++) {
+ oout.write(written[i]);
+ }
+ oout.close();
+ }
+
@Test
public void main() throws Exception {
boolean succ = true;