none
[Java][Azure Storage] OutputStream for Block Blob not working RRS feed

  • Question

  • Greetings, everyone! I come here with a rather quirky thing I've found while using Azure's Java Storage SDK, something which I'm hoping to get some light shed on.

    Lately, I've been using the Java Storage SDK (version 2.2.0) made available through Maven. In the CloudBlockBlob object of that SDK, there's a method called openOutputStream. This method returns an OutputStream object onto which one can write anything. Unfortunately, no matter how I write to an OutputStream given to me by this method, the operation silently fails, giving me no feedback as to why that happened. To top it all off, it doesn't even create anything, not even a zero-bytes file.

    Has anyone here experienced this? Is this a bug of some sort, or a quirk that I didn't find in the Javadocs? I'm quite the newbie, so forgive my lack of experience.

    Thanks for your time.




    Friday, May 29, 2015 3:56 PM

Answers

  • Hi,

    We can write data to the block blob via openOutputStream method, based on your description, this operation failed, but it didn't give you any feedback, it is weird. I would suggest you check your buffer data, I have tested on my local, everything works fine, the following is my test code.

    CloudBlockBlob blockBlob = container
    					.getBlockBlobReference("test.txt");
    			BlobOutputStream blobOutputStream = blockBlob.openOutputStream();
    			String content = "hello, I want to input some information to test.txt file.";
    			byte[] buffer = content.getBytes();
    			ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer);
    			int next = inputStream.read();
    			while (next != -1) {
    				blobOutputStream.write(next);
    				next = inputStream.read();
    			}
    			blobOutputStream.close();

    Hope it gives you some tips, if not, please feel free follow up with more information.

    Best Regards,

    Jambor


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Monday, June 1, 2015 6:11 AM
    Moderator

All replies

  • Hi Lopson,

    As I understand from your query, you are using a type BlobOutputStream with the method openOutputStream() that Creates and opens an output stream to write data to the block blob but it fails.

    Is it failing to  open output stream ?

    When you said the operations silently Fails, does it throw any error message ?

    Also, let us know if the operation was ever successful ?

    Have you specified any request options or operation context like openOutputStream(AccessCondition accessCondition, BlobRequestOptions options,    OperationContext opContext)

    References : https://github.com/Azure/azure-storage-java

                       How to use Blob Storage with Java

                       Uses of BlobOutputStream in com.microsoft.azure.storage.blob

    Saturday, May 30, 2015 9:50 AM
  • Hi,

    We can write data to the block blob via openOutputStream method, based on your description, this operation failed, but it didn't give you any feedback, it is weird. I would suggest you check your buffer data, I have tested on my local, everything works fine, the following is my test code.

    CloudBlockBlob blockBlob = container
    					.getBlockBlobReference("test.txt");
    			BlobOutputStream blobOutputStream = blockBlob.openOutputStream();
    			String content = "hello, I want to input some information to test.txt file.";
    			byte[] buffer = content.getBytes();
    			ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer);
    			int next = inputStream.read();
    			while (next != -1) {
    				blobOutputStream.write(next);
    				next = inputStream.read();
    			}
    			blobOutputStream.close();

    Hope it gives you some tips, if not, please feel free follow up with more information.

    Best Regards,

    Jambor


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Monday, June 1, 2015 6:11 AM
    Moderator
  • Hi everyone! First of all, sorry for the late reply.

    Second of all, I realized yesterday what was causing this erroneous behavior: unsurprisingly, it was a simple mistake on my part, and not something on your end. After reading Jambor Yao's code snippet, I realized that I was forgetting to close the CloudBlockBlob's OutputStream I was creating! Doing so after performing the write to the OutputStream has fixed the issue.

    I apologize for my hastiness in creating this topic and for taking up some of your time. Clearly, I should've taken a closer look into my own code instead of shifting the blame somewhere else! I'd also like to thank you for making such a great tool!

    Monday, June 1, 2015 9:33 AM