Bui Dinh Ngoc
Bui Dinh Ngoc

Reputation: 425

Google appengine can store java object POJO

Can App Engine Store information like the ObjectOutputStream?

Upvotes: 0

Views: 393

Answers (3)

Bui Dinh Ngoc
Bui Dinh Ngoc

Reputation: 425

      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();
    }

Here is code for save POJO to blobstore . MyObject need implement Serializable interface .

Upvotes: 0

sathish_at_madison
sathish_at_madison

Reputation: 833

GAE does support Blob data. But there are some size limitations. Here is the API documentation

But other option is to make POJO's extended from com.google.appengine.api.datastore.Entity are serializable and , GAE can do store information. If you are looking for some documentation or information around it, check this out. More information on extending an entity can be looked up here.

Upvotes: 0

Dave W. Smith
Dave W. Smith

Reputation: 24966

Sure, GAE can store blobs of data. Use Blobs for data up to 1Mb, and the Blobstore for larger objects.

Upvotes: 2

Related Questions