Advertisement
olutel

put

Nov 23rd, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1.  public PutResult putContent(String fileName, InputStream data)
  2.             throws IOException, ContainerNotFoundException {
  3.         BlobStore blobStore = connectionProvider.getBlobStore();
  4.         String container = connectionProvider.getContainer();
  5.         CountingInputStream countingInputStream = new CountingInputStream(data);
  6.         DigestInputStream md5DigestInputStream = md5InputStream(countingInputStream);
  7.         BlobBuilder builder = blobStore.blobBuilder(fileName);
  8.         builder = builder.name(fileName);
  9.         builder = builder.payload(md5DigestInputStream);
  10.         Blob blob = builder.build();
  11.         blobStore.putBlob(container, blob);
  12.  
  13.         String md5 = BaseEncoding.base16().lowerCase().encode(md5DigestInputStream.getMessageDigest().digest());
  14.         Long contentLength = countingInputStream.getCount();
  15.         return new PutResult(md5, contentLength);
  16.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement