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

Java BinaryUtils类代码示例

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

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



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

示例1: testWriterWithExistingStream

import com.amazonaws.util.BinaryUtils; //导入依赖的package包/类
@Test
public void testWriterWithExistingStream() throws Exception
{
    initialize("TestKinesisAppender/testWriterWithExistingStream.properties");

    MockKinesisClient mockClient = new MockKinesisClient();

    appender.setThreadFactory(new DefaultThreadFactory());
    appender.setWriterFactory(mockClient.newWriterFactory());

    logger.debug("example message");
    mockClient.allowWriterThread();

    assertEquals("describeStream: invocation count",        1,          mockClient.describeStreamInvocationCount);
    assertEquals("describeStream: stream name",             "argle",    mockClient.describeStreamStreamName);
    assertEquals("createStream: invocation count",          0,          mockClient.createStreamInvocationCount);
    assertEquals("putRecords: invocation count",            1,          mockClient.putRecordsInvocationCount);
    assertEquals("putRecords: source record count",         1,          mockClient.putRecordsSourceRecords.size());
    assertEquals("putRecords: source record partition key", "bargle",   mockClient.putRecordsSourceRecords.get(0).getPartitionKey());
    assertEquals("putRecords: source record content",       "example message\n",
                                                            new String(
                                                                BinaryUtils.copyAllBytesFrom(mockClient.putRecordsSourceRecords.get(0).getData()),
                                                                "UTF-8"));
}
 
开发者ID:kdgregory,项目名称:log4j-aws-appenders,代码行数:25,代码来源:TestKinesisAppender.java


示例2: createStringToSign

import com.amazonaws.util.BinaryUtils; //导入依赖的package包/类
/**
 * Step 2 of the AWS Signature version 4 calculation. Refer to
 * http://docs.aws
 * .amazon.com/general/latest/gr/sigv4-create-string-to-sign.html.
 */
