I get the correct byte count reading it this way:

   private byte[] getImageBytes(BlobData blobData) {

    if (blobData == null) {

      return null;

    }

  

    BlobKey blobKey = new BlobKey(blobData.getKey());

    if (blobKey == null) {

      return null;

    }

    

    long filesize = blobData.getSize();

    long chunkSize = 1024;

    long startIndex = 0;

    long endIndex = chunkSize;

    

    ByteArrayOutputStream out = new ByteArrayOutputStream();

    if (filesize > 1024) {


      boolean theend = false;

      while (theend == false) {

        if (endIndex == filesize) {

          theend = true;

        }

        

        System.out.println("startIndex=" + startIndex + " endIndex=" + 
endIndex);

        

        byte[] b = blobstoreService.fetchData(blobKey, startIndex, 
endIndex);

        try {

          out.write(b);

        } catch (IOException e) {

          e.printStackTrace();

        }

        

        startIndex = endIndex + 1;

        endIndex = startIndex + chunkSize;

        if (endIndex > filesize) {

          endIndex = filesize;

        }

      }

      

    } else {

      byte[] b = blobstoreService.fetchData(blobKey, 0, 1024);

      try {

        out.write(b);

      } catch (IOException e) {

        e.printStackTrace();

      }

    }

    

    byte[] filebytes = out.toByteArray();

    

    System.out.println("getImageBytes(): filebytes size: " + filebytes.
length + " blobData.size=" + blobData.getSize());

    

    return filebytes;

  }

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to