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
/** * Encodes a byte array into Base64 notation. Does not GZip-compress data. * <p> * As of v 2.3, if there is an error, the method will throw an java.io.IOException. <b>This is new to v2.3!</b> In earlier * versions, it just returned a null value, but in retrospect that's a pretty poor way to handle it. * </p> * * @param source The data to convert * @param off Offset in array where conversion should begin * @param len Length of data to convert * @return The Base64-encoded data as a String * @throws NullPointerException if source array is null * @throws IllegalArgumentException if source array, offset, or length are invalid * @since 1.4 */ public static String encodeBytes( byte[] source, int off, int len ) { // 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, off, len, 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. * <p> * As of v 2.3, if there is an error, the method will throw an java.io.IOException. <b>This is new to v2.3!</b> In earlier * versions, it just returned a null value, but in retrospect that's a pretty poor way to handle it. * </p> * * @param source The data to convert * @param off Offset in array where conversion should begin * @param len Length of data to convert * @return The Base64-encoded data as a String * @throws NullPointerException if source array is null * @throws IllegalArgumentException if source array, offset, or length are invalid * @since 1.4 */ public static String encodeBytes( byte[] source, int off, int len ) { // 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, off, len, 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. * <p> * As of v 2.3, if there is an error, the method will throw an java.io.IOException. <b>This is new to v2.3!</b> In earlier * versions, it just returned a null value, but in retrospect that's a pretty poor way to handle it. * </p> * * @param source The data to convert * @param off Offset in array where conversion should begin * @param len Length of data to convert * @return The Base64-encoded data as a String * @throws NullPointerException if source array is null * @throws IllegalArgumentException if source array, offset, or length are invalid * @since 1.4 */ public static String encodeBytes( byte[] source, int off, int len ) { // 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, off, len, NO_OPTIONS); } catch (java.io.IOException ex) { assert false : ex.getMessage(); } // end catch assert encoded != null; return encoded; } // end encodeBytes
/** * {@inheritDoc} * * @see org.modeshape.common.text.TextEncoder#encode(java.lang.String) */ @Override public String encode( String text ) { try { byte[] hash = SecureHash.getHash(algorithm, text.getBytes()); String result = Base64.encodeBytes(hash); return result.length() < maxLength ? result : result.substring(0, maxLength); } catch (NoSuchAlgorithmException e) { return text; } }
/** * {@inheritDoc} * * @see org.modeshape.common.text.TextEncoder#encode(java.lang.String) */ @Override public String encode( String text ) { try { byte[] hash = SecureHash.getHash(algorithm, text.getBytes()); String result = Base64.encodeBytes(hash); return result.length() < maxLength ? result : result.substring(0, maxLength); } catch (NoSuchAlgorithmException e) { return text; } }
/** * {@inheritDoc} * * @see org.modeshape.common.text.TextEncoder#encode(java.lang.String) */ @Override public String encode( String text ) { try { byte[] hash = SecureHash.getHash(algorithm, text.getBytes()); String result = Base64.encodeBytes(hash); return result.length() < maxLength ? result : result.substring(0, maxLength); } catch (NoSuchAlgorithmException e) { return text; } }
/** * {@inheritDoc} * * @see org.modeshape.graph.property.ValueTypeSystem.Factory#asReadableString(java.lang.Object) */ @Override public String asReadableString( Object value ) { Binary binary = this.valueFactory.create(value); // Just print out the SHA-1 hash in Base64, plus length return "(Binary,length=" + binary.getSize() + ",SHA1=" + Base64.encodeBytes(binary.getHash()) + ")"; }
@Override public String asReadableString( Object value ) { BinaryValue binary = this.valueFactory.create(value); // Just print out the SHA-1 hash in Base64, plus length return "(Binary,length=" + binary.getSize() + ",SHA1=" + Base64.encodeBytes(binary.getHash()) + ")"; }
@Override public String asReadableString( Object value ) { BinaryValue binary = this.valueFactory.create(value); // Just print out the SHA-1 hash in Base64, plus length return "(Binary,length=" + binary.getSize() + ",SHA1=" + Base64.encodeBytes(binary.getHash()) + ")"; }
@Test( expected = NullPointerException.class ) public void testEncodeNullByteArray() { Base64.encodeBytes(null); }
@Test public void testBasicExamples() throws IOException { // Make up some source objects byte[] originalBytes = {(byte)-2, (byte)-1, (byte)0, (byte)1, (byte)2}; // Display original array System.out.println("\n\nOriginal array: "); for (int i = 0; i < originalBytes.length; i++) System.out.print(originalBytes[i] + " "); System.out.println(); // Encode serialized bytes String encBytes = Base64.encodeBytes(originalBytes); // Print encoded bytes System.out.println("Bytes, encoded ( " + encBytes.getBytes().length + " bytes):\n" + encBytes); // Decode bytes byte[] decBytes = Base64.decode(encBytes); // Display decoded bytes System.out.println("Encoded Bytes -> decoded: "); for (int i = 0; i < decBytes.length; i++) System.out.print(decBytes[i] + " "); System.out.println(); }
@Test public void shouldEncodeStringValue() throws UnsupportedEncodingException, IOException { String actualValue = "propertyValue"; String encoded = Base64.encodeBytes(actualValue.getBytes("UTF-8")); byte[] decoded = Base64.decode(encoded); String decodedValue = new String(decoded, "UTF-8"); assertThat(decodedValue, is(actualValue)); }
@Test public void shouldEncodeStreamableValue() throws IOException { String actualValue = "propertyValue"; byte[] actualBytes = actualValue.getBytes(); InputStream actualStream = new ByteArrayInputStream(actualBytes); String encoded = Base64.encode(actualStream); String encoded2 = Base64.encodeBytes(actualBytes); assertThat(encoded, is(encoded2)); byte[] decoded = Base64.decode(encoded); String decodedValue = new String(decoded); assertThat(decodedValue, is(actualValue)); }
@Test public void testEncodeEmptyByteArray() { String result = Base64.encodeBytes(new byte[] {}); assertThat(result, is(notNullValue())); assertThat(result.length(), is(0)); }