/** * Decodes data from Base64 notation, automatically detecting gzip-compressed data and decompressing it. * * @param s the string to decode * @return the decoded data * @throws java.io.IOException If there is a problem * @since 1.4 */ public static byte[] decode( String s ) throws java.io.IOException { return decode(s, NO_OPTIONS); }
/** * Decodes data from Base64 notation, automatically detecting gzip-compressed data and decompressing it. * * @param s the string to decode * @return the decoded data * @throws java.io.IOException If there is a problem * @since 1.4 */ public static byte[] decode( String s ) throws java.io.IOException { return decode(s, NO_OPTIONS); }
/** * Decodes data from Base64 notation, automatically detecting gzip-compressed data and decompressing it. * * @param s the string to decode * @return the decoded data * @throws java.io.IOException If there is a problem * @since 1.4 */ public static byte[] decode( String s ) throws java.io.IOException { return decode(s, NO_OPTIONS); }
/** * Low-level access to decoding ASCII characters in the form of a byte array. <strong>Ignores GUNZIP option, if it's * set.</strong> This is not generally a recommended method, although it is used internally as part of the decoding process. * Special case: if len = 0, an empty array is returned. Still, if you need more speed and reduced memory footprint (and * aren't gzipping), consider this method. * * @param source The Base64 encoded data * @return decoded data * @throws IOException if there is an error decoding the supplied byte array * @since 2.3.1 */ public static byte[] decode( byte[] source ) throws IOException { byte[] decoded = null; // try { decoded = decode(source, 0, source.length, Base64.NO_OPTIONS); // } catch( java.io.IOException ex ) { // assert false : "IOExceptions only come from GZipping, which is turned off: " + ex.getMessage(); // } return decoded; }
/** * Low-level access to decoding ASCII characters in the form of a byte array. <strong>Ignores GUNZIP option, if it's * set.</strong> This is not generally a recommended method, although it is used internally as part of the decoding process. * Special case: if len = 0, an empty array is returned. Still, if you need more speed and reduced memory footprint (and * aren't gzipping), consider this method. * * @param source The Base64 encoded data * @return decoded data * @throws IOException if there is an error decoding the supplied byte array * @since 2.3.1 */ public static byte[] decode( byte[] source ) throws IOException { byte[] decoded = null; // try { decoded = decode(source, 0, source.length, Base64.NO_OPTIONS); // } catch( java.io.IOException ex ) { // assert false : "IOExceptions only come from GZipping, which is turned off: " + ex.getMessage(); // } return decoded; }
protected static byte[] decodeBase64( String value ) throws IOException { try { return Base64.decode(value.getBytes("UTF-8")); } catch (IOException e) { // try re-reading, in case this was an export from a prior ModeShape version that used URL_SAFE ... return Base64.decode(value, Base64.URL_SAFE); } }
protected static byte[] decodeBase64( String value ) throws IOException { try { return Base64.decode(value.getBytes("UTF-8")); } catch (IOException e) { // try re-reading, in case this was an export from a prior ModeShape version that used URL_SAFE ... return Base64.decode(value, Base64.URL_SAFE); } }
/** * Low-level access to decoding ASCII characters in the form of a byte array. <strong>Ignores GUNZIP option, if it's * set.</strong> This is not generally a recommended method, although it is used internally as part of the decoding process. * Special case: if len = 0, an empty array is returned. Still, if you need more speed and reduced memory footprint (and * aren't gzipping), consider this method. * * @param source The Base64 encoded data * @return decoded data * @throws IOException if there is an error decoding the supplied byte array * @since 2.3.1 */ public static byte[] decode( byte[] source ) throws IOException { byte[] decoded = null; // try { decoded = decode(source, 0, source.length, Base64.NO_OPTIONS); // } catch( java.io.IOException ex ) { // assert false : "IOExceptions only come from GZipping, which is turned off: " + ex.getMessage(); // } return decoded; }
byte[] objBytes = decode(encodedObject, options);
byte[] objBytes = decode(encodedObject, options);
byte[] objBytes = decode(encodedObject, options);
bytes = decode(bytes, 0, bytes.length, options);
bytes = decode(bytes, 0, bytes.length, options);
bytes = decode(bytes, 0, bytes.length, options);
private Value createBinaryValue( String base64EncodedValue, ValueFactory valueFactory ) throws RepositoryException { InputStream stream = null; try { byte[] binaryValue = Base64.decode(base64EncodedValue); stream = new ByteArrayInputStream(binaryValue); Binary binary = valueFactory.createBinary(stream); return valueFactory.createValue(binary); } catch (IOException ioe) { throw new RepositoryException(ioe); } finally { try { if (stream != null) { stream.close(); } } catch (IOException e) { logger.debug(e, "Error while closing binary stream"); } } }
@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)); }
byte[] msBytes = org.modeshape.common.util.Base64.decode(base64Str); if (print) { System.out.println("ModeShape: " + toString(msBytes));