private static AppEngineFile newFile(String fileDescription) throws IOException {
return getFileService().createNewBlobFile(MIME_TYPE, abbrev(fileDescription));
}
private static byte[] slurp(BlobKey blobKey) throws IOException {
FileReadChannel in = getFileService().openReadChannel(
new AppEngineFile(AppEngineFile.FileSystem.BLOBSTORE, blobKey.getKeyString()),
false);
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteBuffer buf = ByteBuffer.allocate(BUFFER_BYTES);
while (true) {
int bytesRead = in.read(buf);
if (bytesRead < 0) {
break;
}
Preconditions.checkState(bytesRead != 0, "0 bytes read: %s", buf);
out.write(buf.array(), 0, bytesRead);