Skip to content

Commit

Permalink
fix #39 bump version 2.14. fix bug in some exception handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
RuedigerMoeller committed Nov 20, 2014
1 parent e3e7013 commit 123cd07
Show file tree
Hide file tree
Showing 16 changed files with 143 additions and 28 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import java.util.zip.ZipFile

apply plugin: 'java'
apply plugin: 'maven'
version="2.13"
version="2.14"

targetCompatibility = 1.7
sourceCompatibility = 1.7
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.ruedigermoeller</groupId>
<artifactId>fst</artifactId>
<version>2.13</version>
<version>2.14</version>

<description>a fast java serialization drop in-replacement + some serialization based utils (Structs, OffHeap Memory)</description>
<url>https://code.google.com/p/fast-serialization/</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public ByteSource encodeValue(V value) {
tmpVal.setLen(buffer.length);
return encodeValue(value);
} catch (Exception e) {
FSTUtil.rethrow(e);
throw FSTUtil.rethrow(e);
}
return tmpVal;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public static FSTConfiguration createDefaultConfiguration() {
reg.putSerializer(HashSet.class, new FSTCollectionSerializer(), false); // subclass should register manually
reg.putSerializer(HashMap.class, new FSTMapSerializer(), false); // subclass should register manually
reg.putSerializer(LinkedHashMap.class, new FSTMapSerializer(), false); // subclass should register manually
reg.putSerializer(Hashtable.class, new FSTMapSerializer(), false); // subclass should register manually
reg.putSerializer(Hashtable.class, new FSTMapSerializer(), true); // subclass should register manually
reg.putSerializer(ConcurrentHashMap.class, new FSTMapSerializer(), true); // subclass should register manually
reg.putSerializer(FSTStruct.class, new FSTStructSerializer(), true); // subclasses also use this
return conf;
Expand Down
17 changes: 14 additions & 3 deletions src/main/java/org/nustaq/serialization/FSTObjectInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ protected Object instantiateAndReadNoSer(Class c, FSTClazzInfo clzSerInfo, FSTCl
final Object prevNew = newObj;
newObj = handleReadRessolve(clzSerInfo, newObj);
if ( newObj != prevNew && needsRefLookup ) {
objects.replace(prevNew,newObj,tmp);
objects.replace(prevNew, newObj, tmp);
}
}
} else if (clzSerInfo.useCompatibleMode())
Expand Down Expand Up @@ -573,8 +573,19 @@ protected void readObjectCompatibleRecursive(FSTClazzInfo.FSTFieldInfo reference
{
// came from writeMethod, but no readMethod defined => assume defaultWriteObject
tag = readByte(); // consume tag of defaultwriteobject (99)
// if ( tag != 99 )
// System.out.println("weird stuff incoming");
if ( tag == 77 ) // came from putfield
{
HashMap<String, Object> fieldMap = (HashMap<String, Object>) FSTObjectInput.this.readObjectInternal(HashMap.class);
final FSTClazzInfo.FSTFieldInfo[] fieldArray = fstCompatibilityInfo.getFieldArray();
for (int i = 0; i < fieldArray.length; i++) {
FSTClazzInfo.FSTFieldInfo fstFieldInfo = fieldArray[i];
final Object val = fieldMap.get(fstFieldInfo.getField().getName());
if ( val != null ) {
fstFieldInfo.setObjectValue(toRead,val);
}
}
return;
}
}
readObjectFields(referencee, serializationInfo, fstCompatibilityInfo.getFieldArray(), toRead,0,0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected void readNextInputChunk(int bytes) {
readUntil = pos+read;
}
} catch (IOException e) {
FSTUtil.rethrow(e);
throw FSTUtil.rethrow(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public void writeInt32At(int position, int v) {
try {
ensureFree( position+4);
} catch (IOException e) {
FSTUtil.rethrow(e);
throw FSTUtil.rethrow(e);
}
buffout.putInt(position,v);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public int toByteArray( Object obj, byte result[], int resultOffset, int avaiabl
try {
output.writeObject(obj);
} catch (IOException e) {
FSTUtil.rethrow(e);
throw FSTUtil.rethrow(e);
}
int written = output.getWritten();
if ( written > avaiableSize ) {
Expand All @@ -74,7 +74,7 @@ public byte[] toByteArray( Object o ) {
try {
output.writeObject(o);
} catch (IOException e) {
FSTUtil.rethrow(e);
throw FSTUtil.rethrow(e);
}
return output.getCopyOfWrittenBuffer();
}
Expand All @@ -94,9 +94,8 @@ public Object toObject( byte arr[], int off, int len ) {
}
return input.readObject();
} catch (Exception e) {
FSTUtil.rethrow(e);
throw FSTUtil.rethrow(e);
}
return null;
}

public Object toObject( byte arr[] ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public int toByteArray( Object o, byte arr[], int startIndex, int availableSize
try {
out.writeObject(o);
} catch (IOException e) {
FSTUtil.rethrow(e);
throw FSTUtil.rethrow(e);
}
int written = out.getWritten();
return written;
Expand All @@ -107,7 +107,7 @@ public byte[] toByteArray(Object o) {
try {
out.writeObject(o);
} catch (IOException e) {
FSTUtil.rethrow(e);
throw FSTUtil.rethrow(e);
}
return out.getCopyOfWrittenBuffer();
} catch (FSTBufferTooSmallException ex) {
Expand Down Expand Up @@ -138,9 +138,8 @@ public Object toObject( byte arr[], int startIndex, int availableSize) {
Object o = in.readObject();
return o;
} catch (Exception e) {
FSTUtil.rethrow(e);
throw FSTUtil.rethrow(e);
}
return null;
}

/**
Expand Down
106 changes: 106 additions & 0 deletions src/test/ser/GitHub39.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package ser;

import com.cedarsoftware.util.DeepEquals;
import junit.framework.Assert;
import org.junit.Test;
import org.nustaq.serialization.FSTConfiguration;
import org.nustaq.serialization.FSTObjectInput;
import org.nustaq.serialization.FSTObjectOutput;
import org.nustaq.serialization.serializers.FSTCollectionSerializer;

import java.io.IOException;
import java.io.Serializable;
import java.util.Stack;

/**
* Created by ruedi on 20.11.2014.
*/
public class GitHub39 {

static class OneStackClass implements Serializable {

Stack<String> a;

public OneStackClass(Stack<String> a) {
this.a = a;
}
}

static class TwoStackClass implements Serializable {

Stack<String> a;
Stack<String> b;

public TwoStackClass(Stack<String> a, Stack<String> b) {
this.a = a;
this.b = b;
}
}

@Test
public void test() {

OneStackClass osc = new OneStackClass(new Stack<String>());
byte[] mywriteMethod1 = FSTSerialization.mywriteMethod(osc);
OneStackClass myreadMethod1 = FSTSerialization.myreadMethod(mywriteMethod1, OneStackClass.class);
Assert.assertTrue(DeepEquals.deepEquals(osc,myreadMethod1));
//
TwoStackClass tsc = new TwoStackClass(new Stack<String>(), new Stack<String>());
byte[] mywriteMethod2 = FSTSerialization.mywriteMethod(tsc);
TwoStackClass myreadMethod2 = FSTSerialization.myreadMethod(mywriteMethod2, TwoStackClass.class);
Assert.assertTrue(DeepEquals.deepEquals(tsc,myreadMethod2));

}

static public class FSTSerialization {

final static FSTConfiguration configuration;

public static FSTConfiguration getConfiguration() {
return configuration;
}

static {
configuration = FSTConfiguration.createDefaultConfiguration();
// configuration.setShareReferences(true);
// configuration.registerSerializer(Stack.class,new FSTCollectionSerializer(), true);
configuration.registerClass(
Stack.class,
String.class
);
}

public static <T> T myreadMethod(byte[] stream, Class<T> c) {
FSTObjectInput in = configuration.getObjectInput(stream);
T result = null;
try {
result = (T) in.readObject(c);
} catch (Exception ex) {
ex.printStackTrace();
}
return result;
}

@SuppressWarnings("null")
public static byte[] mywriteMethod(Object toWrite) {
return mywriteMethod(null, toWrite);
}

public static byte[] mywriteMethod(byte[] stream, Object toWrite) {
FSTObjectOutput out = configuration.getObjectOutput(stream);
try {
out.writeObject(toWrite, toWrite.getClass());
} catch (IOException ex) {
ex.printStackTrace();
}
try {
out.flush();
} catch (IOException ex) {
ex.printStackTrace();
}
return out.getBuffer();
}

}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package unit.tests;
package ser.unit.tests;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand All @@ -13,8 +13,8 @@
import org.nustaq.serialization.FSTConfiguration;
import org.nustaq.serialization.FSTObjectOutput;

import unit.tests.externalizable.BeanTestClass1;
import unit.tests.externalizable.ExternalizableTestClass;
import ser.unit.tests.externalizable.BeanTestClass1;
import ser.unit.tests.externalizable.ExternalizableTestClass;

public class TestFastSerializationBean1 {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package unit.tests;
package ser.unit.tests;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand All @@ -15,8 +15,8 @@
import org.nustaq.serialization.FSTConfiguration;
import org.nustaq.serialization.FSTObjectOutput;

import unit.tests.externalizable.BeanTestClass2;
import unit.tests.externalizable.ExternalizableTestClass;
import ser.unit.tests.externalizable.BeanTestClass2;
import ser.unit.tests.externalizable.ExternalizableTestClass;

public class TestFastSerializationBean2 {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package unit.tests;
package ser.unit.tests;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand All @@ -15,7 +15,7 @@
import org.nustaq.serialization.FSTConfiguration;
import org.nustaq.serialization.FSTObjectOutput;

import unit.tests.externalizable.ExternalizableTestClass;
import ser.unit.tests.externalizable.ExternalizableTestClass;

public class TestFastSerializationList {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package unit.tests.externalizable;
package ser.unit.tests.externalizable;

import java.io.Serializable;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package unit.tests.externalizable;
package ser.unit.tests.externalizable;

import java.io.Serializable;
import java.util.Set;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package unit.tests.externalizable;
package ser.unit.tests.externalizable;
import java.io.*;

public class ExternalizableTestClass implements Externalizable {
Expand Down

0 comments on commit 123cd07

Please sign in to comment.