示例#1
0
 public int writeObject(BigtableData o) {
   int size = o.toByteArray().length;
   try {
     out.write(size);
     out.write(o.toByteArray());
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
     return 0;
   }
   return size;
 }
示例#2
0
  public static void main(String[] args) {

    String path = "/data/test/test.pb";
    ProtoWriter pwriter = new ProtoWriter();
    pwriter.openFile(path);

    // TODO Auto-generated method stub
    BigtableData.Builder data = BigtableData.newBuilder();
    data.setPrimaryKey("ttt");
    data.addLevelValues(12);
    data.addLevelValues(123);
    data.addLevelValues(124);
    data.addLevelValues(125);
    data.addLevelValues(126);
    pwriter.writeObject(data.build());

    data = BigtableData.newBuilder();
    data.setPrimaryKey("kkk");
    data.addLevelValues(12);
    data.addLevelValues(123);
    pwriter.writeObject(data.build());
    pwriter.close();

    ProtoReader preader = new ProtoReader();
    preader.openFile(path);
    BigtableData tt = preader.readObject();
    System.out.println("key: " + tt.getPrimaryKey() + " value: " + tt.getLevelValuesCount());
    tt = preader.readObject();
    System.out.println("key: " + tt.getPrimaryKey() + " value: " + tt.getLevelValuesCount());
    preader.close();
  }
示例#3
0
 public BigtableData readObject() {
   int size = 0;
   try {
     size = in.read();
     System.out.println("size: " + size);
     byte[] tempchars = new byte[size];
     in.read(tempchars);
     BigtableData tt = BigtableData.parseFrom(tempchars);
     return tt;
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   return null;
 }