google-app-engine
How to read byte by byte from appengine datastore Entity Object
In a nutshell, since GAE cannot write to a filesystem, I have decided to persist my data into the datastore (using JDO). Now, I will like to retrieve the data byte by byte and pass it to the client as an input stream. There's code from the gwtupload library(http://code.google.com/p/gwtupload/) (see below) which breaks on GAE because it writes to the system filesystem. I'll like to be able to provide a GAE ported solution. public static void copyFromInputStreamToOutputStream(InputStream in, OutputStream out) throws IOException { byte[] buffer = new byte[100000]; while (true) { synchronized (buffer) { int amountRead = in.read(buffer); if (amountRead == -1) { break; } out.write(buffer, 0, amountRead); } } in.close(); out.flush(); out.close(); } One work around I have tried (didn't work) is to retrieve the data from the datastore as a resource like this: InputStream resourceAsStream = null; PersistenceManager pm = PMF.get().getPersistenceManager(); try { Query q = pm.newQuery(ImageFile.class); lf = q.execute(); resourceAsStream = getServletContext().getResourceAsStream((String) pm.getObjectById(lf)); } finally { pm.close(); } if (lf != null) { response.setContentType(receivedContentTypes.get(fieldName)); copyFromInputStreamToOutputStream(resourceAsStream, response.getOutputStream()); } I welcome your suggestions. Regards
Store data in a byte array, and use a ByteArrayInputStream or ByteArrayOutputStream to pass it to libraries that expect streams. If by 'client' you mean 'HTTP client' or browser, though, there's no reason to do this - just deal with regular byte arrays on your end and send them to/from the user as you would any other data. The only reason to mess around with streams like this is if you have some library that expects them.
Related Links
All of my applications throw “deadline was exceeded”. GAE breakdown?
Splitting entities vs. using transactions
DataNucleus on AppEngine not returning any results
Is there API for setting TLS certificates for Google App Engine?
GAE printing same log statement multiple times
Adding multiple accounts for “You do not have permission to modify this app” error
Logs are Not Nested Under Requests in Flexible VM
How to create an equivalent of a background thread for an auto-scaling instance
Communication between modules locally
Technology for realtime messaging to mobile apps
how to apply date filter on ancestor query
How to enable speech api higher quota
Google App Engine standard environment to Cloud-SQL Second Generation instance
GAE: Restore ah-builtin-python-bundle and ah-builtin-datastoreservice
Google Cloud Storage Force Download
Importing data into 2nd generation google cloud sql