Cleanup of Azureblob code; as per pull request review. Additional items

not covered here are assigned specific bug ids.
This commit is contained in:
John Kew 2013-07-11 16:12:07 -07:00 committed by Andrew Gaul
parent fcdc3d6138
commit 865b910637
4 changed files with 9 additions and 5 deletions

View File

@ -35,6 +35,7 @@ import java.util.List;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
/**
* Decomposes a blob into blocks for upload and assembly through PutBlock and PutBlockList
@ -57,7 +58,7 @@ public class AzureBlobBlockUploadStrategy implements MultipartUploadStrategy {
public String execute(String container, Blob blob) {
String blobName = blob.getMetadata().getName();
Payload payload = blob.getPayload();
long length = payload.getContentMetadata().getContentLength();
Long length = payload.getContentMetadata().getContentLength();
checkNotNull(length,
"please invoke payload.getContentMetadata().setContentLength(length) prior to azure block upload");
checkArgument(length <= (MAX_NUMBER_OF_BLOCKS * MAX_BLOCK_SIZE));
@ -81,7 +82,7 @@ public class AzureBlobBlockUploadStrategy implements MultipartUploadStrategy {
blockIds.add(blockId);
client.putBlock(container, blobName, blockId, block);
}
assert bytesWritten == length;
checkState(bytesWritten == length, "Wrote " + bytesWritten + " bytes, but we wanted to write " + length + " bytes");
return client.putBlockList(container, blobName, blockIds);
}
}

View File

@ -19,6 +19,7 @@ package org.jclouds.azureblob.domain.internal;
import org.jclouds.azureblob.domain.BlobBlockProperties;
import com.google.common.base.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Representation of the blocks which compose a Blob
@ -29,7 +30,7 @@ public class BlobBlockPropertiesImpl implements BlobBlockProperties {
private final boolean committed;
public BlobBlockPropertiesImpl(String blockName, long contentLength, boolean committed) {
this.blockName = blockName;
this.blockName = checkNotNull(blockName);
this.contentLength = contentLength;
this.committed = committed;
}

View File

@ -33,8 +33,8 @@ import org.jclouds.predicates.Validator;
@Singleton
public class BlockIdValidator extends Validator<String> {
@Override
public void validate(@Nullable String s) throws IllegalArgumentException {
if (s.length() > 64)
public void validate(String s) throws IllegalArgumentException {
if (s == null || s.length() > 64)
throw new IllegalArgumentException("block id:" + s + "; Block Ids must be less than or equal to 64 bytes in size");
}

View File

@ -30,6 +30,7 @@ import com.google.common.collect.Lists;
/**
* Parses the following document:
* <pre>
* <?xml version="1.0" encoding="utf-8"?>
* <BlockList>
* <CommittedBlocks>
@ -39,6 +40,7 @@ import com.google.common.collect.Lists;
* </Block>
* <CommittedBlocks>
* </BlockList>
* </pre>
*/
public class BlobBlocksResultsHandler extends ParseSax.HandlerWithResult<ListBlobBlocksResponse> {