protected String createStringToSign(String canonicalRequest,
        AWS4SignerRequestParams signerParams) {

    final StringBuilder stringToSignBuilder = new StringBuilder(
            signerParams.getSigningAlgorithm());
    stringToSignBuilder.append(LINE_SEPARATOR)
            .append(signerParams.getFormattedSigningDateTime())
            .append(LINE_SEPARATOR)
            .append(signerParams.getScope())
            .append(LINE_SEPARATOR)
            .append(BinaryUtils.toHex(hash(canonicalRequest)));

    final String stringToSign = stringToSignBuilder.toString();

    if (log.isDebugEnabled())
        log.debug("AWS4 String to Sign: '\"" + stringToSign + "\"");

    return stringToSign;
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:25,代码来源:AWS4Signer.java


示例3: buildAuthorizationHeader

import com.amazonaws.util.BinaryUtils; //导入依赖的package包/类
/**
 * Creates the authorization header to be included in the request.
 */
private String buildAuthorizationHeader(SignableRequest<?> request,
        byte[] signature, AWSCredentials credentials,
        AWS4SignerRequestParams signerParams) {
    final String signingCredentials = credentials.getAWSAccessKeyId() + "/"
            + signerParams.getScope();

    final String credential = "Credential="
            + signingCredentials;
    final String signerHeaders = "SignedHeaders="
            + getSignedHeadersString(request);
    final String signatureHeader = "Signature="
            + BinaryUtils.toHex(signature);

    final StringBuilder authHeaderBuilder = new StringBuilder();

    authHeaderBuilder.append(AWS4_SIGNING_ALGORITHM)
                     .append(" ")
                     .append(credential)
                     .append(", ")
                     .append(signerHeaders)
                     .append(", ")
                     .append(signatureHeader);

    return authHeaderBuilder.toString();
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:29,代码来源:AWS4Signer.java


示例4: finishSimpleUpload

import com.amazonaws.util.BinaryUtils; //导入依赖的package包/类
private void finishSimpleUpload() {
    ObjectMetadata objectMetadata = new ObjectMetadata();
    objectMetadata.setContentLength(this.currentOutputStream.size());

    byte[] content = this.currentOutputStream.toByteArray();
    try {
        MessageDigest messageDigest = MessageDigest.getInstance("MD5");
        String md5Digest = BinaryUtils.toBase64(messageDigest.digest(content));
        objectMetadata.setContentMD5(md5Digest);
    } catch (NoSuchAlgorithmException e) {
        throw new IllegalStateException("MessageDigest could not be initialized because it uses an unknown algorithm", e);
    }

    SimpleStorageResource.this.amazonS3.putObject(SimpleStorageResource.this.bucketName, SimpleStorageResource.this.objectName,
            new ByteArrayInputStream(content), objectMetadata);

    //Release the memory early
    this.currentOutputStream = null;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:20,代码来源:SimpleStorageResource.java


示例5: testWriterWithNewStream

import com.amazonaws.util.BinaryUtils; //导入依赖的package包/类
@Test
public void testWriterWithNewStream() throws Exception
{
    initialize("TestKinesisAppender/testWriterWithNewStream.properties");

    MockKinesisClient mockClient = new MockKinesisClient();

    appender.setThreadFactory(new DefaultThreadFactory());
    appender.setWriterFactory(mockClient.newWriterFactory());

    logger.debug("example message");
    mockClient.allowWriterThread();

    // writer calls describeStream once to see if stream exists, a second time
    // to verify that it's active -- could perhaps combine those calls?

    assertEquals("describeStream: invocation count",        3,          mockClient.describeStreamInvocationCount);
    assertEquals("describeStream: stream name",             "foo",      mockClient.describeStreamStreamName);
    assertEquals("createStream: invocation count",          1,          mockClient.createStreamInvocationCount);
    assertEquals("createStream: stream name",               "foo",      mockClient.createStreamStreamName);
    assertEquals("putRecords: invocation count",            1,          mockClient.putRecordsInvocationCount);
    assertEquals("putRecords: source record count",         1,          mockClient.putRecordsSourceRecords.size());
    assertEquals("putRecords: source record partition key", "bar",      mockClient.putRecordsSourceRecords.get(0).getPartitionKey());
    assertEquals("putRecords: source record content",       "example message\n",
                                                            new String(
                                                                BinaryUtils.copyAllBytesFrom(mockClient.putRecordsSourceRecords.get(0).getData()),
                                                                "UTF-8"));
}
 
开发者ID:kdgregory,项目名称:log4j-aws-appenders,代码行数:29,代码来源:TestKinesisAppender.java


示例6: testStaticClientFactory

import com.amazonaws.util.BinaryUtils; //导入依赖的package包/类
@Test
public void testStaticClientFactory() throws Exception
{
    initialize("TestKinesisAppender/testStaticClientFactory.properties");
    appender.setThreadFactory(new DefaultThreadFactory());
    appender.setWriterFactory(new KinesisWriterFactory());

    // first message triggers writer creation

    logger.debug("example message");
    waitForInitialization();
    AbstractLogWriter writer = (AbstractLogWriter)appender.getWriter();

    assertNotNull("factory was called to create client", staticFactoryMock);
    assertEquals("no initialization errors",             "",
                                                         writer.getInitializationMessage());
    assertEquals("factory method called",                "com.kdgregory.log4j.aws.TestKinesisAppender.createMockClient",
                                                         writer.getClientFactoryUsed());

    // although we should be happy at this point, we'll actually verify that the
    // message got written; assertions copied from testWriterWithExistingStream()

    staticFactoryMock.allowWriterThread();

    assertEquals("describeStream: invocation count",        1,          staticFactoryMock.describeStreamInvocationCount);
    assertEquals("describeStream: stream name",             "argle",    staticFactoryMock.describeStreamStreamName);
    assertEquals("createStream: invocation count",          0,          staticFactoryMock.createStreamInvocationCount);
    assertEquals("putRecords: invocation count",            1,          staticFactoryMock.putRecordsInvocationCount);
    assertEquals("putRecords: source record count",         1,          staticFactoryMock.putRecordsSourceRecords.size());
    assertEquals("putRecords: source record partition key", "bargle",   staticFactoryMock.putRecordsSourceRecords.get(0).getPartitionKey());
    assertEquals("putRecords: source record content",       "example message\n",
                                                            new String(
                                                                BinaryUtils.copyAllBytesFrom(staticFactoryMock.putRecordsSourceRecords.get(0).getData()),
                                                                "UTF-8"));
}
 
开发者ID:kdgregory,项目名称:log4j-aws-appenders,代码行数:36,代码来源:TestKinesisAppender.java


示例7: RetrievedRecord

import com.amazonaws.util.BinaryUtils; //导入依赖的package包/类
public RetrievedRecord(String shardId, Record record)
throws Exception
{
    this.shardId = shardId;
    this.partitionKey = record.getPartitionKey();
    this.message = new String(BinaryUtils.copyAllBytesFrom(record.getData()), "UTF-8").trim();
}
 
开发者ID:kdgregory,项目名称:log4j-aws-appenders,代码行数:8,代码来源:KinesisAppenderIntegrationTest.java


示例8: getObjectMD5

import com.amazonaws.util.BinaryUtils; //导入依赖的package包/类
private String getObjectMD5(byte[] objectData) {
  byte[] expectedMd5 = null;
  try {
    expectedMd5 = Md5Utils.computeMD5Hash(objectData);
  } catch (Exception e) {}
  return BinaryUtils.toHex(expectedMd5);
}
 
开发者ID:daflockinger,项目名称:unitstack,代码行数:8,代码来源:MockS3Test.java


示例9: getAwsMessageMD5

import com.amazonaws.util.BinaryUtils; //导入依赖的package包/类
private String getAwsMessageMD5(String message) {
  byte[] expectedMd5 = null;
  try {
    expectedMd5 = Md5Utils.computeMD5Hash(message.getBytes(UTF8));
  } catch (Exception e) {}
  return BinaryUtils.toHex(expectedMd5);
}
 
开发者ID:daflockinger,项目名称:unitstack,代码行数:8,代码来源:MockSqsTest.java


示例10: marshallBinaryPayload

import com.amazonaws.util.BinaryUtils; //导入依赖的package包/类
/**
 * Binary data should be placed as is, directly into the content.
 */
private void marshallBinaryPayload(Object val) {
    if (val instanceof ByteBuffer) {
        request.setContent(BinaryUtils.toStream((ByteBuffer) val));
    } else if (val instanceof InputStream) {
        request.setContent((InputStream) val);
    }
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:11,代码来源:JsonProtocolMarshaller.java


示例11: writeValue

import com.amazonaws.util.BinaryUtils; //导入依赖的package包/类
@Override
public StructuredJsonGenerator writeValue(ByteBuffer bytes) {
    try {
        writer.writeBlob(BinaryUtils.copyAllBytesFrom(bytes));
    } catch (IOException e) {
        throw new SdkClientException(e);
    }
    return this;
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:10,代码来源:SdkIonGenerator.java


示例12: writeValue

import com.amazonaws.util.BinaryUtils; //导入依赖的package包/类
@Override
public StructuredJsonGenerator writeValue(ByteBuffer bytes) {
    try {
        generator.writeBinary(BinaryUtils.copyBytesFrom(bytes));
    } catch (IOException e) {
        throw new JsonGenerationException(e);
    }
    return this;
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:10,代码来源:SdkJsonGenerator.java


示例13: presignRequest

import com.amazonaws.util.BinaryUtils; //导入依赖的package包/类
@Override
public void presignRequest(SignableRequest<?> request, AWSCredentials credentials,
        Date userSpecifiedExpirationDate) {

    // anonymous credentials, don't sign
    if (isAnonymous(credentials)) {
        return;
    }

    long expirationInSeconds = generateExpirationDate(userSpecifiedExpirationDate);

    addHostHeader(request);

    AWSCredentials sanitizedCredentials = sanitizeCredentials(credentials);
    if (sanitizedCredentials instanceof AWSSessionCredentials) {
        // For SigV4 pre-signing URL, we need to add "X-Amz-Security-Token"
        // as a query string parameter, before constructing the canonical
        // request.
        request.addParameter(X_AMZ_SECURITY_TOKEN,
                ((AWSSessionCredentials) sanitizedCredentials)
                        .getSessionToken());
    }

    final AWS4SignerRequestParams signerRequestParams = new AWS4SignerRequestParams(
            request, overriddenDate, regionName, serviceName,
            AWS4_SIGNING_ALGORITHM);

    // Add the important parameters for v4 signing
    final String timeStamp = signerRequestParams.getFormattedSigningDateTime();

    addPreSignInformationToRequest(request, sanitizedCredentials,
            signerRequestParams, timeStamp, expirationInSeconds);

    final String contentSha256 = calculateContentHashPresign(request);

    final String canonicalRequest = createCanonicalRequest(request,
            contentSha256);

    final String stringToSign = createStringToSign(canonicalRequest,
            signerRequestParams);

    final byte[] signingKey = deriveSigningKey(sanitizedCredentials,
            signerRequestParams);

    final byte[] signature = computeSignature(stringToSign, signingKey,
            signerRequestParams);

    request.addParameter(X_AMZ_SIGNATURE, BinaryUtils.toHex(signature));
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:50,代码来源:AWS4Signer.java


示例14: calculateContentHash

import com.amazonaws.util.BinaryUtils; //导入依赖的package包/类
/**
 * Calculate the hash of the request's payload. Subclass could override this
 * method to provide different values for "x-amz-content-sha256" header or
 * do any other necessary set-ups on the request headers. (e.g. aws-chunked
 * uses a pre-defined header value, and needs to change some headers
 * relating to content-encoding and content-length.)
 */
protected String calculateContentHash(SignableRequest<?> request) {
    InputStream payloadStream = getBinaryRequestPayloadStream(request);
    ReadLimitInfo info = request.getReadLimitInfo();
    payloadStream.mark(info == null ? -1 : info.getReadLimit());
    String contentSha256 = BinaryUtils.toHex(hash(payloadStream));
    try {
        payloadStream.reset();
    } catch (IOException e) {
        throw new SdkClientException(
                "Unable to reset stream after calculating AWS4 signature",
                e);
    }
    return contentSha256;
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:22,代码来源:AWS4Signer.java


示例15: createSignedChunk

import com.amazonaws.util.BinaryUtils; //导入依赖的package包/类
private byte[] createSignedChunk(byte[] chunkData) {
    StringBuilder chunkHeader = new StringBuilder();
    // chunk-size
    chunkHeader.append(Integer.toHexString(chunkData.length));
    // sig-extension
    final String chunkStringToSign =
            CHUNK_STRING_TO_SIGN_PREFIX + "\n" +
            dateTime + "\n" +
            keyPath + "\n" +
            priorChunkSignature + "\n" +
            AbstractAWSSigner.EMPTY_STRING_SHA256_HEX + "\n" +
            BinaryUtils.toHex(sha256.digest(chunkData));
    final String chunkSignature =
        BinaryUtils.toHex(aws4Signer.signWithMac(chunkStringToSign, hmacSha256));
    priorChunkSignature = chunkSignature;
    chunkHeader.append(CHUNK_SIGNATURE_HEADER)
               .append(chunkSignature)
               .append(CRLF)
               ;
    try {
        byte[] header = chunkHeader.toString().getBytes(UTF8);
        byte[] trailer = CRLF.getBytes(UTF8);
        byte[] signedChunk = new byte[header.length + chunkData.length + trailer.length];
        System.arraycopy(header, 0, signedChunk, 0, header.length);
        System.arraycopy(chunkData, 0, signedChunk, header.length, chunkData.length);
        System.arraycopy(trailer, 0,
                signedChunk, header.length + chunkData.length,
                trailer.length);
        return signedChunk;
    } catch (Exception e) {
        throw new SdkClientException("Unable to sign the chunked data. " + e.getMessage(), e);
    }
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:34,代码来源:AwsChunkedEncodingInputStream.java


示例16: setBucketCrossOriginConfiguration

import com.amazonaws.util.BinaryUtils; //导入依赖的package包/类
@Override
public void setBucketCrossOriginConfiguration(
        SetBucketCrossOriginConfigurationRequest setBucketCrossOriginConfigurationRequest) {
    setBucketCrossOriginConfigurationRequest = beforeClientExecution(setBucketCrossOriginConfigurationRequest);
    rejectNull(setBucketCrossOriginConfigurationRequest,
            "The set bucket cross origin configuration request object must be specified.");

    String bucketName = setBucketCrossOriginConfigurationRequest.getBucketName();
    BucketCrossOriginConfiguration bucketCrossOriginConfiguration = setBucketCrossOriginConfigurationRequest.getCrossOriginConfiguration();

    rejectNull(bucketName,
            "The bucket name parameter must be specified when setting bucket cross origin configuration.");
    rejectNull(bucketCrossOriginConfiguration,
            "The cross origin configuration parameter must be specified when setting bucket cross origin configuration.");

    Request<SetBucketCrossOriginConfigurationRequest> request = createRequest(bucketName, null, setBucketCrossOriginConfigurationRequest, HttpMethodName.PUT);
    request.addParameter("cors", null);

    byte[] content = new BucketConfigurationXmlFactory().convertToXmlByteArray(bucketCrossOriginConfiguration);
    request.addHeader("Content-Length", String.valueOf(content.length));
    request.addHeader("Content-Type", "application/xml");
    request.setContent(new ByteArrayInputStream(content));
    try {
        byte[] md5 = Md5Utils.computeMD5Hash(content);
        String md5Base64 = BinaryUtils.toBase64(md5);
        request.addHeader("Content-MD5", md5Base64);
    } catch ( Exception e ) {
        throw new SdkClientException("Couldn't compute md5 sum", e);
    }

    invoke(request, voidResponseHandler, bucketName, null);
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:33,代码来源:AmazonS3Client.java


示例17: setBucketTaggingConfiguration

import com.amazonaws.util.BinaryUtils; //导入依赖的package包/类
@Override
public void setBucketTaggingConfiguration(
        SetBucketTaggingConfigurationRequest setBucketTaggingConfigurationRequest) {
    setBucketTaggingConfigurationRequest = beforeClientExecution(setBucketTaggingConfigurationRequest);
    rejectNull(setBucketTaggingConfigurationRequest,
            "The set bucket tagging configuration request object must be specified.");

    String bucketName = setBucketTaggingConfigurationRequest.getBucketName();
    BucketTaggingConfiguration bucketTaggingConfiguration = setBucketTaggingConfigurationRequest.getTaggingConfiguration();

    rejectNull(bucketName,
            "The bucket name parameter must be specified when setting bucket tagging configuration.");
    rejectNull(bucketTaggingConfiguration,
            "The tagging configuration parameter must be specified when setting bucket tagging configuration.");

    Request<SetBucketTaggingConfigurationRequest> request = createRequest(bucketName, null, setBucketTaggingConfigurationRequest, HttpMethodName.PUT);
    request.addParameter("tagging", null);

    byte[] content = new BucketConfigurationXmlFactory().convertToXmlByteArray(bucketTaggingConfiguration);
    request.addHeader("Content-Length", String.valueOf(content.length));
    request.addHeader("Content-Type", "application/xml");
    request.setContent(new ByteArrayInputStream(content));
    try {
        byte[] md5 = Md5Utils.computeMD5Hash(content);
        String md5Base64 = BinaryUtils.toBase64(md5);
        request.addHeader("Content-MD5", md5Base64);
    } catch ( Exception e ) {
        throw new SdkClientException("Couldn't compute md5 sum", e);
    }

    invoke(request, voidResponseHandler, bucketName, null);
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:33,代码来源:AmazonS3Client.java


示例18: setContent

import com.amazonaws.util.BinaryUtils; //导入依赖的package包/类
private void setContent(Request<?> request, byte[] content, String contentType, boolean setMd5) {
    request.setContent(new ByteArrayInputStream(content));
    request.addHeader("Content-Length", Integer.toString(content.length));
    request.addHeader("Content-Type", contentType);
    if (setMd5) {
        try {
            byte[] md5 = Md5Utils.computeMD5Hash(content);
            String md5Base64 = BinaryUtils.toBase64(md5);
            request.addHeader("Content-MD5", md5Base64);
        } catch ( Exception e ) {
            throw new AmazonClientException("Couldn't compute md5 sum", e);
        }
    }
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:15,代码来源:AmazonS3Client.java


示例19: processRequestPayload

import com.amazonaws.util.BinaryUtils; //导入依赖的package包/类
/**
 * If necessary, creates a chunk-encoding wrapper on the request payload.
 */
@Override
protected void processRequestPayload(SignableRequest<?> request, byte[] signature,
        byte[] signingKey, AWS4SignerRequestParams signerRequestParams) {
    if (useChunkEncoding(request)) {
        AwsChunkedEncodingInputStream chunkEncodededStream = new AwsChunkedEncodingInputStream(
                request.getContent(), signingKey,
                signerRequestParams.getFormattedSigningDateTime(),
                signerRequestParams.getScope(),
                BinaryUtils.toHex(signature), this);
        request.setContent(chunkEncodededStream);
    }
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:16,代码来源:AWSS3V4Signer.java


示例20: uploadContents

import com.amazonaws.util.BinaryUtils; //导入依赖的package包/类
private void uploadContents(String bucket, String key, byte[] contents)
        throws IOException {
    int failures = 0;
    boolean uploaded = false;
    while (!uploaded) {
        ObjectMetadata objectMetadata = new ObjectMetadata();
        objectMetadata.setContentType(MediaType.TEXT_PLAIN);
        objectMetadata.setContentLength(contents.length);
        objectMetadata.setContentMD5(BinaryUtils.toBase64(Hashing.md5().hashBytes(contents).asBytes()));

        try {
            _amazonS3.putObject(
                    new PutObjectRequest(bucket, key, new ByteArrayInputStream(contents), objectMetadata));
            uploaded = true;
        } catch (AmazonClientException e) {
            if (++failures == MAX_RETRIES) {
                throw new IOException(e);
            }
            try {
                Thread.sleep(_retryDelay.getMillis());
            } catch (InterruptedException e2) {
                // Stop retrying and propagate the original exception
                throw new IOException(e);
            }
        }
    }
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:28,代码来源:S3ScanWriter.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java ProgressView类代码示例发布时间:2022-05-22
下一篇:
Java Serie类代码示例发布时间: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