/** * Encodes a byte array into Base64 notation. * Does not GZip-compress data. * * @param source The data to convert * @return the encode bytes * @since 1.4 */ public static String encodeBytes(byte[] source) { return encodeBytes(source, 0, source.length, NO_OPTIONS); } // end encodeBytes
/** * Converts byte array into a base64Binary value. */ public static String marshalBase64(byte[] value) { return Base64.encodeBytes(value); }
/** * Encodes a byte array into Base64 notation. * Does not GZip-compress data. * * @param source The data to convert * @param off Offset in array where conversion should begin * @param len Length of data to convert * @return the text node * @since 1.4 */ public static String encodeBytes(byte[] source, int off, int len) { return encodeBytes(source, off, len, NO_OPTIONS); } // end encodeBytes
/** * Encodes a byte array into Base64 notation. * <p> * Valid options:<pre> * GZIP: gzip-compresses object before encoding it. * DONT_BREAK_LINES: don't break lines at 76 characters * <i>Note: Technically, this makes your encoding non-compliant.</i> * </pre> * <p> * Example: <code>encodeBytes( myData, Base64.GZIP )</code> or * <p> * Example: <code>encodeBytes( myData, Base64.GZIP | Base64.DONT_BREAK_LINES )</code> * * * @param source The data to convert * @param options Specified options * @return the encoded bytes * @see Base64#GZIP * @see Base64#DONT_BREAK_LINES * @since 2.0 */ public static String encodeBytes(byte[] source, int options) { return encodeBytes(source, 0, source.length, options); } // end encodeBytes
private static String getBasicAuthHeader(String username, String password) throws IOException { return "Basic " + new String(Base64.encodeBytes((username + ":" + password).getBytes("ISO-8859-1"), Base64.DONT_BREAK_LINES)); }
@Override public String call() throws IOException { final HttpURLConnection conn = (HttpURLConnection) url.openConnection(); if (username != null) { final String userpassword = username + ":" + password; final String basicAuthorization = Base64.encodeBytes(userpassword.getBytes()); conn.setRequestProperty("Authorization", "Basic " + basicAuthorization); } conn.setDoInput(true); return processResponse(conn); } };
private static String handleToString(ActivityHandle ah) { String base64 = null; try { byte[] bytes = null; // need to marshall the handle, but this happens at most once per AS instance int bufferSize = 1024; final ByteArrayOutputStream baos = new ByteArrayOutputStream(bufferSize); //final JBossObjectOutputStream jboos = new JBossObjectOutputStream(baos); final ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(ah); bytes = baos.toByteArray(); base64 = Base64.encodeBytes(bytes); oos.close(); } catch (Exception e) { e.printStackTrace(); } return base64; }
buffer.append(password); String encoded = Base64.encodeBytes(buffer.toString().getBytes());
buffer.append(password); String encoded = Base64.encodeBytes(buffer.toString().getBytes(), Base64.DONT_BREAK_LINES);
/** * Returns an InputStream which can be used to obtain the content of AttachmentPart as Base64 encoded character data, * this method would base64 encode the raw bytes of the attachment and return. * * @return an InputStream from which the Base64 encoded AttachmentPart can be read. * @throws SOAPException if there is no content set into this AttachmentPart object or if there was a data transformation error. * @since SAAJ 1.3 */ @Override public InputStream getBase64Content() throws SOAPException { ByteArrayOutputStream bout = new ByteArrayOutputStream(); try { // TODO: we might skip the buffer and encode lazily IOUtils.copyStream(bout, getDataHandler().getInputStream()); String base64 = Base64.encodeBytes(bout.toByteArray()); return new ByteArrayInputStream(base64.getBytes()); } catch (IOException e) { throw new SOAPException(e); } }
oos.close(); byte[] bytes = baos.toByteArray(); String encoded = Base64.encodeBytes(bytes); String path = "/stub/" + encoded;