开发者

cant print the data of the uploaded blob

            int start=0,flag=1;
    开发者_StackOverflow社区        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);
        }

i tried to print the data of the uploaded text file using the above code but it doesn't seem to be working .


i got it worked out. as

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

     }


My Blob notes: http://code.google.com/p/gwt-examples/wiki/DemoGAEMultiFileBlobUpload

My Fetching:

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;

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