2012-07-10 63 views

回答

2

當然,GAE可以存儲數據的斑點。對於高達1Mb的數據使用Blobs,對於較大的對象使用Blobstore

0

GAE確實支持Blob數據。但是有一些尺寸限制。這裏是API documentation

但另一種選擇是讓POJO的從com.google.appengine.api.datastore.Entity延伸出序列化的,GAE可以做存儲信息。如果您正在尋找一些文件或信息,請查看out。有關擴展實體的更多信息可以查詢here

0
 FileService fileService = FileServiceFactory.getFileService(); 

     // Create a new Blob file with mime-type "text/plain" 
     AppEngineFile file = fileService.createNewBlobFile("text/plain"); 

     // Open a channel to write to it 
     boolean lock = true; 
     FileWriteChannel writeChannel = fileService.openWriteChannel(file, lock); 




     MyObject obj = new MyObject(); 
     obj.name="testing now"; 
     ObjectOutputStream oos = new ObjectOutputStream(Channels.newOutputStream(writeChannel)); 
     oos.writeObject(obj); 
     oos.flush(); 
     oos.close(); 
     // Now finalize 
     writeChannel.closeFinally(); 

     // Later, read from the file using the file API 
     FileReadChannel readChannel = fileService.openReadChannel(file, false); 
     ObjectInputStream ooi = new ObjectInputStream(Channels.newInputStream(readChannel)); 
     resp.setContentType("text/plain"); 
     try { 
     resp.getWriter().print(ooi.readObject().toString()); 
    } catch (ClassNotFoundException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

這裏是將POJO保存到blobstore的代碼。 MyObject需要實現Serializable接口。

相關問題