/** * Wraps a ByteBuffer in an InputStream. If the input {@code byteBuffer} * is null, returns an empty stream. * * @param byteBuffer The ByteBuffer to wrap. * * @return An InputStream wrapping the ByteBuffer content. */ public static ByteArrayInputStream toStream(ByteBuffer byteBuffer) { if (byteBuffer == null) { return new ByteArrayInputStream(new byte[0]); } return new ByteArrayInputStream(copyBytesFrom(byteBuffer)); }
@Override public void visit(RecordsEvent event) { ByteBuffer records = event.getPayload(); if (records != null) { result.add(new ByteArrayInputStream(BinaryUtils.copyBytesFrom(records))); } } });
/** * Base64 encodes the data in the specified byte buffer (from the current * position to the buffer's limit) and returns it as a base64 encoded * string. * * @param byteBuffer * The data to base64 encode and return as a string; must not be * null. * * @return The base64 encoded contents of the specified byte buffer. */ public static String fromByteBuffer(ByteBuffer byteBuffer) { return Base64.encodeAsString(copyBytesFrom(byteBuffer)); }
/** * Sets the value of the specified attribute in the current item to the * given value. */ public Item withBinary(String attrName, ByteBuffer val) { checkInvalidAttribute(attrName, val); // convert ByteBuffer to bytes to keep Jackson happy attributes.put(attrName, copyBytesFrom(val)); return this; }
/** * Sets the value of the specified attribute in the current item to the * given value. */ public Item withByteBufferSet(String attrName, Set<ByteBuffer> val) { checkInvalidAttribute(attrName, val); // convert ByteBuffer to bytes to keep Jackson happy Set<byte[]> set = new LinkedHashSet<byte[]>(val.size()); for (ByteBuffer bb: val) set.add(copyBytesFrom(bb)); attributes.put(attrName, set); return this; }
/** * Sets the value of the specified attribute in the current item to the * given value. */ public Item withBinarySet(String attrName, ByteBuffer ... vals) { checkInvalidAttribute(attrName, vals); // convert ByteBuffer to bytes to keep Jackson happy Set<byte[]> set = new LinkedHashSet<byte[]>(vals.length); for (ByteBuffer bb: vals) set.add(copyBytesFrom(bb)); if (set.size() != vals.length) throw new IllegalArgumentException(DUPLICATE_VALUES_FOUND_IN_INPUT); attributes.put(attrName, set); return this; }
/** * We've received all the error content so send it off to the error response handler to produce the service exception. */ private AmazonServiceException unmarshallError() throws Exception { errorResponse.setContent(new ByteArrayInputStream(BinaryUtils.copyBytesFrom(cumulation.nioBuffer()))); return errorResponseHandler.handle(errorResponse); }
@Override public StructuredJsonGenerator writeValue(ByteBuffer bytes) { try { generator.writeBinary(BinaryUtils.copyBytesFrom(bytes)); } catch (IOException e) { throw new JsonGenerationException(e); } return this; }
return value; } else if (value instanceof ByteBuffer) { return copyBytesFrom((ByteBuffer)value); } else if (value instanceof Set) { @SuppressWarnings("unchecked") Set<byte[]> out = new LinkedHashSet<byte[]>(bs.size()); for (ByteBuffer bb: bs) out.add(copyBytesFrom(bb)); return out; } else {
/** * 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(Base64.encodeAsString(BinaryUtils.copyBytesFrom(b)))); return this; }
/** * Wraps a ByteBuffer in an InputStream. If the input {@code byteBuffer} * is null, returns an empty stream. * * @param byteBuffer The ByteBuffer to wrap. * * @return An InputStream wrapping the ByteBuffer content. */ public static ByteArrayInputStream toStream(ByteBuffer byteBuffer) { if (byteBuffer == null) { return new ByteArrayInputStream(new byte[0]); } return new ByteArrayInputStream(copyBytesFrom(byteBuffer)); }
/** * Base64 encodes the data in the specified byte buffer (from the current * position to the buffer's limit) and returns it as a base64 encoded * string. * * @param byteBuffer * The data to base64 encode and return as a string; must not be * null. * * @return The base64 encoded contents of the specified byte buffer. */ public static String fromByteBuffer(ByteBuffer byteBuffer) { return Base64.encodeAsString(copyBytesFrom(byteBuffer)); }
@Override public StructuredJsonGenerator writeValue(ByteBuffer bytes) { try { generator.writeBinary(BinaryUtils.copyBytesFrom(bytes)); } catch (IOException e) { throw new JsonGenerationException(e); } return this; }
/** * 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(Base64.encodeAsString(BinaryUtils.copyBytesFrom(b)))); return this; }
/** * Wraps a ByteBuffer in an InputStream. If the input {@code byteBuffer} * is null, returns an empty stream. * * @param byteBuffer The ByteBuffer to wrap. * * @return An InputStream wrapping the ByteBuffer content. */ public static ByteArrayInputStream toStream(ByteBuffer byteBuffer) { if (byteBuffer == null) { return new ByteArrayInputStream(new byte[0]); } return new ByteArrayInputStream(copyBytesFrom(byteBuffer)); }
/** * Sets the value of the specified attribute in the current item to the * given value. */ public Item withBinary(String attrName, ByteBuffer val) { checkInvalidAttribute(attrName, val); // convert ByteBuffer to bytes to keep Jackson happy attributes.put(attrName, copyBytesFrom(val)); return this; }
/** * Sets the value of the specified attribute in the current item to the * given value. */ public Item withByteBufferSet(String attrName, Set<ByteBuffer> val) { checkInvalidAttribute(attrName, val); // convert ByteBuffer to bytes to keep Jackson happy Set<byte[]> set = new LinkedHashSet<byte[]>(val.size()); for (ByteBuffer bb: val) set.add(copyBytesFrom(bb)); attributes.put(attrName, set); return this; }
/** * Sets the value of the specified attribute in the current item to the * given value. */ public Item withBinarySet(String attrName, ByteBuffer ... vals) { checkInvalidAttribute(attrName, vals); // convert ByteBuffer to bytes to keep Jackson happy Set<byte[]> set = new LinkedHashSet<byte[]>(vals.length); for (ByteBuffer bb: vals) set.add(copyBytesFrom(bb)); if (set.size() != vals.length) throw new IllegalArgumentException(DUPLICATE_VALUES_FOUND_IN_INPUT); attributes.put(attrName, set); return this; }
/** * We've received all the error content so send it off to the error response handler to produce the service exception. */ private AmazonServiceException unmarshallError() throws Exception { errorResponse.setContent(new ByteArrayInputStream(BinaryUtils.copyBytesFrom(cumulation.nioBuffer()))); return errorResponseHandler.handle(errorResponse); }
@Override public StructuredJsonGenerator writeValue(ByteBuffer bytes) { try { generator.writeBinary(BinaryUtils.copyBytesFrom(bytes)); } catch (IOException e) { throw new JsonGenerationException(e); } return this; }