My work around:
try {
writeChannel.closeFinally();
} catch (IllegalStateException e) {
success = false;
log.severe("close(): Error 6: writeChannel.closeFinally() error " +
e.toString());
} catch (IOException e) {
success = false;
log.severe("close(): Error 7: writeChannel.closeFinally() error " +
e.toString());
}
if (success == false) {
log.severe("close(): Error 8: quitting...");
return;
}
BlobKey blobKey = fileService.getBlobKey(file);
// try by finding filename
if (blobKey == null) {
log.severe("close(): Blobkey was null. 1. trying workaround.");
blobKey = tryfindingBlobKey();
}
// try waiting then check fileservice again
if (blobKey == null) {
log.info("close(): 2. trying to get it from fileservice again.");
try {
wait(2000);
} catch (InterruptedException e) {
log.warning("close(): 3. couldn't wait 2 seconds.");
e.printStackTrace();
}
blobKey = fileService.getBlobKey(file);
}
// try finding the filename again
if (blobKey == null) {
log.severe("close(): 4. Blobkey was null. trying workaround.");
blobKey = tryfindingBlobKey();
}
// quit if haven't found it
if (blobKey == null) {
success = false;
log.severe("close(): 5. Workaround, Blobkey was null agian. Couldn't find
the blobkey using the filename");
return;
}
}
private BlobKey tryfindingBlobKey() {
log.info("tryfindingBlobKey(): filename=" + filename);
String skey = null;
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
try {
Query q = new Query("__BlobInfo__");
q.addFilter("filename", FilterOperator.EQUAL, filename);
PreparedQuery e = datastore.prepare(q);
Iterator<Entity> itr = e.asIterator();
while (itr.hasNext()) {
Entity entity = itr.next();
Key k = entity.getKey();
// #GAE needs a k.getStringId(); // only has k.getId();
String sk = k.toString();
String sbk = sk.replaceFirst(".*?\"", "");
sbk = sbk.replaceFirst("\".*", "");
skey = sbk;
}
} catch (Exception e) {
success = false;
log.log(Level.SEVERE, "decode(): ERROR: ", e);
}
BlobKey blobKey = null;
if (skey != null) {
blobKey = new BlobKey(skey);
} else {
log.warning("tryfindingBlobKey(): warn: wasn't able to parse the blobkey
or find the file: skey=" + skey);
}
return blobKey;
}
Brandon Donnelson
http://gwt-examples.googlecode.com
--
You received this message because you are subscribed to the Google Groups
"Google App Engine for Java" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-appengine-java/-/eDBmbFdJX01TS2tK.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=en.