0

I am in the process of creating a web application to download files from an azure blob storage container.

I have most of it working but sometimes receive the following the stacktrace error:-

java.lang.IllegalArgumentException: The argument must not be null or an empty string. Argument name: buffer.
  at com.microsoft.azure.storage.core.Utility.assertNotNull(Utility.java:272)
  at com.microsoft.azure.storage.blob.CloudBlob.downloadToByteArray(CloudBlob.java:1586)
  at com.microsoft.azure.storage.blob.CloudBlob.downloadToByteArray(CloudBlob.java:1555)
  at DSAengine.Cloudlet.download(Cloudlet.java:176) 

The line of code which I am using to download the files to a bytearray is blob.downloadToByteArray(bytearr, 100000);

It is detailed that the '0' is a buffer for the bytearray, so I am guessing this is used to temporarily store information. But have no idea why it is required/what it does, and therefore do not understand how to solve this error, as the buffer is not null, and the error only occurs some of the time.

Any help is greatly appreciated!

1
  • Can you show me more code about how you define the parameter 'bytearr' and how you use it in your code ? Commented Mar 25, 2016 at 6:28

2 Answers 2

1

I reproduced your issue thru the code below

byte[] buffer = null;
int bufferOffset = 0;
blob.downloadToByteArray(buffer, 0);

The correct usage for the function public final int downloadToByteArray(final byte[] buffer, final int bufferOffset) as below.

/*
 * For example, there is a text file block blob that the content is "ABC123\n"
 * The variable `bufferOffset` must be less than `buffer.length`, 
 * and the buffer size must be more than the sum of the blob size and the `bufferOffset`.
 */
byte[] buffer = new byte[10];
int bufferOffset = 0;
blob.downloadToByteArray(buffer, 0);

As references, please see the line 1527 and 1555 of the source code CloudBlob.java, and refer to the line 41 of the source code WrappedByteArrayOutputStream.java.

Sign up to request clarification or add additional context in comments.

Comments

0

This error happens when your are using blob.downloadToByteArray(buffer, 100000);while the buffer is null. This perhaps like this:

byte[] buffer = new byte[100000];

for (ListBlobItem blobItem : container.listBlobs()) {
    if (blobItem instanceof CloudBlockBlob) {

        CloudBlockBlob retrievedBlob = (CloudBlockBlob) blobItem;
        retrievedBlob.downloadToByteArray(buffer, 10000);

        // ......

        buffer = null;
    }
}

You can check whether you have tried to set buffer to null anywhere in you code before finishing reading blobs.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.