/** * Returns this byte string in Base64 format. * * @return Base64 string */ public String toBase64String() { return Base64.encodeBytes(bytes); }
/** * Returns this byte string in Base64 format. * * @return Base64 string */ public String toBase64String() { return Base64.encodeBytes(bytes); }
/** * Returns this byte string in Base64 format. * * @return Base64 string */ public String toBase64String() { return Base64.encodeBytes(bytes); }
return encodeBytes( source, 0, source.length, options );
return encodeBytes( source, 0, source.length, options );
return encodeBytes( source, 0, source.length, options );
/** * Encodes a byte array into Base64 notation. * Does not GZip-compress data. * * @param source The data to convert * @return The data in Base64-encoded form * @throws NullPointerException if source array is null * @since 1.4 */ public static String encodeBytes( byte[] source ) { // Since we're not going to have the GZIP encoding turned on, // we're not going to have an java.io.IOException thrown, so // we should not force the user to have to catch it. String encoded = null; try { encoded = encodeBytes(source, 0, source.length, NO_OPTIONS); } catch (java.io.IOException ex) { assert false : ex.getMessage(); } // end catch assert encoded != null; return encoded; } // end encodeBytes
/** * Encodes a byte array into Base64 notation. * Does not GZip-compress data. * * @param source The data to convert * @return The data in Base64-encoded form * @throws NullPointerException if source array is null * @since 1.4 */ public static String encodeBytes( byte[] source ) { // Since we're not going to have the GZIP encoding turned on, // we're not going to have an java.io.IOException thrown, so // we should not force the user to have to catch it. String encoded = null; try { encoded = encodeBytes(source, 0, source.length, NO_OPTIONS); } catch (java.io.IOException ex) { assert false : ex.getMessage(); } // end catch assert encoded != null; return encoded; } // end encodeBytes
/** * Encodes a byte array into Base64 notation. * Does not GZip-compress data. * * @param source The data to convert * @return The data in Base64-encoded form * @throws NullPointerException if source array is null * @since 1.4 */ public static String encodeBytes( byte[] source ) { // Since we're not going to have the GZIP encoding turned on, // we're not going to have an java.io.IOException thrown, so // we should not force the user to have to catch it. String encoded = null; try { encoded = encodeBytes(source, 0, source.length, NO_OPTIONS); } catch (java.io.IOException ex) { assert false : ex.getMessage(); } // end catch assert encoded != null; return encoded; } // end encodeBytes
encoded = encodeBytes( source, off, len, NO_OPTIONS ); } catch (java.io.IOException ex) { assert false : ex.getMessage();
encoded = encodeBytes( source, off, len, NO_OPTIONS ); } catch (java.io.IOException ex) { assert false : ex.getMessage();
encoded = encodeBytes( source, off, len, NO_OPTIONS ); } catch (java.io.IOException ex) { assert false : ex.getMessage();
} else { builder.setStringValue(Base64.encodeBytes((byte[]) o));
} else { builder.setStringValue(Base64.encodeBytes((byte[]) o));
@Test public void testProtobufBytesNotSentAsBase64() { final byte[] bytes = "asdf".getBytes(UTF_8); final byte[] b64Bytes = Base64.encodeBytes(bytes).getBytes(UTF_8); TypedValue tv = TypedValue.ofLocal(Rep.BYTE_STRING, new ByteString(bytes)); // JSON encodes it as base64 assertEquals(new String(b64Bytes, UTF_8), tv.value); // Get the protobuf variant Common.TypedValue protoTv = tv.toProto(); Common.Rep protoRep = protoTv.getType(); assertEquals(Common.Rep.BYTE_STRING, protoRep); // The pb variant should have the native bytes of the original value com.google.protobuf.ByteString protoByteString = protoTv.getBytesValue(); assertNotNull(protoByteString); assertArrayEquals(bytes, protoByteString.toByteArray()); // We should have the b64 string as a backwards compatibility feature assertEquals(new String(b64Bytes, UTF_8), protoTv.getStringValue()); }
@Test public void testProtobufBytesNotSentAsBase64() { final byte[] bytes = "asdf".getBytes(UTF_8); final byte[] b64Bytes = Base64.encodeBytes(bytes).getBytes(UTF_8); TypedValue tv = TypedValue.ofLocal(Rep.BYTE_STRING, new ByteString(bytes)); // JSON encodes it as base64 assertEquals(new String(b64Bytes, UTF_8), tv.value); // Get the protobuf variant Common.TypedValue protoTv = tv.toProto(); Common.Rep protoRep = protoTv.getType(); assertEquals(Common.Rep.BYTE_STRING, protoRep); // The pb variant should have the native bytes of the original value com.google.protobuf.ByteString protoByteString = protoTv.getBytesValue(); assertNotNull(protoByteString); assertArrayEquals(bytes, protoByteString.toByteArray()); // We should have the b64 string as a backwards compatibility feature assertEquals(new String(b64Bytes, UTF_8), protoTv.getStringValue()); }
@Test public void testLegacyBase64StringEncodingForBytes() { // CALCITE-1103 CALCITE-1209 We observed that binary data was being // serialized as base-64 encoded strings instead of the native binary // data type in protobufs. We need to still handle older clients sending // data in this form. final byte[] bytes = "asdf".getBytes(UTF_8); final String base64Str = Base64.encodeBytes(bytes); Common.TypedValue.Builder builder = Common.TypedValue.newBuilder(); builder.setStringValue(base64Str); builder.setType(Common.Rep.BYTE_STRING); Common.TypedValue protoTv = builder.build(); TypedValue tv = TypedValue.fromProto(protoTv); assertEquals(Rep.BYTE_STRING, tv.type); assertEquals(base64Str, tv.value); }
@Test public void testLegacyBase64StringEncodingForBytes() { // CALCITE-1103 CALCITE-1209 We observed that binary data was being // serialized as base-64 encoded strings instead of the native binary // data type in protobufs. We need to still handle older clients sending // data in this form. final byte[] bytes = "asdf".getBytes(UTF_8); final String base64Str = Base64.encodeBytes(bytes); Common.TypedValue.Builder builder = Common.TypedValue.newBuilder(); builder.setStringValue(base64Str); builder.setType(Common.Rep.BYTE_STRING); Common.TypedValue protoTv = builder.build(); TypedValue tv = TypedValue.fromProto(protoTv); assertEquals(Rep.BYTE_STRING, tv.type); assertEquals(base64Str, tv.value); }