/** * Download file from Azure and save to target path specified. Return true if download succeeds * @param filePathName * @return */ private static Boolean downloadFromAzure(@NotNull Path filePathName) { boolean result = true; try { URI cloudBlobUri = new URI(AZURE_BLOB_URI); CloudBlobClient serviceClient = new CloudBlobClient(cloudBlobUri); CloudBlobContainer container = serviceClient.getContainerReference("libcontainer1"); CloudBlockBlob blob = container.getBlockBlobReference(filePathName.getFileName().toString()); File downloadingFile = filePathName.toFile(); blob.downloadToFile(downloadingFile.getAbsolutePath()); } catch (Exception e) { result = false; log.warning("Fail to download file from Azure: " + e.getMessage()); } return result; }
String fn = pp + "/" + EncyptUtils.encString(nm, Main.chunkStoreEncryptionEnabled); CloudBlockBlob blob = container.getBlockBlobReference(fn); blob.downloadToFile(p.getPath(), null, null, opContext); byte[] md5 = Base64.decode(blob.getProperties().getContentMD5()); if (!FileUtils.fileValid(p, md5))
blob.uploadStandardBlobTier(StandardBlobTier.HOT); blob.downloadToFile(f.getPath(), null, null, opContext); if (Main.REFRESH_BLOBS) { synchronized (this.refresh) {
private void doUploadDownloadFileTest(CloudBlockBlob blob, int fileSize) throws IOException, StorageException { File sourceFile = File.createTempFile("sourceFile", ".tmp"); File destinationFile = new File(sourceFile.getParentFile(), "destinationFile.tmp"); try { byte[] buffer = BlobTestHelper.getRandomBuffer(fileSize); FileOutputStream fos = new FileOutputStream(sourceFile); fos.write(buffer); fos.close(); blob.uploadFromFile(sourceFile.getAbsolutePath()); blob.downloadToFile(destinationFile.getAbsolutePath()); assertTrue("Destination file does not exist.", destinationFile.exists()); assertEquals("Destination file does not match input file.", fileSize, destinationFile.length()); FileInputStream fis = new FileInputStream(destinationFile); byte[] readBuffer = new byte[fileSize]; fis.read(readBuffer); fis.close(); for (int i = 0; i < fileSize; i++) { assertEquals("File contents do not match.", buffer[i], readBuffer[i]); } } finally { if (sourceFile.exists()) { sourceFile.delete(); } if (destinationFile.exists()) { destinationFile.delete(); } } }