• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java BlockEntry类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.microsoft.azure.storage.blob.BlockEntry的典型用法代码示例。如果您正苦于以下问题:Java BlockEntry类的具体用法?Java BlockEntry怎么用?Java BlockEntry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



BlockEntry类属于com.microsoft.azure.storage.blob包,在下文中一共展示了BlockEntry类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: uploadFileBlocksAsBlockBlob

import com.microsoft.azure.storage.blob.BlockEntry; //导入依赖的package包/类
/**
 * Creates and returns a temporary local file for use by the sample.
 *
 * @param blockBlob CloudBlockBlob object.
 * @param filePath The path to the file to be uploaded.
 *
 * @throws Throwable
 */
private static void uploadFileBlocksAsBlockBlob(CloudBlockBlob blockBlob, String filePath) throws Throwable {

    FileInputStream fileInputStream = null;
    try {
        // Open the file
        fileInputStream = new FileInputStream(filePath);

        // Split the file into 32K blocks (block size deliberately kept small for the demo) and upload all the blocks
        int blockNum = 0;
        String blockId = null;
        String blockIdEncoded = null;
        ArrayList<BlockEntry> blockList = new ArrayList<BlockEntry>();
        while (fileInputStream.available() > (32 * 1024)) {
            blockId = String.format("%05d", blockNum);
            blockIdEncoded = Base64.getEncoder().encodeToString(blockId.getBytes());
            blockBlob.uploadBlock(blockIdEncoded, fileInputStream, (32 * 1024));
            blockList.add(new BlockEntry(blockIdEncoded));
            blockNum++;
        }
        blockId = String.format("%05d", blockNum);
        blockIdEncoded = Base64.getEncoder().encodeToString(blockId.getBytes());
        blockBlob.uploadBlock(blockIdEncoded, fileInputStream, fileInputStream.available());
        blockList.add(new BlockEntry(blockIdEncoded));

        // Commit the blocks
        blockBlob.commitBlockList(blockList);
    }
    catch (Throwable t) {
        throw t;
    }
    finally {
        // Close the file output stream writer
        if (fileInputStream != null) {
            fileInputStream.close();
        }
    }
}
 
开发者ID:Azure-Samples,项目名称:storage-blob-java-getting-started,代码行数:46,代码来源:BlobBasics.java


示例2: testStoreBlobMd5

import com.microsoft.azure.storage.blob.BlockEntry; //导入依赖的package包/类
private void testStoreBlobMd5(boolean expectMd5Stored) throws Exception {
  assumeNotNull(testAccount);
  // Write a test file.
  String testFileKey = "testFile";
  Path testFilePath = new Path("/" + testFileKey);
  OutputStream outStream = testAccount.getFileSystem().create(testFilePath);
  outStream.write(new byte[] { 5, 15 });
  outStream.close();

  // Check that we stored/didn't store the MD5 field as configured.
  CloudBlockBlob blob = testAccount.getBlobReference(testFileKey);
  blob.downloadAttributes();
  String obtainedMd5 = blob.getProperties().getContentMD5();
  if (expectMd5Stored) {
    assertNotNull(obtainedMd5);
  } else {
    assertNull("Expected no MD5, found: " + obtainedMd5, obtainedMd5);
  }

  // Mess with the content so it doesn't match the MD5.
  String newBlockId = Base64.encode(new byte[] { 55, 44, 33, 22 });
  blob.uploadBlock(newBlockId,
      new ByteArrayInputStream(new byte[] { 6, 45 }), 2);
  blob.commitBlockList(Arrays.asList(new BlockEntry[] { new BlockEntry(
      newBlockId, BlockSearchMode.UNCOMMITTED) }));

  // Now read back the content. If we stored the MD5 for the blob content
  // we should get a data corruption error.
  InputStream inStream = testAccount.getFileSystem().open(testFilePath);
  try {
    byte[] inBuf = new byte[100];
    while (inStream.read(inBuf) > 0){
      //nothing;
    }
    inStream.close();
    if (expectMd5Stored) {
      fail("Should've thrown because of data corruption.");
    }
  } catch (IOException ex) {
    if (!expectMd5Stored) {
      throw ex;
    }
    StorageException cause = (StorageException)ex.getCause();
    assertNotNull(cause);
    assertTrue("Unexpected cause: " + cause,
        cause.getErrorCode().equals(StorageErrorCodeStrings.INVALID_MD5));
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:49,代码来源:TestBlobDataValidation.java


示例3: upload

import com.microsoft.azure.storage.blob.BlockEntry; //导入依赖的package包/类
private void upload(EntryVideo video, String url) 
throws Exception {
	
	final byte[] buffer = new byte[BLOCK_SIZE_BYTES];
	final File file = new File(App.STORAGE_DIRECTORY, video.filename);
	
	if(!file.exists()) {
		dao.markAsUploaded(video);
		return;
	}
	
	CloudBlockBlob blob = new CloudBlockBlob(new URI(url));
	ArrayList<BlockEntry> blocks = blob.exists() 
			? blob.downloadBlockList() 
			: new ArrayList<BlockEntry>();
	BufferedInputStream input = new BufferedInputStream(
			new FileInputStream(file));
	try {
		int id = 0;
		if(blocks.size() > 0) {
			id = decodeId(blocks.get(blocks.size() -1).getId()) + 1;
			input.skip(BLOCK_SIZE_BYTES * id);
		}
		int read;
		while((read = input.read(buffer, 0, BLOCK_SIZE_BYTES)) > 0) {
			BlockEntry block = new BlockEntry(encodeId(id)); 
			blocks.add(block);
			blob.uploadBlock(block.getId(), 
					new ByteArrayInputStream(buffer, 0, read), read);
			blob.commitBlockList(blocks);
			id++;
			
			video.percentUploaded = Math.min(100, (int)((((id + 1) 
					* BLOCK_SIZE_BYTES) / file.length()) * 100));
			dao.update(video);
			for(UploadProgressListener l : listeners)
				l.progressChanged(video);
		}
					
		dao.markAsUploaded(video);
		
	} finally {
		input.close();
	}
}
 
开发者ID:horizon-institute,项目名称:runspotrun-android-client,代码行数:46,代码来源:ServiceVideoUpload.java



注:本文中的com.microsoft.azure.storage.blob.BlockEntry类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RongExceptionHandler类代码示例发布时间:2022-05-22
下一篇:
Java EventListener类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap