How to convert a given variable to / from byte / file / inputstream / string?

I am trying to save a set containing some data in blob (in cloud storage like Rackspace CloudFiles or Amazon S3 )

Now this is the code used to actually store the given variable in the cloud provider (using the jclouds library) -

 Set<? extends NodeMetadata> nodes; BlobStore blobStore = bscontext.getBlobStore(); Blob blob; 

blob needs to be saved / retrieved to / from cloud storage. These are the following ways to actually store some data in a blob -

  blob.setPayload(argument) Argument= byte/file/inputstream/string. 

I want to know which of the above I am using (e.g. byte or file or input stream or string)? Also, how do I convert the value stored in the Set variable named 'nodes' to this format so that I can store it as a blob ?

+4
source share
1 answer

You can do any of the above. I suggest you do what you think is the easiest. You can save it as text / string using XMLEncoder or XStream as XML or JSon. You can store data binary with ObjectOutputStream or something like protobuf,

+2
source

All Articles