public long getBlobLength(final String containerName, final String blobPath) throws URISyntaxException, StorageException { return getCloudBlobContainer(containerName).getBlockBlobReference(blobPath).getProperties().getLength(); }
long length = blob.getProperties().getLength(); attributes.put("azure.length", String.valueOf(length));
.etag(properties.getEtag()) .lastModifiedTime(properties.getLastModified().getTime()) .length(properties.getLength());
@Override public long contentLength() throws IOException { return this.blockBlob.getProperties().getLength(); }
@Override public List<String> readLines() throws IOException { try { if (!gcJournal.exists()) { return Collections.emptyList(); } byte[] data = new byte[(int) gcJournal.getProperties().getLength()]; gcJournal.downloadToByteArray(data, 0); return IOUtils.readLines(new ByteArrayInputStream(data), Charset.defaultCharset()); } catch (StorageException e) { throw new IOException(e); } } }
@Override public List<String> readLines() throws IOException { try { if (!gcJournal.exists()) { return Collections.emptyList(); } byte[] data = new byte[(int) gcJournal.getProperties().getLength()]; gcJournal.downloadToByteArray(data, 0); return IOUtils.readLines(new ByteArrayInputStream(data), Charset.defaultCharset()); } catch (StorageException e) { throw new IOException(e); } } }
@Override public Properties load() throws IOException { Properties properties = new Properties(); if (exists()) { long length = manifestBlob.getProperties().getLength(); byte[] data = new byte[(int) length]; try { manifestBlob.downloadToByteArray(data, 0); } catch (StorageException e) { throw new IOException(e); } properties.load(new ByteArrayInputStream(data)); } return properties; }
public ReverseFileReader(CloudBlob blob, int bufferSize) throws StorageException { this.blob = blob; if (blob.exists()) { this.fileOffset = (int) blob.getProperties().getLength(); } else { this.fileOffset = 0; } this.bufferSize = bufferSize; }
@Override public Properties load() throws IOException { Properties properties = new Properties(); if (exists()) { long length = manifestBlob.getProperties().getLength(); byte[] data = new byte[(int) length]; try { manifestBlob.downloadToByteArray(data, 0); } catch (StorageException e) { throw new IOException(e); } properties.load(new ByteArrayInputStream(data)); } return properties; }
public ReverseFileReader(CloudBlob blob, int bufferSize) throws StorageException { this.blob = blob; if (blob.exists()) { this.fileOffset = (int) blob.getProperties().getLength(); } else { this.fileOffset = 0; } this.bufferSize = bufferSize; }
AzureSegmentArchiveReader(CloudBlobDirectory archiveDirectory, IOMonitor ioMonitor) throws IOException { this.archiveDirectory = archiveDirectory; this.ioMonitor = ioMonitor; long length = 0; for (CloudBlob blob : AzureUtilities.getBlobs(archiveDirectory).collect(Collectors.toList())) { Map<String, String> metadata = blob.getMetadata(); if (AzureBlobMetadata.isSegment(metadata)) { AzureSegmentArchiveEntry indexEntry = AzureBlobMetadata.toIndexEntry(metadata, (int) blob.getProperties().getLength()); index.put(new UUID(indexEntry.getMsb(), indexEntry.getLsb()), indexEntry); } length += blob.getProperties().getLength(); } this.length = length; }
AzureSegmentArchiveReader(CloudBlobDirectory archiveDirectory, IOMonitor ioMonitor) throws IOException { this.archiveDirectory = archiveDirectory; this.ioMonitor = ioMonitor; long length = 0; for (CloudBlob blob : AzureUtilities.getBlobs(archiveDirectory).collect(Collectors.toList())) { Map<String, String> metadata = blob.getMetadata(); if (AzureBlobMetadata.isSegment(metadata)) { AzureSegmentArchiveEntry indexEntry = AzureBlobMetadata.toIndexEntry(metadata, (int) blob.getProperties().getLength()); index.put(new UUID(indexEntry.getMsb(), indexEntry.getLsb()), indexEntry); } length += blob.getProperties().getLength(); } this.length = length; }
public long getBlobLength(final String containerName, final String blobPath) throws URISyntaxException, StorageException { return getCloudBlobContainer(containerName).getBlockBlobReference(blobPath).getProperties().getLength(); }
public static AzureBlobInfo fromCloudBlob(CloudBlob cloudBlob) { return new AzureBlobInfo(cloudBlob.getName(), cloudBlob.getProperties().getLastModified().getTime(), cloudBlob.getProperties().getLength()); } }
private Buffer readBlob(String name) throws IOException { try { CloudBlockBlob blob = getBlob(name); if (!blob.exists()) { return null; } long length = blob.getProperties().getLength(); Buffer buffer = Buffer.allocate((int) length); AzureUtilities.readBufferFully(blob, buffer); return buffer; } catch (StorageException e) { throw new IOException(e); } }
private Buffer readBlob(String name) throws IOException { try { CloudBlockBlob blob = getBlob(name); if (!blob.exists()) { return null; } long length = blob.getProperties().getLength(); Buffer buffer = Buffer.allocate((int) length); AzureUtilities.readBufferFully(blob, buffer); return buffer; } catch (StorageException e) { throw new IOException(e); } }
protected static void doDownloadTest(CloudBlob blob, int blobSize, int bufferSize, int bufferOffset) throws StorageException, IOException { final Random randGenerator = new Random(); final byte[] buffer = new byte[blobSize]; randGenerator.nextBytes(buffer); byte[] resultBuffer = new byte[bufferSize]; BlobRequestOptions options = new BlobRequestOptions(); if (blob.getClass() == CloudBlockBlob.class) { options.setUseTransactionalContentMD5(true); } blob.upload(new ByteArrayInputStream(buffer), buffer.length); blob.downloadToByteArray(resultBuffer, bufferOffset, null, options, null); for (int i = 0; i < blob.getProperties().getLength(); i++) { assertEquals(buffer[i], resultBuffer[bufferOffset + i]); } if (bufferOffset + blobSize < bufferSize) { for (int k = bufferOffset + blobSize; k < bufferSize; k++) { assertEquals(0, resultBuffer[k]); } } }
@Test public void testAppendBlobUploadFromStream() throws StorageException, IOException, URISyntaxException { byte[] buffer = BlobTestHelper.getRandomBuffer(6 * 1024 * 1024); CloudAppendBlob blob = this.container.getAppendBlobReference("blob1"); blob.upload(new ByteArrayInputStream(buffer), buffer.length); blob.downloadAttributes(); assertEquals(6 * 1024 * 1024, blob.getProperties().getLength()); blob.upload(new ByteArrayInputStream(buffer), buffer.length); blob.downloadAttributes(); assertEquals(6 * 1024 * 1024, blob.getProperties().getLength()); blob.upload(new ByteArrayInputStream(buffer), buffer.length, null /* accessCondition */, null /* options */, null /* operationContext */); blob.downloadAttributes(); assertEquals(6 * 1024 * 1024, blob.getProperties().getLength()); }
@Test public void testEmpty() throws URISyntaxException, StorageException, IOException { String blobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testblob"); CloudBlockBlob blockBlob = this.container.getBlockBlobReference(blobName); BlobOutputStream str = blockBlob.openOutputStream(); str.close(); CloudBlockBlob blockBlob2 = this.container.getBlockBlobReference(blobName); blockBlob2.downloadAttributes(); assertEquals(0, blockBlob2.getProperties().getLength()); ArrayList<BlockEntry> blocks = blockBlob2.downloadBlockList(BlockListingFilter.ALL, null, null, null); assertEquals(0, blocks.size()); }
@Test public void testAppendBlobUploadNegativeLength() throws URISyntaxException, StorageException, IOException { final int blobLength = 16 * 1024; String blobName = BlobTestHelper .generateRandomBlobNameWithPrefix("testblob"); final CloudAppendBlob blobRef = this.container .getAppendBlobReference(blobName); final byte[] buff = BlobTestHelper.getRandomBuffer(blobLength); ByteArrayInputStream sourceStream = new ByteArrayInputStream(buff); blobRef.upload(sourceStream, -1); assertTrue(blobRef.exists()); assertEquals(blobRef.getProperties().getLength(), blobLength); }