/** * Decode base64 encoded data. * * @param chars the base64 encoded data to be decoded * @param out stream where the decoded data should be written to * @throws java.io.IOException if an i/o error occurs */ public static void decode(char[] chars, OutputStream out) throws IOException { decode(chars, 0, chars.length, out); }
/** * Outputs base64 representation of the specified stream data to an * <code>OutputStream</code>. * * @param in stream data to be encoded * @param out stream where the encoded data should be written to * @throws java.io.IOException if an i/o error occurs */ public static void encode(InputStream in, OutputStream out) throws IOException { Writer writer = new OutputStreamWriter(out, CHARSET); encode(in, writer); }
/** * Base64-decodes or -encodes (see {@link #decodeOrEncode(String)} * all the given arguments and prints the results on separate lines * in standard output. * * @since Apache Jackrabbit 2.3 * @param args command line arguments to be decoded or encoded */ public static void main(String[] args) { for (String arg : args) { System.out.println(decodeOrEncode(arg)); } }
/** * Base64-decodes or -encodes the given string, depending on whether * or not it contains a "{base64}" prefix. If the string gets encoded, * the "{base64}" prefix is added to it. * * @since Apache Jackrabbit 2.3 * @param data string to be decoded or encoded * @return decoded or encoded string */ public static String decodeOrEncode(String data) { if (data.startsWith("{base64}")) { return decode(data.substring("{base64}".length())); } else { return "{base64}" + encode(data); } }
/** * Retrieve a {@code DataSource} for the specified properties. * This can be a JNDI Data Source as well. To do that, * the driver class name must reference a {@code javax.naming.Context} class * (for example {@code javax.naming.InitialContext}), and the URL must be the JNDI URL * (for example {@code java:comp/env/jdbc/Test}). * * @param driver the JDBC driver or the Context class * @param url the database URL * @param user the user name * @param password the password * @return the {@code DataSource} * @throws RepositoryException if the driver could not be loaded * @throws SQLException if the connection could not be established */ public DataSource getDataSource(String driver, String url, String user, String password) throws RepositoryException, SQLException { final String key = driver + url + user; synchronized(lock) { sanityCheck(); DataSource ds = keyToDataSource.get(key); if (ds == null) { ds = createDataSource( driver, url, user, Base64.decodeIfEncoded(password)); keyToDataSource.put(key, ds); } return ds; } }
/** * Base64-decodes or -encodes the given string, depending on whether * or not it contains a "{base64}" prefix. If the string gets encoded, * the "{base64}" prefix is added to it. * * @since Apache Jackrabbit 2.3 * @param data string to be decoded or encoded * @return decoded or encoded string */ public static String decodeOrEncode(String data) { if (data.startsWith("{base64}")) { return decode(data.substring("{base64}".length())); } else { return "{base64}" + encode(data); } }
/** * Retrieve a {@code DataSource} for the specified properties. * This can be a JNDI Data Source as well. To do that, * the driver class name must reference a {@code javax.naming.Context} class * (for example {@code javax.naming.InitialContext}), and the URL must be the JNDI URL * (for example {@code java:comp/env/jdbc/Test}). * * @param driver the JDBC driver or the Context class * @param url the database URL * @param user the user name * @param password the password * @return the {@code DataSource} * @throws RepositoryException if the driver could not be loaded * @throws SQLException if the connection could not be established */ public DataSource getDataSource(String driver, String url, String user, String password) throws RepositoryException, SQLException { final String key = driver + url + user; synchronized(lock) { sanityCheck(); DataSource ds = keyToDataSource.get(key); if (ds == null) { ds = createDataSource( driver, url, user, Base64.decodeIfEncoded(password)); keyToDataSource.put(key, ds); } return ds; } }
/** * Decode base64 encoded data. * * @param chars the base64 encoded data to be decoded * @param out stream where the decoded data should be written to * @throws java.io.IOException if an i/o error occurs */ public static void decode(char[] chars, OutputStream out) throws IOException { decode(chars, 0, chars.length, out); }
/** * From a byte[] returns a base 64 representation * @param data byte[] * @return String * @throws IOException * @throws IOException */ public static String byteToBase64(byte[] data) throws IOException { StringWriter writer = new StringWriter(); Base64.encode(data, 0, data.length, writer); return writer.toString(); }
/** * Base64-decodes or -encodes the given string, depending on whether * or not it contains a "{base64}" prefix. If the string gets encoded, * the "{base64}" prefix is added to it. * * @since Apache Jackrabbit 2.3 * @param data string to be decoded or encoded * @return decoded or encoded string */ public static String decodeOrEncode(String data) { if (data.startsWith("{base64}")) { return decode(data.substring("{base64}".length())); } else { return "{base64}" + encode(data); } }
/** * Base64-decodes or -encodes (see {@link #decodeOrEncode(String)} * all the given arguments and prints the results on separate lines * in standard output. * * @since Apache Jackrabbit 2.3 * @param args command line arguments to be decoded or encoded */ public static void main(String[] args) { for (String arg : args) { System.out.println(decodeOrEncode(arg)); } }
/** * Retrieve a {@code DataSource} for the specified properties. * This can be a JNDI Data Source as well. To do that, * the driver class name must reference a {@code javax.naming.Context} class * (for example {@code javax.naming.InitialContext}), and the URL must be the JNDI URL * (for example {@code java:comp/env/jdbc/Test}). * * @param driver the JDBC driver or the Context class * @param url the database URL * @param user the user name * @param password the password * @return the {@code DataSource} * @throws RepositoryException if the driver could not be loaded * @throws SQLException if the connection could not be established */ public DataSource getDataSource(String driver, String url, String user, String password) throws RepositoryException, SQLException { final String key = driver + url + user; synchronized(lock) { sanityCheck(); DataSource ds = keyToDataSource.get(key); if (ds == null) { ds = createDataSource( driver, url, user, Base64.decodeIfEncoded(password)); keyToDataSource.put(key, ds); } return ds; } }
/** * Decode base64 encoded data. * * @param chars the base64 encoded data to be decoded * @param out stream where the decoded data should be written to * @throws java.io.IOException if an i/o error occurs */ public static void decode(char[] chars, OutputStream out) throws IOException { decode(chars, 0, chars.length, out); }
/** * Outputs base64 representation of the specified stream data to a * <code>Writer</code>. * * @param in stream data to be encoded * @param writer writer to output the encoded data * @throws java.io.IOException if an i/o error occurs */ public static void encode(InputStream in, Writer writer) throws IOException { // encode stream data in chunks; // chunksize must be a multiple of 3 in order // to avoid padding within output byte[] buffer = new byte[9 * 1024]; int read; while ((read = in.read(buffer)) > 0) { encode(buffer, 0, read, writer); } }
/** * Base64-decodes or -encodes (see {@link #decodeOrEncode(String)} * all the given arguments and prints the results on separate lines * in standard output. * * @since Apache Jackrabbit 2.3 * @param args command line arguments to be decoded or encoded */ public static void main(String[] args) { for (String arg : args) { System.out.println(decodeOrEncode(arg)); } }
/** * Decode base64 encoded data. * * @param chars the base64 encoded data to be decoded * @param out stream where the decoded data should be written to * @throws java.io.IOException if an i/o error occurs */ public static void decode(char[] chars, OutputStream out) throws IOException { decode(chars, 0, chars.length, out); }
/** * Outputs base64 representation of the specified stream data to a * <code>Writer</code>. * * @param in stream data to be encoded * @param writer writer to output the encoded data * @throws java.io.IOException if an i/o error occurs */ public static void encode(InputStream in, Writer writer) throws IOException { // encode stream data in chunks; // chunksize must be a multiple of 3 in order // to avoid padding within output byte[] buffer = new byte[9 * 1024]; int read; while ((read = in.read(buffer)) > 0) { encode(buffer, 0, read, writer); } }
/** * Decode base64 encoded data. * * @param data the base64 encoded data to be decoded * @param out stream where the decoded data should be written to * @throws java.io.IOException if an i/o error occurs */ public static void decode(String data, OutputStream out) throws IOException { char[] chars = data.toCharArray(); decode(chars, 0, chars.length, out); }
/** * Outputs base64 representation of the specified stream data to a * <code>Writer</code>. * * @param in stream data to be encoded * @param writer writer to output the encoded data * @throws java.io.IOException if an i/o error occurs */ public static void encode(InputStream in, Writer writer) throws IOException { // encode stream data in chunks; // chunksize must be a multiple of 3 in order // to avoid padding within output byte[] buffer = new byte[9 * 1024]; int read; while ((read = in.read(buffer)) > 0) { encode(buffer, 0, read, writer); } }
/** * Decode base64 encoded data. The data read from the inputstream is * assumed to be of charset "US-ASCII". * * @param in inputstream of the base64 encoded data to be decoded * @param out stream where the decoded data should be written to * @throws java.io.IOException if an i/o error occurs */ public static void decode(InputStream in, OutputStream out) throws IOException { decode(new InputStreamReader(in, CHARSET), out); }