File tree Expand file tree Collapse file tree 3 files changed +40
-0
lines changed
main/java/oracle/nosql/driver/values
test/java/oracle/nosql/driver Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
2020- Cloud only: Added new SignatureProvider constructors to allow use of an instance
2121principal with a delegation token for authorization and authentication:
2222 - SignatureProvider.createInstancePrincipalForDelegation()
23+ - BinaryValue constructor to create BinaryValue from a Base64-encoded string
2324
2425### Fixed
2526- Ensure that TableLimits is always null in TableResult on-premise.
Original file line number Diff line number Diff line change @@ -38,6 +38,20 @@ public BinaryValue(byte[] value) {
3838 this .value = value ;
3939 }
4040
41+ /**
42+ * Creates a new instance from a Base64 encoded string.
43+ *
44+ * @param value the value to use
45+ *
46+ * @throws IllegalArgumentException if the value is not a valid Base64
47+ * encoded value.
48+ */
49+ public BinaryValue (String value ) {
50+ super ();
51+ requireNonNull (value , "BinaryValue: value must be non-null" );
52+ this .value = decodeBase64 (value );
53+ }
54+
4155 @ Override
4256 public Type getType () {
4357 return Type .BINARY ;
@@ -116,6 +130,9 @@ public static String encodeBase64(byte[] buffer) {
116130 * @param binString the encoded input string
117131 *
118132 * @return the decoded array
133+ *
134+ * @throws IllegalArgumentException if the value is not a valid Base64
135+ * encoded value.
119136 */
120137 public static byte [] decodeBase64 (String binString ) {
121138 requireNonNull (binString ,
Original file line number Diff line number Diff line change @@ -932,6 +932,28 @@ public void testFieldCreator() throws Exception {
932932 }
933933 }
934934
935+ /*
936+ * Test BinaryValue constructor that takes a Base64-encoded string
937+ */
938+ @ Test
939+ public void testBinary () throws Exception {
940+ final String testString = "abcdefg" ;
941+ final byte [] byteValue = testString .getBytes ();
942+ final String encodedString = BinaryValue .encodeBase64 (byteValue );
943+
944+ BinaryValue value1 = new BinaryValue (byteValue );
945+ BinaryValue value2 = new BinaryValue (encodedString );
946+
947+ assertEquals (value1 , value2 );
948+
949+ try {
950+ value1 = new BinaryValue (testString );
951+ fail ("Cast to BinaryValue should have failed" );
952+ } catch (IllegalArgumentException e ) {
953+ // success
954+ }
955+ }
956+
935957 private void assertSize (FieldValue val , int size ) {
936958 /* Leave for future debugging:
937959 * System.out.println("assertSize: " + val + ", " +
You can’t perform that action at this time.
0 commit comments