簡體   English   中英

無法打印上傳的Blob的數據

[英]cant print the data of the uploaded blob

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

我試圖使用上面的代碼打印上載的文本文件的數據,但是它似乎不起作用。

我知道了。

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

     }

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

我的抓取:

私有字節[] getImageBytes(BlobData blobData){如果(blobData == null){返回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;

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM