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

Categories

HOME
xml
oracle12c
scikit-learn
rdbms
datastore
themes
pascal
simulink
crystal-lang
title
character
qpython
pattern-matching
mql5
google-schemas
distribution
cmdb
php-5.6
tput
intercom
onedrive-api
parameter-passing
gruntfile
alpacajs
mathprog
sse
apache2.4
selinux
microsoft-ocr
breadth-first-search
visual-glitch
libigl
joptionpane
imageresizer
beta
slidetoggle
custom-post-type
ms-access-web-app
android-things
paperjs
user-defined-functions
gitlab-api
cognos-bi
catch-unit-test
rselenium
laravel-eloquent
dsx-desktop
android-gridview
yowsup
ideascript
comparison-operators
softmax
smoothstate.js
yii2-api
aquamacs
boxing
check-mk
gpg-signature
cpu-cache
offline.js
gameplay-kit
swingworker
tooleap
createprocess
html-to-pdf
httpruntime.cache
jaunt-api
jnlua
assertion
lazybones
rate-limiting
visual-sourcesafe-2005
evolus-pencil
eoferror
alloy-ui
node-serialport
uvc
zxspectrum
dot.js
infosphere-spl
deform
cocos3d
nsmenu
ss7
drupal-nodes
git-repo
accesscontrolexception
gwt-openlayers
solace-mq
dtmf
process-explorer
wimax
wiimote
relative
gobject-introspection
procedures
google-ajax-api
jqote
tournament
strsep
photolibrary
rowlex
java1.4

Resources

Encrypt Message