int start=0,flag=1;
long size=blobInfo.getSize(),fetched=0,fetch;
byte temp[] = null;
while(fetched<size){
if(size-fetched>MAX_BLOB_FETCH_SIZE)
fetch=MAX_BLOB_FETCH_SIZE;
else
fetch=size-fetched;
temp=blobstoreService.fetchData(blobKey,fetched,fetch );
fetched+=fetch;
out.println(temp);
}
我尝试使用上面的代码打印上传的文本文件的数据,但它似乎不起作用。
答案 0 :(得分:1)
我得到了解决方案。 如
而(blobInfo.getSize()&GT; positionInBlob){ long endIndex = Math.min(blobInfo.getSize(),positionInBlob + chunkSize); chunk = blobstoreService.fetchData(blobKey,positionInBlob,endIndex); positionInBlob + = chunk.length;
for(int j=0;j<chunk.length;j++){
int c=chunk[j];
out.println((char)c);
}
}
答案 1 :(得分:0)
我的Blob笔记: http://code.google.com/p/gwt-examples/wiki/DemoGAEMultiFileBlobUpload
我的追求:
private byte [] getImageBytes(BlobData blobData){ if(blobData == null){ return null; }
BlobKey blobKey = new BlobKey(blobData.getKey());
if (blobKey == null) {
return null;
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
long filesize = blobData.getSize();
int chunkSize = 1024;
long offset = 0;
while (offset < filesize) {
long limit = offset + chunkSize - 1;
if (filesize < limit) {
limit = filesize;
}
System.out.println("offset=" + offset + " limit=" + limit);
byte[] b = null;
try {
b = blobstoreService.fetchData(blobKey, offset, limit);
} catch (Exception e) {
e.printStackTrace();
return null;
}
try {
out.write(b);
} catch (IOException e) {
e.printStackTrace();
return null;
}
offset += chunkSize;
if (offset > filesize) {
offset = filesize;
}
}
byte[] filebytes = out.toByteArray();
System.out.println("getImageBytes(): filebytes size: " + filebytes.length + " blobData.size=" + blobData.getSize());
return filebytes;
}