0
            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);
        }

我尝试使用上面的代码打印上传的文本文件的数据,但它似乎不起作用。

4

2 回答 2

1

我搞定了。作为

while(blobInfo.getSize()>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);
         }

     }
于 2010-04-15T10:58:03.307 回答
0

我的 Blob 笔记: http ://code.google.com/p/gwt-examples/wiki/DemoGAEMultiFileBlobUpload

我的抓取:

私有字节[] 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;

}

于 2011-03-28T02:55:06.637 回答