Package com.onpositive.gae.baseviewer.io

Source Code of com.onpositive.gae.baseviewer.io.EntityAccess

package com.onpositive.gae.baseviewer.io;

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);
  }
 
  public void toXML(Entity e){
   
  }
}
TOP

Related Classes of com.onpositive.gae.baseviewer.io.EntityAccess

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.