org.mapdb.serializer.SerializerString Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mapdb Show documentation
Show all versions of mapdb Show documentation
MapDB provides concurrent Maps, Sets and Queues backed by disk storage or off-heap memory. It is a fast, scalable and easy to use embedded Java database.
package org.mapdb.serializer;
import org.mapdb.DataInput2;
import org.mapdb.DataOutput2;
import org.mapdb.Serializer;
import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;
public class SerializerString implements GroupSerializer {
@Override
public void serialize(DataOutput2 out, String value) throws IOException {
out.writeUTF(value);
}
@Override
public String deserialize(DataInput2 in, int available) throws IOException {
return in.readUTF();
}
@Override
public boolean isTrusted() {
return true;
}
@Override
public void valueArraySerialize(DataOutput2 out2, Object vals) throws IOException {
for(char[] v:(char[][])vals){
out2.packInt(v.length);
for(char c:v){
out2.packInt(c);
}
}
}
@Override
public char[][] valueArrayDeserialize(DataInput2 in2, int size) throws IOException {
char[][] ret = new char[size][];
for(int i=0;i>> 1;
int compare = comparator.compare(key, new String(array[mid]));
if (compare == 0)
return mid;
else if (compare < 0)
hi = mid - 1;
else
lo = mid + 1;
}
return -(lo + 1);
}
@Override
public String valueArrayGet(Object vals, int pos) {
return new String(((char[][])vals)[pos]);
}
@Override
public int valueArraySize(Object vals) {
return ((char[][])vals).length;
}
@Override
public char[][] valueArrayEmpty() {
return new char[0][];
}
@Override
public char[][] valueArrayPut(Object vals, int pos, String newValue) {
char[][] array = (char[][]) vals;
final char[][] ret = Arrays.copyOf(array, array.length+1);
if(pos