package com.onpositive.gae.baseviewer.impl;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.EntityTranslator;
import com.google.storage.onestore.v3.OnestoreEntity.EntityProto;
public class EntityAccess {
public static void writeEntityToStream(Entity ent, DataOutputStream stream)
throws IOException {
byte[] byteArray = EntityTranslator.convertToPb(ent).toByteArray();
stream.writeInt(byteArray.length);
stream.write(byteArray);
}
public static Entity read(DataInputStream stream) throws IOException {
int readInt = stream.readInt();
byte[] arr = new byte[readInt];
stream.readFully(arr);
EntityProto pr = new EntityProto();
pr.mergeFrom(arr);
return EntityTranslator.createFromPb(pr);
}
}