GoawayException(long errorCode, ByteBuf debugData) { this.errorCode = errorCode; this.debugData = BinaryUtils.copyBytesFrom(debugData.nioBuffer()); }
/** * Adds the specified value as Base64 encoded text to the current position of the in * progress XML document. * * @param b * The binary data to add to the XML document. * * @return This XMLWriter so that additional method calls can be chained * together. */ public XmlWriter value(ByteBuffer b) { append(escapeXmlEntities(BinaryUtils.toBase64(BinaryUtils.copyBytesFrom(b)))); return this; }
/** * Unmarshalls a string header, taking into account whether it's a Base 64 encoded JSON value. * * @param value Value to unmarshall * @param field {@link SdkField} containing metadata about member being unmarshalled. * @return Unmarshalled value. */ private static String unmarshallStringHeader(String value, SdkField<String> field) { return field.containsTrait(JsonValueTrait.class) ? new String(BinaryUtils.fromBase64(value), StandardCharsets.UTF_8) : value; }
/** * Add a field to the to-string result. * @param fieldName The name of the field. Must not be null. * @param field The value of the field. Value is ignored if null. */ public ToString add(String fieldName, Object field) { if (field != null) { String value; if (field.getClass().isArray()) { if (field instanceof byte[]) { value = "0x" + BinaryUtils.toHex((byte[]) field); } else { value = Arrays.toString((Object[]) field); } } else { value = String.valueOf(field); } result.append(fieldName).append("=").append(value).append(", "); } return this; }
/** * Returns the MD5 in base64 for the given byte array. */ public static String md5AsBase64(byte[] input) { return BinaryUtils.toBase64(computeMD5Hash(input)); }
/** * Client side validation for {@link PutObjectRequest} * * @param response the response * @param executionAttributes the execution attributes */ public static void validatePutObjectChecksum(PutObjectResponse response, ExecutionAttributes executionAttributes) { SdkChecksum checksum = executionAttributes.getAttribute(CHECKSUM); if (response.eTag() != null) { String contentMd5 = BinaryUtils.toBase64(checksum.getChecksumBytes()); byte[] digest = BinaryUtils.fromBase64(contentMd5); byte[] ssHash = Base16Lower.decode(response.eTag().replace("\"", "")); if (!Arrays.equals(digest, ssHash)) { throw SdkClientException.create("Data read has a different checksum than expected."); } } }
@Override public StructuredJsonGenerator writeValue(ByteBuffer bytes) { try { writer.writeBlob(BinaryUtils.copyAllBytesFrom(bytes)); } catch (IOException e) { throw SdkClientException.builder().cause(e).build(); } return this; }
/** * Converts byte data to a Base64-encoded string. * @param data * * data to Base64 encode. * @return encoded Base64 string. */ public static String toBase64(byte[] data) { return data == null ? null : new String(toBase64Bytes(data), StandardCharsets.UTF_8); }
/** * Add a field to the to-string result. * @param fieldName The name of the field. Must not be null. * @param field The value of the field. Value is ignored if null. */ public ToString add(String fieldName, Object field) { if (field != null) { String value; if (field.getClass().isArray()) { if (field instanceof byte[]) { value = "0x" + BinaryUtils.toHex((byte[]) field); } else { value = Arrays.toString((Object[]) field); } } else { value = String.valueOf(field); } result.append(fieldName).append("=").append(value).append(", "); } return this; }
/** * Returns the MD5 in base64 for the given file. */ public static String md5AsBase64(File file) throws FileNotFoundException, IOException { return BinaryUtils.toBase64(computeMD5Hash(file)); } }
/** * Creates a {@link AsyncRequestBody} from a {@link ByteBuffer}. Buffer contents are copied so any modifications * made to the original {@link ByteBuffer} are not reflected in the {@link AsyncRequestBody}. * * @param byteBuffer ByteBuffer to send to the service. * @return AsyncRequestBody instance. */ static AsyncRequestBody fromByteBuffer(ByteBuffer byteBuffer) { return new ByteArrayAsyncRequestBody(BinaryUtils.copyAllBytesFrom(byteBuffer)); }
/** * Converts byte data to a Base64-encoded string. * @param data * * data to Base64 encode. * @return encoded Base64 string. */ public static String toBase64(byte[] data) { return data == null ? null : new String(toBase64Bytes(data), StandardCharsets.UTF_8); }
GoawayException(long errorCode, ByteBuf debugData) { this.errorCode = errorCode; this.debugData = BinaryUtils.copyBytesFrom(debugData.nioBuffer()); }
priorChunkSignature + "\n" + AbstractAws4Signer.EMPTY_STRING_SHA256_HEX + "\n" + BinaryUtils.toHex(sha256.digest(chunkData)); String chunkSignature = BinaryUtils.toHex(aws4Signer.signWithMac(chunkStringToSign, hmacSha256)); priorChunkSignature = chunkSignature; chunkHeader.append(CHUNK_SIGNATURE_HEADER)
/** * Adds the specified value as Base64 encoded text to the current position of the in * progress XML document. * * @param b * The binary data to add to the XML document. * * @return This XMLWriter so that additional method calls can be chained * together. */ public XmlWriter value(ByteBuffer b) { append(escapeXmlEntities(BinaryUtils.toBase64(BinaryUtils.copyBytesFrom(b)))); return this; }
/** * Returns the MD5 in base64 for the data from the given input stream. * Note this method closes the given input stream upon completion. */ public static String md5AsBase64(InputStream is) throws IOException { return BinaryUtils.toBase64(computeMD5Hash(is)); }
/** * Unmarshalls a string header, taking into account whether it's a Base 64 encoded JSON value. * * @param value Value to unmarshall * @param field {@link SdkField} containing metadata about member being unmarshalled. * @return Unmarshalled value. */ private static String unmarshallStringHeader(String value, SdkField<String> field) { return field.containsTrait(JsonValueTrait.class) ? new String(BinaryUtils.fromBase64(value), StandardCharsets.UTF_8) : value; }
/** * Creates a {@link RequestBody} from a {@link ByteBuffer}. Buffer contents are copied so any modifications * made to the original {@link ByteBuffer} are not reflected in the {@link RequestBody}. * * @param byteBuffer ByteBuffer to send to the service. * @return RequestBody instance. */ public static RequestBody fromByteBuffer(ByteBuffer byteBuffer) { return fromBytesDirect(BinaryUtils.copyAllBytesFrom(byteBuffer)); }
public static ByteBuffer copy(ByteBuffer bb) { if (bb == null) { return null; } return ByteBuffer.wrap(BinaryUtils.copyBytesFrom(bb)).asReadOnlyBuffer(); } }
/** * Returns the hex-encoded MD5 hash String of the given message body. */ private static String calculateMessageBodyMd5(String messageBody) { log.debug(() -> "Message body: " + messageBody); byte[] expectedMd5; try { expectedMd5 = Md5Utils.computeMD5Hash(messageBody.getBytes(StandardCharsets.UTF_8)); } catch (Exception e) { throw SdkClientException.builder() .message("Unable to calculate the MD5 hash of the message body. " + e.getMessage()) .cause(e) .build(); } String expectedMd5Hex = BinaryUtils.toHex(expectedMd5); log.debug(() -> "Expected MD5 of message body: " + expectedMd5Hex); return expectedMd5Hex; }