Skip to content

Commit

Permalink
changes for fast-cast 2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
RuedigerMoeller committed Mar 16, 2014
1 parent fa94b89 commit 284a627
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 2 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="1.42"
version="1.5"


jar.baseName='fst'
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>1.42</version>
<version>1.5</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
67 changes: 67 additions & 0 deletions src/main/java/de/ruedigermoeller/serialization/FSTObjectInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,73 @@ public String readStringAsc() throws IOException {
return new String(ascStringCache,0,0,len);
}

/**
* utility for fast-cast
* @param componentType
* @param len
* @return
*/
public Object readFPrimitiveArray( Class componentType, int len ) {
try {
Object array = Array.newInstance(componentType, len);
if (componentType == byte.class) {
byte[] arr = (byte[]) array;
ensureReadAhead(arr.length); // fixme: move this stuff to the stream !
read(arr);
return arr;
} else if (componentType == char.class) {
char[] arr = (char[]) array;
for (int j = 0; j < len; j++) {
arr[j] = readCChar();
}
return arr;
} else if (componentType == short.class) {
short[] arr = (short[]) array;
ensureReadAhead(arr.length*2);
for (int j = 0; j < len; j++) {
arr[j] = readFShort();
}
return arr;
} else if (componentType == int.class) {
final int[] arr = (int[]) array;
readFIntArr(len, arr);
return arr;
} else if (componentType == float.class) {
float[] arr = (float[]) array;
ensureReadAhead(arr.length*4);
for (int j = 0; j < len; j++) {
arr[j] = readFFloat();
}
return arr;
} else if (componentType == double.class) {
double[] arr = (double[]) array;
ensureReadAhead(arr.length*8);
for (int j = 0; j < len; j++) {
arr[j] = readFDouble();
}
return arr;
} else if (componentType == long.class) {
long[] arr = (long[]) array;
ensureReadAhead(arr.length*8);
for (int j = 0; j < len; j++) {
arr[j] = readFLong();
}
return arr;
} else if (componentType == boolean.class) {
boolean[] arr = (boolean[]) array;
ensureReadAhead(arr.length);
for (int j = 0; j < len; j++) {
arr[j] = readBoolean();
}
return arr;
} else {
throw new RuntimeException("unexpected primitive type " + componentType);
}
} catch (IOException e) {
throw FSTUtil.rethrow(e); //To change body of catch statement use File | Settings | File Templates.
}
}

protected Object readArray(FSTClazzInfo.FSTFieldInfo referencee) throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException {
Class arrCl = readClass().getClazz();
final int len = readCInt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,10 @@ public void writeCCharArr(char[] arr) throws IOException {
writeCChar(arr[i]);
}

public void writeFByteArr(byte[] array) throws IOException {
writeFByteArr(array,0,array.length);
}

/**
* does not write length, just plain bytes
* @param array
Expand Down

0 comments on commit 284a627

Please sign in to comment.