Kryo kryo = new Kryo();
Output output = null;
try
{
kryo = kryos.get();
kryo.register(Codes.class,new CompatibleFieldSerializer(kryo,Codes.class));
kryo.register(ArrayList.class,new CollectionSerializer());
kryo.register(String.class);
RandomAccessFile raf = new RandomAccessFile(f, "rw");
output = new Output(new BufferedOutputStream(new FileOutputStream(raf.getFD()), bufferSize));
kryo.writeObject(output, myObject);
System.out.println("Writing in file with Kryo...............");
} finally
{
if (output != null)
{
output.close();
}
}
output.close();
try{
code_from_file.clear();
kryo = kryos.get();
kryo.register(Codes.class,new CompatibleFieldSerializer(kryo,Codes.class));
kryo.register(ArrayList.class,new CollectionSerializer());
kryo.register(String.class);
RandomAccessFile raf = new RandomAccessFile(f, "rw");
input = new Input(new BufferedInputStream(new FileInputStream(raf.getFD()), bufferSize));
Codes obj = new Codes();
while( (obj = (Codes) kryo.readObject(input, Codes.class)) != null)
{
if(obj instanceof Codes)
{
code_from_file.add(obj);
}
System.out.println("obj : " + obj.toString());
}
}catch (EOFException ex)
{
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
} finally
{
if (input != null)
{
input.close();
}
}
input.close();
private static ThreadLocal<Kryo> kryos = new ThreadLocal<Kryo>() {
protected Kryo initialValue() {
Kryo kryo = new Kryo();
// configure kryo instance, customize settings
return kryo;
};
};