_id stringlengths 2 7 | title stringlengths 3 140 | partition stringclasses 3
values | text stringlengths 73 34.1k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q167700 | FileRequest.deleteDirectory | validation | public static HttpURLConnection deleteDirectory(final URI uri, final FileRequestOptions fileOptions,
final OperationContext opContext, final AccessCondition accessCondition) throws IOException,
URISyntaxException, StorageException {
final UriQueryBuilder directoryBuilder = getDirectoryUriQueryBuilder();
HttpURLConnection request = BaseRequest.delete(uri, fileOptions, directoryBuilder, opContext);
if (accessCondition != null) {
accessCondition.applyConditionToRequest(request);
}
return request;
} | java | {
"resource": ""
} |
q167701 | FileRequest.getDirectoryProperties | validation | public static HttpURLConnection getDirectoryProperties(final URI uri, final FileRequestOptions fileOptions,
final OperationContext opContext, AccessCondition accessCondition, String snapshotVersion) throws IOException, URISyntaxException,
StorageException {
final UriQueryBuilder directoryBuilder = getDirectoryUriQueryBuilder();
return getProperties(uri, fileOptions, opContext, accessCondition, directoryBuilder, snapshotVersion);
} | java | {
"resource": ""
} |
q167702 | FileRequest.listFilesAndDirectories | validation | public static HttpURLConnection listFilesAndDirectories(final URI uri, final FileRequestOptions fileOptions,
final OperationContext opContext, final ListingContext listingContext, String snapshotVersion) throws URISyntaxException,
IOException, StorageException {
final UriQueryBuilder builder = getDirectoryUriQueryBuilder();
addShareSnapshot(builder, snapshotVersion);
builder.add(Constants.QueryConstants.COMPONENT, Constants.QueryConstants.LIST);
if (listingContext != null) {
if (!Utility.isNullOrEmpty(listingContext.getMarker())) {
builder.add(Constants.QueryConstants.MARKER, listingContext.getMarker());
}
if (listingContext.getMaxResults() != null && listingContext.getMaxResults() > 0) {
builder.add(Constants.QueryConstants.MAX_RESULTS, listingContext.getMaxResults().toString());
}
if (!Utility.isNullOrEmpty(listingContext.getPrefix())) {
builder.add(Constants.QueryConstants.PREFIX, listingContext.getPrefix().toString());
}
}
final HttpURLConnection request = BaseRequest.createURLConnection(uri, fileOptions, builder, opContext);
request.setRequestMethod(Constants.HTTP_GET);
return request;
} | java | {
"resource": ""
} |
q167703 | FileRequest.putFile | validation | public static HttpURLConnection putFile(final URI uri, final FileRequestOptions fileOptions,
final OperationContext opContext, final AccessCondition accessCondition, final FileProperties properties,
final long fileSize) throws IOException, URISyntaxException, StorageException {
final HttpURLConnection request = BaseRequest.createURLConnection(uri, fileOptions, null, opContext);
request.setDoOutput(true);
request.setRequestMethod(Constants.HTTP_PUT);
addProperties(request, properties);
request.setFixedLengthStreamingMode(0);
request.setRequestProperty(Constants.HeaderConstants.CONTENT_LENGTH, "0");
request.setRequestProperty(FileConstants.FILE_TYPE_HEADER, FileConstants.FILE);
request.setRequestProperty(FileConstants.CONTENT_LENGTH_HEADER, String.valueOf(fileSize));
properties.setLength(fileSize);
if (accessCondition != null) {
accessCondition.applyConditionToRequest(request);
}
return request;
} | java | {
"resource": ""
} |
q167704 | FileRequest.putRange | validation | public static HttpURLConnection putRange(final URI uri, final FileRequestOptions fileOptions,
final OperationContext opContext, final AccessCondition accessCondition, final FileRange range,
FileRangeOperationType operationType) throws IOException, URISyntaxException, StorageException {
final UriQueryBuilder builder = new UriQueryBuilder();
builder.add(Constants.QueryConstants.COMPONENT, RANGE_QUERY_ELEMENT_NAME);
final HttpURLConnection request = BaseRequest.createURLConnection(uri, fileOptions, builder, opContext);
request.setDoOutput(true);
request.setRequestMethod(Constants.HTTP_PUT);
if (operationType == FileRangeOperationType.CLEAR) {
request.setFixedLengthStreamingMode(0);
}
// Range write is either update or clear; required
request.setRequestProperty(FileConstants.FILE_RANGE_WRITE, operationType.toString());
request.setRequestProperty(Constants.HeaderConstants.STORAGE_RANGE_HEADER, range.toString());
if (accessCondition != null) {
accessCondition.applyConditionToRequest(request);
}
return request;
} | java | {
"resource": ""
} |
q167705 | FileRequest.resize | validation | public static HttpURLConnection resize(final URI uri, final FileRequestOptions fileOptions,
final OperationContext opContext, final AccessCondition accessCondition, final Long newFileSize)
throws IOException, URISyntaxException, StorageException {
final HttpURLConnection request = setFileProperties(uri, fileOptions, opContext, accessCondition, null);
if (newFileSize != null) {
request.setRequestProperty(FileConstants.CONTENT_LENGTH_HEADER, newFileSize.toString());
}
return request;
} | java | {
"resource": ""
} |
q167706 | FileRequest.setMetadata | validation | private static HttpURLConnection setMetadata(final URI uri, final FileRequestOptions fileOptions,
final OperationContext opContext, final AccessCondition accessCondition, final UriQueryBuilder builder)
throws IOException, URISyntaxException, StorageException {
final HttpURLConnection request = BaseRequest.setMetadata(uri, fileOptions, builder, opContext);
if (accessCondition != null) {
accessCondition.applyConditionToRequest(request);
}
return request;
} | java | {
"resource": ""
} |
q167707 | FileRequest.setFileMetadata | validation | public static HttpURLConnection setFileMetadata(final URI uri, final FileRequestOptions fileOptions,
final OperationContext opContext, final AccessCondition accessCondition) throws IOException,
URISyntaxException, StorageException {
return setMetadata(uri, fileOptions, opContext, accessCondition, null);
} | java | {
"resource": ""
} |
q167708 | FileRequest.snapshotShare | validation | public static HttpURLConnection snapshotShare(final URI uri, final FileRequestOptions fileOptions,
final OperationContext opContext, final AccessCondition accessCondition) throws IOException,
URISyntaxException, StorageException {
final UriQueryBuilder builder = new UriQueryBuilder();
builder.add(Constants.QueryConstants.RESOURCETYPE, "share");
builder.add(Constants.QueryConstants.COMPONENT, Constants.QueryConstants.SNAPSHOT);
final HttpURLConnection request = BaseRequest.createURLConnection(uri, fileOptions, builder, opContext);
request.setFixedLengthStreamingMode(0);
request.setDoOutput(true);
request.setRequestMethod(Constants.HTTP_PUT);
if (accessCondition != null) {
accessCondition.applyConditionToRequest(request);
}
return request;
} | java | {
"resource": ""
} |
q167709 | FileRequest.setFileProperties | validation | public static HttpURLConnection setFileProperties(final URI uri, final FileRequestOptions fileOptions,
final OperationContext opContext, final AccessCondition accessCondition, final FileProperties properties)
throws IOException, URISyntaxException, StorageException {
final UriQueryBuilder builder = new UriQueryBuilder();
builder.add(Constants.QueryConstants.COMPONENT, Constants.QueryConstants.PROPERTIES);
final HttpURLConnection request = BaseRequest.createURLConnection(uri, fileOptions, builder, opContext);
request.setFixedLengthStreamingMode(0);
request.setDoOutput(true);
request.setRequestMethod(Constants.HTTP_PUT);
if (accessCondition != null) {
accessCondition.applyConditionToRequest(request);
}
if (properties != null) {
addProperties(request, properties);
}
return request;
} | java | {
"resource": ""
} |
q167710 | FileInputStream.close | validation | @Override
public synchronized void close() throws IOException {
this.currentBuffer = null;
this.streamFaulted = true;
this.lastError = new IOException(SR.STREAM_CLOSED);
} | java | {
"resource": ""
} |
q167711 | FileInputStream.dispatchRead | validation | @DoesServiceRequest
private synchronized void dispatchRead(final int readLength) throws IOException {
try {
final byte[] byteBuffer = new byte[readLength];
this.parentFileRef.downloadRangeInternal(this.currentAbsoluteReadPosition, (long) readLength, byteBuffer,
0, null /* this.accessCondition */, this.options, this.opContext);
// Check Etag manually for now -- use access condition once conditional headers supported.
if (this.accessCondition != null) {
if (!this.accessCondition.getIfMatch().equals(this.parentFileRef.getProperties().getEtag())) {
throw new StorageException(StorageErrorCode.CONDITION_FAILED.toString(),
SR.INVALID_CONDITIONAL_HEADERS, HttpURLConnection.HTTP_PRECON_FAILED, null, null);
}
}
this.currentBuffer = new ByteArrayInputStream(byteBuffer);
this.bufferSize = readLength;
this.bufferStartOffset = this.currentAbsoluteReadPosition;
}
catch (final StorageException e) {
this.streamFaulted = true;
this.lastError = Utility.initIOException(e);
throw this.lastError;
}
} | java | {
"resource": ""
} |
q167712 | FileInputStream.read | validation | @Override
@DoesServiceRequest
public int read() throws IOException {
final byte[] tBuff = new byte[1];
final int numberOfBytesRead = this.read(tBuff, 0, 1);
if (numberOfBytesRead > 0) {
return tBuff[0] & 0xFF;
}
else if (numberOfBytesRead == 0) {
throw new IOException(SR.UNEXPECTED_STREAM_READ_ERROR);
}
else {
return -1;
}
} | java | {
"resource": ""
} |
q167713 | FileInputStream.readInternal | validation | @DoesServiceRequest
private synchronized int readInternal(final byte[] b, final int off, int len) throws IOException {
this.checkStreamState();
// if buffer is empty do next get operation
if ((this.currentBuffer == null || this.currentBuffer.available() == 0)
&& this.currentAbsoluteReadPosition < this.streamLength) {
this.dispatchRead((int) Math.min(this.readSize, this.streamLength - this.currentAbsoluteReadPosition));
}
len = Math.min(len, this.readSize);
// do read from buffer
final int numberOfBytesRead = this.currentBuffer.read(b, off, len);
if (numberOfBytesRead > 0) {
this.currentAbsoluteReadPosition += numberOfBytesRead;
if (this.validateFileMd5) {
this.md5Digest.update(b, off, numberOfBytesRead);
if (this.currentAbsoluteReadPosition == this.streamLength) {
// Reached end of stream, validate md5.
final String calculatedMd5 = Base64.encode(this.md5Digest.digest());
if (!calculatedMd5.equals(this.retrievedContentMD5Value)) {
this.lastError = Utility
.initIOException(new StorageException(
StorageErrorCodeStrings.INVALID_MD5,
String.format(
"File data corrupted (integrity check failed), Expected value is %s, retrieved %s",
this.retrievedContentMD5Value, calculatedMd5),
Constants.HeaderConstants.HTTP_UNUSED_306, null, null));
this.streamFaulted = true;
throw this.lastError;
}
}
}
}
// update markers
if (this.markExpiry > 0 && this.markedPosition + this.markExpiry < this.currentAbsoluteReadPosition) {
this.markedPosition = 0;
this.markExpiry = 0;
}
return numberOfBytesRead;
} | java | {
"resource": ""
} |
q167714 | FileInputStream.reset | validation | @Override
public synchronized void reset() throws IOException {
if (this.markedPosition + this.markExpiry < this.currentAbsoluteReadPosition) {
throw new IOException(SR.MARK_EXPIRED);
}
this.validateFileMd5 = false;
this.md5Digest = null;
this.reposition(this.markedPosition);
} | java | {
"resource": ""
} |
q167715 | FileInputStream.skip | validation | @Override
public synchronized long skip(final long n) throws IOException {
if (n == 0) {
return 0;
}
if (n < 0 || this.currentAbsoluteReadPosition + n > this.streamLength) {
throw new IndexOutOfBoundsException();
}
this.validateFileMd5 = false;
this.md5Digest = null;
this.reposition(this.currentAbsoluteReadPosition + n);
return n;
} | java | {
"resource": ""
} |
q167716 | MainActivity.runBlobGettingStartedSample | validation | public void runBlobGettingStartedSample(View view) {
new BlobGettingStartedTask(this, (TextView) findViewById(R.id.textView))
.execute();
} | java | {
"resource": ""
} |
q167717 | MainActivity.runQueueGettingStartedSample | validation | public void runQueueGettingStartedSample(View view) {
new QueueGettingStartedTask(this,
(TextView) findViewById(R.id.textView)).execute();
} | java | {
"resource": ""
} |
q167718 | MainActivity.runTableGettingStartedSample | validation | public void runTableGettingStartedSample(View view) {
new TableGettingStartedTask(this,
(TextView) findViewById(R.id.textView)).execute();
} | java | {
"resource": ""
} |
q167719 | MainActivity.runTablePayloadFormatSample | validation | public void runTablePayloadFormatSample(View view) {
new TablePayloadFormatTask(this, (TextView) findViewById(R.id.textView))
.execute();
} | java | {
"resource": ""
} |
q167720 | MainActivity.outputText | validation | public void outputText(final TextView view, final String value) {
runOnUiThread(new Runnable() {
@Override
public void run() {
view.append(value + "\n");
System.out.println(view);
}
});
} | java | {
"resource": ""
} |
q167721 | MainActivity.printException | validation | public void printException(Throwable t) {
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
t.printStackTrace(printWriter);
outputText(
(TextView) findViewById(R.id.textView),
String.format(
"Got an exception from running samples. Exception details:\n%s\n",
stringWriter.toString()));
} | java | {
"resource": ""
} |
q167722 | MainActivity.printSampleStartInfo | validation | public void printSampleStartInfo(String sampleName) {
TextView view = (TextView) findViewById(R.id.textView);
clearText(view);
outputText(view, String.format(
"The Azure storage client library sample %s is starting...",
sampleName));
} | java | {
"resource": ""
} |
q167723 | MainActivity.printSampleCompleteInfo | validation | public void printSampleCompleteInfo(String sampleName) {
outputText((TextView) findViewById(R.id.textView), String.format(
"The Azure storage client library sample %s completed.\n",
sampleName));
} | java | {
"resource": ""
} |
q167724 | TableCanonicalizer.canonicalize | validation | @Override
protected String canonicalize(final HttpURLConnection conn, final String accountName, final Long contentLength)
throws StorageException {
if (contentLength < -1) {
throw new InvalidParameterException(SR.INVALID_CONTENT_LENGTH);
}
return canonicalizeTableHttpRequest(conn.getURL(), accountName, conn.getRequestMethod(),
Utility.getStandardHeaderValue(conn, Constants.HeaderConstants.CONTENT_TYPE), contentLength, null,
conn);
} | java | {
"resource": ""
} |
q167725 | OperationContext.getLastResult | validation | public synchronized RequestResult getLastResult() {
if (this.requestResults == null || this.requestResults.size() == 0) {
return null;
}
else {
return this.requestResults.get(this.requestResults.size() - 1);
}
} | java | {
"resource": ""
} |
q167726 | LogBlobIterator.isCorrectLogType | validation | private boolean isCorrectLogType(ListBlobItem current) {
HashMap<String, String> metadata = ((CloudBlob) current).getMetadata();
String logType = metadata.get("LogType");
if (logType == null) {
return true;
}
if (this.operations.contains(LoggingOperations.READ) && logType.contains("read")) {
return true;
}
if (this.operations.contains(LoggingOperations.WRITE) && logType.contains("write")) {
return true;
}
if (this.operations.contains(LoggingOperations.DELETE) && logType.contains("delete")) {
return true;
}
return false;
} | java | {
"resource": ""
} |
q167727 | LogBlobIterator.updateIterator | validation | private void updateIterator() throws StorageException, URISyntaxException {
if (this.currentPrefixTime != null && this.currentPrefixTime.isEmpty()) {
// If we've already called listBlobs() with an empty prefix, don't do so again.
this.isExpired = true;
return;
}
GregorianCalendar now = new GregorianCalendar();
now.add(GregorianCalendar.HOUR_OF_DAY, 1);
now.setTimeZone(TimeZone.getTimeZone("GMT"));
updatePrefix();
if ((this.startDate == null || this.startDate.compareTo(now) <= 0)
&& (this.endDate == null || ((this.logDirectory.getPrefix() + this.currentPrefixTime)
.compareTo(this.endPrefix) <= 0))) {
// Only make the next call if the prefix is still possible
this.currentIterator = this.logDirectory.listBlobs(this.currentPrefixTime, true, this.details,
this.options, this.opContext).iterator();
}
else {
// We are in the future.
this.isExpired = true;
}
} | java | {
"resource": ""
} |
q167728 | CloudFile.startCopy | validation | @DoesServiceRequest
public final String startCopy(final CloudBlob sourceBlob) throws StorageException, URISyntaxException {
return this.startCopy(sourceBlob, null /* sourceAccessCondition */,
null /* destinationAccessCondition */, null /* options */, null /* opContext */);
} | java | {
"resource": ""
} |
q167729 | CloudFile.startCopy | validation | @DoesServiceRequest
public final String startCopy(final CloudBlob sourceBlob, final AccessCondition sourceAccessCondition,
final AccessCondition destinationAccessCondition, FileRequestOptions options, OperationContext opContext)
throws StorageException, URISyntaxException {
Utility.assertNotNull("sourceBlob", sourceBlob);
URI source = sourceBlob.getSnapshotQualifiedUri();
if (sourceBlob.getServiceClient() != null && sourceBlob.getServiceClient().getCredentials() != null)
{
source = sourceBlob.getServiceClient().getCredentials().transformUri(sourceBlob.getSnapshotQualifiedUri());
}
return this.startCopy(source, sourceAccessCondition, destinationAccessCondition, options, opContext);
} | java | {
"resource": ""
} |
q167730 | CloudFile.startCopy | validation | @DoesServiceRequest
public final String startCopy(final CloudFile sourceFile) throws StorageException, URISyntaxException {
return this.startCopy(sourceFile, null /* sourceAccessCondition */,
null /* destinationAccessCondition */, null /* options */, null /* opContext */);
} | java | {
"resource": ""
} |
q167731 | CloudFile.startCopy | validation | @DoesServiceRequest
public final String startCopy(final CloudFile sourceFile, final AccessCondition sourceAccessCondition,
final AccessCondition destinationAccessCondition, FileRequestOptions options, OperationContext opContext)
throws StorageException, URISyntaxException {
Utility.assertNotNull("sourceFile", sourceFile);
return this.startCopy(sourceFile.getTransformedAddress(opContext).getPrimaryUri(),
sourceAccessCondition, destinationAccessCondition, options, opContext);
} | java | {
"resource": ""
} |
q167732 | CloudFile.startCopy | validation | @DoesServiceRequest
public final String startCopy(final URI source) throws StorageException, URISyntaxException {
return this.startCopy(source, null /* sourceAccessCondition */,
null /* destinationAccessCondition */, null /* options */, null /* opContext */);
} | java | {
"resource": ""
} |
q167733 | CloudFile.startCopy | validation | @DoesServiceRequest
public final String startCopy(final URI source, final AccessCondition sourceAccessCondition,
final AccessCondition destinationAccessCondition, FileRequestOptions options, OperationContext opContext)
throws StorageException, URISyntaxException {
if (opContext == null) {
opContext = new OperationContext();
}
this.getShare().assertNoSnapshot();
opContext.initialize();
options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient);
return ExecutionEngine.executeWithRetry(this.fileServiceClient, this,
this.startCopyImpl(source, sourceAccessCondition, destinationAccessCondition, options),
options.getRetryPolicyFactory(), opContext);
} | java | {
"resource": ""
} |
q167734 | CloudFile.create | validation | @DoesServiceRequest
public void create(final long size) throws StorageException, URISyntaxException {
this.create(size, null /* accessCondition */, null /* options */, null /* opContext */);
} | java | {
"resource": ""
} |
q167735 | CloudFile.create | validation | @DoesServiceRequest
public void create(final long size, final AccessCondition accessCondition, FileRequestOptions options,
OperationContext opContext) throws StorageException, URISyntaxException {
if (opContext == null) {
opContext = new OperationContext();
}
this.getShare().assertNoSnapshot();
options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient);
ExecutionEngine.executeWithRetry(this.fileServiceClient, this, this.createImpl(size, accessCondition, options),
options.getRetryPolicyFactory(), opContext);
} | java | {
"resource": ""
} |
q167736 | CloudFile.deleteEmptyFileOnException | validation | private void deleteEmptyFileOnException(OutputStream outputStream, String path) {
try {
outputStream.close();
File fileToDelete = new File(path);
fileToDelete.delete();
}
catch (Exception e) {
// Best effort delete.
}
} | java | {
"resource": ""
} |
q167737 | CloudFile.downloadText | validation | public String downloadText(final String charsetName, final AccessCondition accessCondition,
FileRequestOptions options, OperationContext opContext) throws StorageException, IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
this.download(baos, accessCondition, options, opContext);
return charsetName == null ? baos.toString() : baos.toString(charsetName);
} | java | {
"resource": ""
} |
q167738 | CloudFile.downloadFileRanges | validation | @DoesServiceRequest
public ArrayList<FileRange> downloadFileRanges(final AccessCondition accessCondition, FileRequestOptions options,
OperationContext opContext) throws StorageException {
if (opContext == null) {
opContext = new OperationContext();
}
options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient);
return ExecutionEngine.executeWithRetry(this.fileServiceClient, this,
this.downloadFileRangesImpl(accessCondition, options), options.getRetryPolicyFactory(), opContext);
} | java | {
"resource": ""
} |
q167739 | CloudFile.openWriteExisting | validation | @DoesServiceRequest
public FileOutputStream openWriteExisting() throws StorageException, URISyntaxException {
return this
.openOutputStreamInternal(null /* length */, null /* accessCondition */, null /* options */, null /* opContext */);
} | java | {
"resource": ""
} |
q167740 | CloudFile.openWriteExisting | validation | @DoesServiceRequest
public FileOutputStream openWriteExisting(AccessCondition accessCondition, FileRequestOptions options,
OperationContext opContext) throws StorageException, URISyntaxException {
return this.openOutputStreamInternal(null /* length */, accessCondition, options, opContext);
} | java | {
"resource": ""
} |
q167741 | CloudFile.openOutputStreamInternal | validation | private FileOutputStream openOutputStreamInternal(Long length, AccessCondition accessCondition,
FileRequestOptions options, OperationContext opContext) throws StorageException, URISyntaxException {
if (opContext == null) {
opContext = new OperationContext();
}
this.getShare().assertNoSnapshot();
options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient, false /* setStartTime */);
if (length != null) {
this.create(length, accessCondition, options, opContext);
}
else {
if (options.getStoreFileContentMD5()) {
throw new IllegalArgumentException(SR.FILE_MD5_NOT_POSSIBLE);
}
this.downloadAttributes(accessCondition, options, opContext);
length = this.getProperties().getLength();
}
if (accessCondition != null) {
accessCondition = AccessCondition.generateLeaseCondition(accessCondition.getLeaseID());
}
return new FileOutputStream(this, length, accessCondition, options, opContext);
} | java | {
"resource": ""
} |
q167742 | CloudFile.uploadFromFile | validation | public void uploadFromFile(final String path) throws StorageException, IOException, URISyntaxException {
uploadFromFile(path, null /* accessCondition */, null /* options */, null /* opContext */);
} | java | {
"resource": ""
} |
q167743 | CloudFile.uploadFromFile | validation | public void uploadFromFile(final String path, final AccessCondition accessCondition, FileRequestOptions options,
OperationContext opContext) throws StorageException, IOException, URISyntaxException {
File file = new File(path);
long fileLength = file.length();
InputStream inputStream = new BufferedInputStream(new java.io.FileInputStream(file));
this.upload(inputStream, fileLength, accessCondition, options, opContext);
inputStream.close();
} | java | {
"resource": ""
} |
q167744 | CloudFile.uploadText | validation | public void uploadText(final String content) throws StorageException, IOException, URISyntaxException {
this.uploadText(content, null /* charsetName */, null /* accessCondition */, null /* options */, null /* opContext */);
} | java | {
"resource": ""
} |
q167745 | CloudFile.uploadText | validation | public void uploadText(final String content, final String charsetName, final AccessCondition accessCondition,
FileRequestOptions options, OperationContext opContext) throws StorageException, IOException, URISyntaxException {
byte[] bytes = (charsetName == null) ? content.getBytes() : content.getBytes(charsetName);
this.uploadFromByteArray(bytes, 0, bytes.length, accessCondition, options, opContext);
} | java | {
"resource": ""
} |
q167746 | CloudFile.uploadRange | validation | @DoesServiceRequest
public void uploadRange(final InputStream sourceStream, final long offset, final long length)
throws StorageException, IOException, URISyntaxException {
this.uploadRange(sourceStream, offset, length, null /* accessCondition */, null /* options */, null /* opContext */);
} | java | {
"resource": ""
} |
q167747 | CloudFile.uploadRange | validation | @DoesServiceRequest
public void uploadRange(final InputStream sourceStream, final long offset, final long length,
final AccessCondition accessCondition, FileRequestOptions options, OperationContext opContext)
throws StorageException, IOException, URISyntaxException {
if (opContext == null) {
opContext = new OperationContext();
}
this.getShare().assertNoSnapshot();
options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient);
final FileRange range = new FileRange(offset, offset + length - 1);
final byte[] data = new byte[(int) length];
String md5 = null;
int count = 0;
int total = 0;
while (total < length) {
count = sourceStream.read(data, total, (int) Math.min(length - total, Integer.MAX_VALUE));
total += count;
}
if (options.getUseTransactionalContentMD5()) {
try {
final MessageDigest digest = MessageDigest.getInstance("MD5");
digest.update(data, 0, data.length);
md5 = Base64.encode(digest.digest());
}
catch (final NoSuchAlgorithmException e) {
// This wont happen, throw fatal.
throw Utility.generateNewUnexpectedStorageException(e);
}
}
this.putRangeInternal(range, FileRangeOperationType.UPDATE, data, length, md5, accessCondition, options,
opContext);
} | java | {
"resource": ""
} |
q167748 | CloudFile.putRangeInternal | validation | @DoesServiceRequest
private void putRangeInternal(final FileRange range, final FileRangeOperationType operationType, final byte[] data,
final long length, final String md5, final AccessCondition accessCondition,
final FileRequestOptions options, final OperationContext opContext) throws StorageException {
ExecutionEngine.executeWithRetry(this.fileServiceClient, this,
putRangeImpl(range, operationType, data, length, md5, accessCondition, options, opContext),
options.getRetryPolicyFactory(), opContext);
} | java | {
"resource": ""
} |
q167749 | CloudFile.resize | validation | public void resize(long size, AccessCondition accessCondition, FileRequestOptions options,
OperationContext opContext) throws StorageException, URISyntaxException {
if (opContext == null) {
opContext = new OperationContext();
}
this.getShare().assertNoSnapshot();
opContext.initialize();
options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient);
ExecutionEngine.executeWithRetry(this.fileServiceClient, this, this.resizeImpl(size, accessCondition, options),
options.getRetryPolicyFactory(), opContext);
} | java | {
"resource": ""
} |
q167750 | CloudFile.upload | validation | @DoesServiceRequest
public void upload(final InputStream sourceStream, final long length) throws StorageException, IOException, URISyntaxException {
this.upload(sourceStream, length, null /* accessCondition */, null /* options */, null /* opContext */);
} | java | {
"resource": ""
} |
q167751 | CloudFile.upload | validation | @DoesServiceRequest
public void upload(final InputStream sourceStream, final long length, final AccessCondition accessCondition,
FileRequestOptions options, OperationContext opContext) throws StorageException, IOException, URISyntaxException {
if (opContext == null) {
opContext = new OperationContext();
}
this.getShare().assertNoSnapshot();
options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient);
if (length < 0) {
throw new IllegalArgumentException(SR.INVALID_FILE_LENGTH);
}
if (sourceStream.markSupported()) {
// Mark sourceStream for current position.
sourceStream.mark(Constants.MAX_MARK_LENGTH);
}
final FileOutputStream streamRef = this.openWriteNew(length, accessCondition, options, opContext);
try {
streamRef.write(sourceStream, length);
}
finally {
streamRef.close();
}
} | java | {
"resource": ""
} |
q167752 | CloudFile.getParentNameFromURI | validation | protected static String getParentNameFromURI(final StorageUri resourceAddress, final CloudFileShare share)
throws URISyntaxException {
Utility.assertNotNull("resourceAddress", resourceAddress);
Utility.assertNotNull("share", share);
String delimiter = "/";
String shareName = share.getName() + delimiter;
String relativeURIString = Utility.safeRelativize(share.getStorageUri().getPrimaryUri(),
resourceAddress.getPrimaryUri());
if (relativeURIString.endsWith(delimiter)) {
relativeURIString = relativeURIString.substring(0, relativeURIString.length() - delimiter.length());
}
String parentName;
if (Utility.isNullOrEmpty(relativeURIString)) {
// Case 1 /<ShareName>[Delimiter]*? => /<ShareName>
// Parent of share is share itself
parentName = null;
}
else {
final int lastDelimiterDex = relativeURIString.lastIndexOf(delimiter);
if (lastDelimiterDex < 0) {
// Case 2 /<Share>/<Directory>
// Parent of a Directory is Share
parentName = "";
}
else {
// Case 3 /<Share>/<Directory>/[<subDirectory>/]*<FileName>
// Parent of CloudFile is CloudFileDirectory
parentName = relativeURIString.substring(0, lastDelimiterDex);
if (parentName != null && parentName.equals(shareName)) {
parentName = "";
}
}
}
return parentName;
} | java | {
"resource": ""
} |
q167753 | CloudFile.getShare | validation | @Override
public final CloudFileShare getShare() throws StorageException, URISyntaxException {
if (this.share == null) {
final StorageUri shareUri = PathUtility.getShareURI(this.getStorageUri(),
this.fileServiceClient.isUsePathStyleUris());
this.share = new CloudFileShare(shareUri, this.fileServiceClient.getCredentials());
}
return this.share;
} | java | {
"resource": ""
} |
q167754 | PathUtility.appendPathToSingleUri | validation | public static URI appendPathToSingleUri(final URI uri, final String relativeUri, final String separator)
throws URISyntaxException {
if (uri == null) {
return null;
}
if (relativeUri == null || relativeUri.isEmpty()) {
return uri;
}
if (uri.getPath().length() == 0 && relativeUri.startsWith(separator)) {
return new URI(uri.getScheme(), uri.getAuthority(), relativeUri, uri.getRawQuery(), uri.getRawFragment());
}
final StringBuilder pathString = new StringBuilder(uri.getPath());
if (uri.getPath().endsWith(separator)) {
pathString.append(relativeUri);
}
else {
pathString.append(separator);
pathString.append(relativeUri);
}
return new URI(uri.getScheme(), uri.getAuthority(), pathString.toString(), uri.getQuery(), uri.getFragment());
} | java | {
"resource": ""
} |
q167755 | PathUtility.getBlobNameFromURI | validation | public static String getBlobNameFromURI(final URI inURI, final boolean usePathStyleUris) throws URISyntaxException {
return Utility.safeRelativize(new URI(getContainerURI(new StorageUri(inURI), usePathStyleUris).getPrimaryUri()
.toString().concat("/")), inURI);
} | java | {
"resource": ""
} |
q167756 | PathUtility.getCanonicalPathFromCredentials | validation | public static String getCanonicalPathFromCredentials(final StorageCredentials credentials, final String absolutePath) {
final String account = credentials.getAccountName();
if (account == null) {
final String errorMessage = SR.CANNOT_CREATE_SAS_FOR_GIVEN_CREDENTIALS;
throw new IllegalArgumentException(errorMessage);
}
final StringBuilder builder = new StringBuilder("/");
builder.append(account);
builder.append(absolutePath);
return builder.toString();
} | java | {
"resource": ""
} |
q167757 | PathUtility.getContainerNameFromUri | validation | public static String getContainerNameFromUri(final URI resourceAddress, final boolean usePathStyleUris) {
return getResourceNameFromUri(resourceAddress, usePathStyleUris,
String.format("Invalid blob address '%s', missing container information", resourceAddress));
} | java | {
"resource": ""
} |
q167758 | PathUtility.getFileNameFromURI | validation | public static String getFileNameFromURI(final URI resourceAddress, final boolean usePathStyleUris) {
// generate an array of the different levels of the path
final String[] pathSegments = resourceAddress.getRawPath().split("/");
// usePathStyleUris ? baseuri/accountname/sharename/objectname : accountname.baseuri/sharename/objectname
final int shareIndex = usePathStyleUris ? 2 : 1;
if (pathSegments.length - 1 <= shareIndex) {
// legal file addresses cannot end with or before the sharename
throw new IllegalArgumentException(String.format("Invalid file address '%s'.", resourceAddress));
}
else {
// in a legal file address the lowest level is the filename
return pathSegments[pathSegments.length - 1];
}
} | java | {
"resource": ""
} |
q167759 | PathUtility.getShareNameFromUri | validation | public static String getShareNameFromUri(final URI resourceAddress, final boolean usePathStyleUris) {
return getResourceNameFromUri(resourceAddress, usePathStyleUris,
String.format("Invalid file address '%s', missing share information", resourceAddress));
} | java | {
"resource": ""
} |
q167760 | PathUtility.getTableNameFromUri | validation | public static String getTableNameFromUri(final URI resourceAddress, final boolean usePathStyleUris) {
return getResourceNameFromUri(resourceAddress, usePathStyleUris,
String.format("Invalid table address '%s', missing table information", resourceAddress));
} | java | {
"resource": ""
} |
q167761 | PathUtility.getResourceNameFromUri | validation | private static String getResourceNameFromUri(final URI resourceAddress, final boolean usePathStyleUris,
final String error) {
Utility.assertNotNull("resourceAddress", resourceAddress);
final String[] pathSegments = resourceAddress.getRawPath().split("/");
final int expectedPartsLength = usePathStyleUris ? 3 : 2;
if (pathSegments.length < expectedPartsLength) {
throw new IllegalArgumentException(error);
}
final String resourceName = usePathStyleUris ? pathSegments[2] : pathSegments[1];
return Utility.trimEnd(resourceName, '/');
} | java | {
"resource": ""
} |
q167762 | PathUtility.getContainerURI | validation | public static StorageUri getContainerURI(final StorageUri blobAddress, final boolean usePathStyleUris)
throws URISyntaxException {
final String containerName = getContainerNameFromUri(blobAddress.getPrimaryUri(), usePathStyleUris);
final StorageUri containerUri = appendPathToUri(getServiceClientBaseAddress(blobAddress, usePathStyleUris),
containerName);
return containerUri;
} | java | {
"resource": ""
} |
q167763 | PathUtility.getShareURI | validation | public static StorageUri getShareURI(final StorageUri fileAddress, final boolean usePathStyleUris)
throws URISyntaxException {
final String shareName = getShareNameFromUri(fileAddress.getPrimaryUri(), usePathStyleUris);
final StorageUri shareUri = appendPathToUri(getServiceClientBaseAddress(fileAddress, usePathStyleUris),
shareName);
return shareUri;
} | java | {
"resource": ""
} |
q167764 | PathUtility.parseQueryString | validation | public static HashMap<String, String[]> parseQueryString(String parseString) throws StorageException {
final HashMap<String, String[]> retVals = new HashMap<String, String[]>();
if (Utility.isNullOrEmpty(parseString)) {
return retVals;
}
// 1. Remove ? if present
final int queryDex = parseString.indexOf("?");
if (queryDex >= 0 && parseString.length() > 0) {
parseString = parseString.substring(queryDex + 1);
}
// 2. split name value pairs by splitting on the 'c&' character
final String[] valuePairs = parseString.contains("&") ? parseString.split("&") : parseString.split(";");
// 3. for each field value pair parse into appropriate map entries
for (int m = 0; m < valuePairs.length; m++) {
final int equalDex = valuePairs[m].indexOf("=");
if (equalDex < 0 || equalDex == valuePairs[m].length() - 1) {
continue;
}
String key = valuePairs[m].substring(0, equalDex);
String value = valuePairs[m].substring(equalDex + 1);
key = Utility.safeDecode(key);
value = Utility.safeDecode(value);
// 3.1 add to map
String[] values = retVals.get(key);
if (values == null) {
values = new String[] { value };
if (!value.equals(Constants.EMPTY_STRING)) {
retVals.put(key, values);
}
}
else if (!value.equals(Constants.EMPTY_STRING)) {
final String[] newValues = new String[values.length + 1];
for (int j = 0; j < values.length; j++) {
newValues[j] = values[j];
}
newValues[newValues.length] = value;
}
}
return retVals;
} | java | {
"resource": ""
} |
q167765 | SharedAccessSignatureHelper.generateSharedAccessSignatureHashForBlobAndFile | validation | public static String generateSharedAccessSignatureHashForBlobAndFile(final SharedAccessPolicy policy,
SharedAccessHeaders headers, final String accessPolicyIdentifier, final String resourceName,
final IPRange ipRange, final SharedAccessProtocols protocols, final ServiceClient client)
throws InvalidKeyException, StorageException {
String stringToSign = generateSharedAccessSignatureStringToSign(
policy, resourceName, ipRange, protocols, accessPolicyIdentifier);
String cacheControl = null;
String contentDisposition = null;
String contentEncoding = null;
String contentLanguage = null;
String contentType = null;
if (headers != null) {
cacheControl = headers.getCacheControl();
contentDisposition = headers.getContentDisposition();
contentEncoding = headers.getContentEncoding();
contentLanguage = headers.getContentLanguage();
contentType = headers.getContentType();
}
stringToSign = String.format("%s\n%s\n%s\n%s\n%s\n%s", stringToSign,
cacheControl == null ? Constants.EMPTY_STRING : cacheControl,
contentDisposition == null ? Constants.EMPTY_STRING : contentDisposition,
contentEncoding == null ? Constants.EMPTY_STRING : contentEncoding,
contentLanguage == null ? Constants.EMPTY_STRING : contentLanguage,
contentType == null ? Constants.EMPTY_STRING : contentType);
return generateSharedAccessSignatureHashHelper(stringToSign, client.getCredentials());
} | java | {
"resource": ""
} |
q167766 | SharedAccessSignatureHelper.generateSharedAccessSignatureHashForQueue | validation | public static String generateSharedAccessSignatureHashForQueue(
final SharedAccessQueuePolicy policy, final String accessPolicyIdentifier, final String resourceName,
final IPRange ipRange, final SharedAccessProtocols protocols, final ServiceClient client)
throws InvalidKeyException, StorageException {
final String stringToSign = generateSharedAccessSignatureStringToSign(
policy, resourceName, ipRange, protocols, accessPolicyIdentifier);
return generateSharedAccessSignatureHashHelper(stringToSign, client.getCredentials());
} | java | {
"resource": ""
} |
q167767 | SharedAccessSignatureHelper.generateSharedAccessSignatureHashForTable | validation | public static String generateSharedAccessSignatureHashForTable(
final SharedAccessTablePolicy policy, final String accessPolicyIdentifier, final String resourceName,
final IPRange ipRange, final SharedAccessProtocols protocols, final String startPartitionKey,
final String startRowKey, final String endPartitionKey, final String endRowKey, final ServiceClient client)
throws InvalidKeyException, StorageException {
String stringToSign = generateSharedAccessSignatureStringToSign(
policy, resourceName, ipRange, protocols, accessPolicyIdentifier);
stringToSign = String.format("%s\n%s\n%s\n%s\n%s", stringToSign,
startPartitionKey == null ? Constants.EMPTY_STRING : startPartitionKey,
startRowKey == null ? Constants.EMPTY_STRING : startRowKey,
endPartitionKey == null ? Constants.EMPTY_STRING : endPartitionKey,
endRowKey == null ? Constants.EMPTY_STRING : endRowKey);
return generateSharedAccessSignatureHashHelper(stringToSign, client.getCredentials());
} | java | {
"resource": ""
} |
q167768 | CloudFileDirectory.create | validation | @DoesServiceRequest
public void create(FileRequestOptions options, OperationContext opContext) throws StorageException, URISyntaxException {
if (opContext == null) {
opContext = new OperationContext();
}
this.getShare().assertNoSnapshot();
opContext.initialize();
options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient);
ExecutionEngine.executeWithRetry(this.fileServiceClient, this, createDirectoryImpl(options),
options.getRetryPolicyFactory(), opContext);
} | java | {
"resource": ""
} |
q167769 | CloudFileDirectory.createIfNotExists | validation | @DoesServiceRequest
public boolean createIfNotExists(FileRequestOptions options, OperationContext opContext) throws StorageException, URISyntaxException {
options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient);
this.getShare().assertNoSnapshot();
boolean exists = this.exists(true /* primaryOnly */, null /* accessCondition */, options, opContext);
if (exists) {
return false;
}
else {
try {
this.create(options, opContext);
return true;
}
catch (StorageException e) {
if (e.getHttpStatusCode() == HttpURLConnection.HTTP_CONFLICT
&& StorageErrorCodeStrings.RESOURCE_ALREADY_EXISTS.equals(e.getErrorCode())) {
return false;
}
else {
throw e;
}
}
}
} | java | {
"resource": ""
} |
q167770 | CloudFileDirectory.deleteIfExists | validation | @DoesServiceRequest
public boolean deleteIfExists(AccessCondition accessCondition, FileRequestOptions options,
OperationContext opContext) throws StorageException, URISyntaxException {
options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient);
boolean exists = this.exists(true /* primaryOnly */, accessCondition, options, opContext);
if (exists) {
try {
this.delete(accessCondition, options, opContext);
return true;
}
catch (StorageException e) {
if (e.getHttpStatusCode() == HttpURLConnection.HTTP_NOT_FOUND
&& StorageErrorCodeStrings.RESOURCE_NOT_FOUND.equals(e.getErrorCode())) {
return false;
}
else {
throw e;
}
}
}
else {
return false;
}
} | java | {
"resource": ""
} |
q167771 | CloudFileDirectory.exists | validation | @DoesServiceRequest
public boolean exists(final AccessCondition accessCondition, FileRequestOptions options, OperationContext opContext)
throws StorageException {
return this.exists(false, accessCondition, options, opContext);
} | java | {
"resource": ""
} |
q167772 | CloudFileDirectory.listFilesAndDirectoriesSegmented | validation | @DoesServiceRequest
public ResultSegment<ListFileItem> listFilesAndDirectoriesSegmented() throws StorageException {
return this.listFilesAndDirectoriesSegmented(null /* prefix */, null /* maxResults */,
null /* continuationToken */, null /* options */, null /* opContext */);
} | java | {
"resource": ""
} |
q167773 | CloudFileDirectory.getShare | validation | @Override
public CloudFileShare getShare() throws StorageException, URISyntaxException {
if (this.share == null) {
this.share = this.fileServiceClient.getShareReference(PathUtility.getShareNameFromUri(this.getUri(),
this.fileServiceClient.isUsePathStyleUris()));
}
return this.share;
} | java | {
"resource": ""
} |
q167774 | QueueRequest.clearMessages | validation | public static HttpURLConnection clearMessages(final URI uri, final QueueRequestOptions queueOptions,
final OperationContext opContext) throws URISyntaxException, IOException, StorageException {
return BaseRequest.delete(uri, queueOptions, null, opContext);
} | java | {
"resource": ""
} |
q167775 | QueueRequest.deleteMessage | validation | public static HttpURLConnection deleteMessage(final URI uri, final QueueRequestOptions queueOptions,
final OperationContext opContext, final String popReceipt) throws URISyntaxException, IOException,
StorageException {
final UriQueryBuilder builder = new UriQueryBuilder();
builder.add(POP_RECEIPT, popReceipt);
final HttpURLConnection request = BaseRequest.delete(uri, queueOptions, builder, opContext);
return request;
} | java | {
"resource": ""
} |
q167776 | QueueRequest.downloadAttributes | validation | public static HttpURLConnection downloadAttributes(final URI uri, final QueueRequestOptions queueOptions,
final OperationContext opContext) throws IOException, URISyntaxException, StorageException {
UriQueryBuilder builder = new UriQueryBuilder();
builder.add(Constants.QueryConstants.COMPONENT, METADATA);
final HttpURLConnection retConnection = BaseRequest.createURLConnection(uri, queueOptions, builder, opContext);
retConnection.setRequestMethod(Constants.HTTP_HEAD);
return retConnection;
} | java | {
"resource": ""
} |
q167777 | QueueRequest.list | validation | public static HttpURLConnection list(final URI uri, final QueueRequestOptions queueOptions,
final OperationContext opContext, final ListingContext listingContext,
final QueueListingDetails detailsIncluded) throws URISyntaxException, IOException, StorageException {
final UriQueryBuilder builder = BaseRequest.getListUriQueryBuilder(listingContext);
if (detailsIncluded == QueueListingDetails.ALL || detailsIncluded == QueueListingDetails.METADATA) {
builder.add(Constants.QueryConstants.INCLUDE, Constants.QueryConstants.METADATA);
}
final HttpURLConnection request = BaseRequest.createURLConnection(uri, queueOptions, builder, opContext);
request.setRequestMethod(Constants.HTTP_GET);
return request;
} | java | {
"resource": ""
} |
q167778 | QueueRequest.peekMessages | validation | public static HttpURLConnection peekMessages(final URI uri, final QueueRequestOptions queueOptions,
final OperationContext opContext, final int numberOfMessages) throws URISyntaxException, IOException,
StorageException {
final UriQueryBuilder builder = new UriQueryBuilder();
builder.add(PEEK_ONLY, "true");
if (numberOfMessages != 0) {
builder.add(NUMBER_OF_MESSAGES, Integer.toString(numberOfMessages));
}
final HttpURLConnection request = BaseRequest.createURLConnection(uri, queueOptions, builder, opContext);
request.setRequestMethod(Constants.HTTP_GET);
return request;
} | java | {
"resource": ""
} |
q167779 | QueueRequest.retrieveMessages | validation | public static HttpURLConnection retrieveMessages(final URI uri, final QueueRequestOptions queueOptions,
final OperationContext opContext, final int numberOfMessages, final int visibilityTimeoutInSeconds)
throws URISyntaxException, IOException, StorageException {
final UriQueryBuilder builder = new UriQueryBuilder();
if (numberOfMessages != 0) {
builder.add(NUMBER_OF_MESSAGES, Integer.toString(numberOfMessages));
}
builder.add(VISIBILITY_TIMEOUT, Integer.toString(visibilityTimeoutInSeconds));
final HttpURLConnection request = BaseRequest.createURLConnection(uri, queueOptions, builder, opContext);
request.setRequestMethod("GET");
return request;
} | java | {
"resource": ""
} |
q167780 | QueueRequest.updateMessage | validation | public static HttpURLConnection updateMessage(final URI uri, final QueueRequestOptions queueOptions,
final OperationContext opContext, final String popReceipt, final int visibilityTimeoutInSeconds)
throws URISyntaxException, IOException, StorageException {
final UriQueryBuilder builder = new UriQueryBuilder();
builder.add(POP_RECEIPT, popReceipt);
builder.add(VISIBILITY_TIMEOUT, Integer.toString(visibilityTimeoutInSeconds));
final HttpURLConnection request = BaseRequest.createURLConnection(uri, queueOptions, builder, opContext);
request.setDoOutput(true);
request.setRequestMethod(Constants.HTTP_PUT);
return request;
} | java | {
"resource": ""
} |
q167781 | QueueRequest.setAcl | validation | public static HttpURLConnection setAcl(final URI uri, final QueueRequestOptions queueOptions,
final OperationContext opContext) throws IOException, URISyntaxException, StorageException {
final UriQueryBuilder builder = new UriQueryBuilder();
builder.add(Constants.QueryConstants.COMPONENT, Constants.QueryConstants.ACL);
final HttpURLConnection request = BaseRequest.createURLConnection(uri, queueOptions, builder, opContext);
request.setDoOutput(true);
request.setRequestMethod(Constants.HTTP_PUT);
return request;
} | java | {
"resource": ""
} |
q167782 | QueueRequest.getAcl | validation | public static HttpURLConnection getAcl(final URI uri, final QueueRequestOptions queueOptions,
final OperationContext opContext) throws IOException, URISyntaxException, StorageException {
final UriQueryBuilder builder = new UriQueryBuilder();
builder.add(Constants.QueryConstants.COMPONENT, Constants.QueryConstants.ACL);
final HttpURLConnection request = BaseRequest.createURLConnection(uri, queueOptions, builder, opContext);
request.setRequestMethod(Constants.HTTP_GET);
return request;
} | java | {
"resource": ""
} |
q167783 | ServicePropertiesHandler.splitToList | validation | private static List<String> splitToList(String str, String delimiter) {
ArrayList<String> list = new ArrayList<String>();
StringTokenizer st = new StringTokenizer(str, delimiter);
while (st.hasMoreElements()) {
list.add(st.nextToken());
}
return list;
} | java | {
"resource": ""
} |
q167784 | ServicePropertiesHandler.splitToEnumSet | validation | private static EnumSet<CorsHttpMethods> splitToEnumSet(String str, String delimiter) {
EnumSet<CorsHttpMethods> set = EnumSet.noneOf(CorsHttpMethods.class);
StringTokenizer st = new StringTokenizer(str, delimiter);
while (st.hasMoreElements()) {
set.add(CorsHttpMethods.valueOf(st.nextToken()));
}
return set;
} | java | {
"resource": ""
} |
q167785 | StorageCredentialsAccountAndKey.updateKey | validation | public synchronized void updateKey(final byte[] key) {
if (key == null || key.length == 0) {
throw new IllegalArgumentException(SR.INVALID_KEY);
}
this.key = key;
this.hmacSha256 = null;
} | java | {
"resource": ""
} |
q167786 | StorageCredentialsAccountAndKey.getHmac256 | validation | public synchronized Mac getHmac256() throws InvalidKeyException {
if (this.hmacSha256 == null) {
// Initializes the HMAC-SHA256 Mac and SecretKey.
try {
this.hmacSha256 = Mac.getInstance("HmacSHA256");
}
catch (final NoSuchAlgorithmException e) {
throw new IllegalArgumentException();
}
this.hmacSha256.init(new SecretKeySpec(this.key, "HmacSHA256"));
}
return this.hmacSha256;
} | java | {
"resource": ""
} |
q167787 | IPRange.validateIPAddress | validation | private static void validateIPAddress(String ipAddress) {
try {
@SuppressWarnings("unused")
Inet4Address address = (Inet4Address) Inet4Address.getByName(ipAddress);
}
catch (Exception ex) {
throw new IllegalArgumentException(String.format(SR.INVALID_IP_ADDRESS, ipAddress), ex);
}
} | java | {
"resource": ""
} |
q167788 | Base64.decode | validation | public static byte[] decode(final String data) {
if (data == null) {
throw new IllegalArgumentException(SR.STRING_NOT_VALID);
}
int byteArrayLength = 3 * data.length() / 4;
if (data.endsWith("==")) {
byteArrayLength -= 2;
}
else if (data.endsWith("=")) {
byteArrayLength -= 1;
}
final byte[] retArray = new byte[byteArrayLength];
int byteDex = 0;
int charDex = 0;
for (; charDex < data.length(); charDex += 4) {
// get 4 chars, convert to 3 bytes
final int char1 = DECODE_64[(byte) data.charAt(charDex)];
final int char2 = DECODE_64[(byte) data.charAt(charDex + 1)];
final int char3 = DECODE_64[(byte) data.charAt(charDex + 2)];
final int char4 = DECODE_64[(byte) data.charAt(charDex + 3)];
if (char1 < 0 || char2 < 0 || char3 == -1 || char4 == -1) {
// invalid character(-1), or bad padding (-2)
throw new IllegalArgumentException(SR.STRING_NOT_VALID);
}
int tVal = char1 << 18;
tVal += char2 << 12;
tVal += (char3 & 0xff) << 6;
tVal += char4 & 0xff;
if (char3 == -2) {
// two "==" pad chars, check bits 12-24
tVal &= 0x00FFF000;
retArray[byteDex++] = (byte) (tVal >> 16 & 0xFF);
}
else if (char4 == -2) {
// one pad char "=" , check bits 6-24.
tVal &= 0x00FFFFC0;
retArray[byteDex++] = (byte) (tVal >> 16 & 0xFF);
retArray[byteDex++] = (byte) (tVal >> 8 & 0xFF);
}
else {
// No pads take all 3 bytes, bits 0-24
retArray[byteDex++] = (byte) (tVal >> 16 & 0xFF);
retArray[byteDex++] = (byte) (tVal >> 8 & 0xFF);
retArray[byteDex++] = (byte) (tVal & 0xFF);
}
}
return retArray;
} | java | {
"resource": ""
} |
q167789 | Base64.encode | validation | public static String encode(final Byte[] data) {
final StringBuilder builder = new StringBuilder();
final int dataRemainder = data.length % 3;
int j = 0;
int n = 0;
for (; j < data.length; j += 3) {
if (j < data.length - dataRemainder) {
n = ((data[j] & 0xFF) << 16) + ((data[j + 1] & 0xFF) << 8) + (data[j + 2] & 0xFF);
}
else {
if (dataRemainder == 1) {
n = (data[j] & 0xFF) << 16;
}
else if (dataRemainder == 2) {
n = ((data[j] & 0xFF) << 16) + ((data[j + 1] & 0xFF) << 8);
}
}
// Left here for readability
// byte char1 = (byte) ((n >>> 18) & 0x3F);
// byte char2 = (byte) ((n >>> 12) & 0x3F);
// byte char3 = (byte) ((n >>> 6) & 0x3F);
// byte char4 = (byte) (n & 0x3F);
builder.append(BASE_64_CHARS.charAt((byte) ((n >>> 18) & 0x3F)));
builder.append(BASE_64_CHARS.charAt((byte) ((n >>> 12) & 0x3F)));
builder.append(BASE_64_CHARS.charAt((byte) ((n >>> 6) & 0x3F)));
builder.append(BASE_64_CHARS.charAt((byte) (n & 0x3F)));
}
final int bLength = builder.length();
// append '=' to pad
if (data.length % 3 == 1) {
builder.replace(bLength - 2, bLength, "==");
}
else if (data.length % 3 == 2) {
builder.replace(bLength - 1, bLength, "=");
}
return builder.toString();
} | java | {
"resource": ""
} |
q167790 | Base64.validateIsBase64String | validation | public static boolean validateIsBase64String(final String data) {
if (data == null || data.length() % 4 != 0) {
return false;
}
for (int m = 0; m < data.length(); m++) {
final byte charByte = (byte) data.charAt(m);
// pad char detected
if (DECODE_64[charByte] == -2) {
if (m < data.length() - 2) {
return false;
}
else if (m == data.length() - 2 && DECODE_64[(byte) data.charAt(m + 1)] != -2) {
return false;
}
}
if (charByte < 0 || DECODE_64[charByte] == -1) {
return false;
}
}
return true;
} | java | {
"resource": ""
} |
q167791 | NameValidator.validateContainerName | validation | public static void validateContainerName(String containerName) {
if (!("$root".equals(containerName) || "$logs".equals(containerName))) {
NameValidator.validateShareContainerQueueHelper(containerName, SR.CONTAINER);
}
} | java | {
"resource": ""
} |
q167792 | NameValidator.validateBlobName | validation | public static void validateBlobName(String blobName) {
if (Utility.isNullOrEmptyOrWhitespace(blobName)) {
throw new IllegalArgumentException(String.format(Utility.LOCALE_US, SR.RESOURCE_NAME_EMPTY, SR.BLOB));
}
if (blobName.length() < NameValidator.BLOB_FILE_DIRECTORY_MIN_LENGTH || blobName.length() > NameValidator.BLOB_MAX_LENGTH) {
throw new IllegalArgumentException(String.format(Utility.LOCALE_US, SR.INVALID_RESOURCE_NAME_LENGTH, SR.BLOB, NameValidator.BLOB_FILE_DIRECTORY_MIN_LENGTH, NameValidator.BLOB_MAX_LENGTH));
}
int slashCount = 0;
for (int i = 0; i < blobName.length(); i++)
{
if (blobName.charAt(i) == '/')
{
slashCount++;
}
}
if (slashCount >= 254)
{
throw new IllegalArgumentException(SR.TOO_MANY_PATH_SEGMENTS);
}
} | java | {
"resource": ""
} |
q167793 | NameValidator.validateFileName | validation | public static void validateFileName(String fileName) {
NameValidator.ValidateFileDirectoryHelper(fileName, SR.FILE);
if (fileName.endsWith("/")) {
throw new IllegalArgumentException(String.format(Utility.LOCALE_US, SR.INVALID_RESOURCE_NAME, SR.FILE));
}
for (String s : NameValidator.RESERVED_FILE_NAMES) {
if (s.equalsIgnoreCase(fileName)) {
throw new IllegalArgumentException(String.format(Utility.LOCALE_US, SR.INVALID_RESOURCE_RESERVED_NAME, SR.FILE));
}
}
} | java | {
"resource": ""
} |
q167794 | NameValidator.validateTableName | validation | public static void validateTableName(String tableName) {
if (Utility.isNullOrEmptyOrWhitespace(tableName)) {
throw new IllegalArgumentException(String.format(Utility.LOCALE_US, SR.RESOURCE_NAME_EMPTY, SR.TABLE));
}
if (tableName.length() < NameValidator.CONTAINER_SHARE_QUEUE_TABLE_MIN_LENGTH || tableName.length() > NameValidator.CONTAINER_SHARE_QUEUE_TABLE_MAX_LENGTH) {
throw new IllegalArgumentException(String.format(Utility.LOCALE_US, SR.INVALID_RESOURCE_NAME_LENGTH, SR.TABLE, NameValidator.CONTAINER_SHARE_QUEUE_TABLE_MIN_LENGTH, NameValidator.CONTAINER_SHARE_QUEUE_TABLE_MAX_LENGTH));
}
if (!(NameValidator.TABLE_REGEX.matcher(tableName).matches()
|| NameValidator.METRICS_TABLE_REGEX.matcher(tableName).matches()
|| tableName.equalsIgnoreCase("$MetricsCapacityBlob"))) {
throw new IllegalArgumentException(String.format(Utility.LOCALE_US, SR.INVALID_RESOURCE_NAME, SR.TABLE));
}
} | java | {
"resource": ""
} |
q167795 | CloudFileClient.listShares | validation | @DoesServiceRequest
public Iterable<CloudFileShare> listShares(final String prefix) {
return this.listSharesWithPrefix(prefix, EnumSet.noneOf(ShareListingDetails.class), null /* options */, null /* opContext */);
} | java | {
"resource": ""
} |
q167796 | CloudFileClient.listShares | validation | @DoesServiceRequest
public Iterable<CloudFileShare> listShares(final String prefix, final EnumSet<ShareListingDetails> detailsIncluded,
final FileRequestOptions options, final OperationContext opContext) {
return this.listSharesWithPrefix(prefix, detailsIncluded, options, opContext);
} | java | {
"resource": ""
} |
q167797 | CloudFileClient.listSharesSegmented | validation | @DoesServiceRequest
public ResultSegment<CloudFileShare> listSharesSegmented() throws StorageException {
return this.listSharesSegmented(null, EnumSet.noneOf(ShareListingDetails.class), null, null /* continuationToken */,
null /* options */, null /* opContext */);
} | java | {
"resource": ""
} |
q167798 | CloudFileClient.listSharesSegmented | validation | @DoesServiceRequest
public ResultSegment<CloudFileShare> listSharesSegmented(final String prefix) throws StorageException {
return this.listSharesWithPrefixSegmented(prefix, EnumSet.noneOf(ShareListingDetails.class), null, null /* continuationToken */,
null /* options */, null /* opContext */);
} | java | {
"resource": ""
} |
q167799 | CloudFileClient.listSharesWithPrefix | validation | private Iterable<CloudFileShare> listSharesWithPrefix(final String prefix,
final EnumSet<ShareListingDetails> detailsIncluded, FileRequestOptions options, OperationContext opContext) {
if (opContext == null) {
opContext = new OperationContext();
}
opContext.initialize();
options = FileRequestOptions.populateAndApplyDefaults(options, this);
SegmentedStorageRequest segmentedRequest = new SegmentedStorageRequest();
return new LazySegmentedIterable<CloudFileClient, Void, CloudFileShare>(this.listSharesWithPrefixSegmentedImpl(
prefix, detailsIncluded, null, options, segmentedRequest), this, null, options.getRetryPolicyFactory(),
opContext);
} | java | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.