Java Code Examples for software.amazon.awssdk.services.dynamodb.model.AttributeValue#Builder
The following examples show how to use
software.amazon.awssdk.services.dynamodb.model.AttributeValue#Builder .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AttributeValueCoder.java From beam with Apache License 2.0 | 4 votes |
@Override public AttributeValue decode(InputStream inStream) throws IOException { AttributeValue.Builder attrBuilder = AttributeValue.builder(); String type = StringUtf8Coder.of().decode(inStream); AttributeValueType attrType = AttributeValueType.valueOf(type); switch (attrType) { case s: attrBuilder.s(StringUtf8Coder.of().decode(inStream)); break; case n: attrBuilder.n(StringUtf8Coder.of().decode(inStream)); break; case bool: attrBuilder.bool(BooleanCoder.of().decode(inStream)); break; case b: attrBuilder.b(SdkBytes.fromByteArray(ByteArrayCoder.of().decode(inStream))); break; case ss: attrBuilder.ss(LIST_STRING_CODER.decode(inStream)); break; case ns: attrBuilder.ns(LIST_STRING_CODER.decode(inStream)); break; case bs: attrBuilder.bs((convertToListByteBuffer(LIST_BYTE_CODER.decode(inStream)))); break; case l: attrBuilder.l(LIST_ATTRIBUTE_CODER.decode(inStream)); break; case m: attrBuilder.m(MAP_ATTRIBUTE_CODER.decode(inStream)); break; case nul: attrBuilder.nul(BooleanCoder.of().decode(inStream)); break; default: throw new CoderException("Unknown Type"); } return attrBuilder.build(); }
Example 2
Source File: AttributeValueMarshaller.java From aws-dynamodb-encryption-java with Apache License 2.0 | 4 votes |
private static AttributeValue unmarshall(final DataInputStream in) throws IOException { char type = in.readChar(); AttributeValue.Builder result = AttributeValue.builder(); switch (type) { case '\0': result.nul(Boolean.TRUE); break; case 'b': result.b(SdkBytes.fromByteBuffer(readBytes(in))); break; case 'B': result.bs(readBytesList(in).stream().map(SdkBytes::fromByteBuffer).collect(Collectors.toList())); break; case 'n': result.n(readString(in)); break; case 'N': result.ns(readStringList(in)); break; case 's': result.s(readString(in)); break; case 'S': result.ss(readStringList(in)); break; case '?': final byte boolValue = in.readByte(); if (boolValue == TRUE_FLAG) { result.bool(Boolean.TRUE); } else if (boolValue == FALSE_FLAG) { result.bool(Boolean.FALSE); } else { throw new IllegalArgumentException("Improperly formatted data"); } break; case 'L': final int lCount = in.readInt(); final List<AttributeValue> l = new ArrayList<>(lCount); for (int lIdx = 0; lIdx < lCount; lIdx++) { l.add(unmarshall(in)); } result.l(l); break; case 'M': final int mCount = in.readInt(); final Map<String, AttributeValue> m = new HashMap<>(); for (int mIdx = 0; mIdx < mCount; mIdx++) { final AttributeValue key = unmarshall(in); if (key.s() == null) { throw new IllegalArgumentException("Improperly formatted data"); } AttributeValue value = unmarshall(in); m.put(key.s(), value); } result.m(m); break; default: throw new IllegalArgumentException("Unsupported data encoding"); } return result.build(); }