public void setProfileImage(byte[] image) { this.map.put(field_profile_image, Base64.encodeBytes(image)); }
if (fileType.fileType == FileType.PNG) { post.setResponse(response, fileType.base64 ? "application/octet-stream" : "image/png"); sos.write(fileType.base64 ? Base64.encodeBytes(matrix.pngEncode(1)).getBytes() : matrix.pngEncode(1)); ImageIO.write(matrix.getImage(), "gif", baos); baos.close(); sos.write(Base64.encodeBytes(baos.toByteArray()).getBytes()); } else { ImageIO.write(matrix.getImage(), "gif", sos); ImageIO.write(matrix.getImage(), "jpg", baos); baos.close(); sos.write(Base64.encodeBytes(baos.toByteArray()).getBytes()); } else { ImageIO.write(matrix.getImage(), "jpg", sos);
String encodedContent = Base64.encodeBytes(buffer.toByteArray());
@Override public String toString() { return Base64.encodeBytes(id); }
/** * Encodes a string with base64. * * @param strToEncode * string to encode * @return encoded string * @throws UnsupportedEncodingException */ public static String btoa(final String strToEncode) throws UnsupportedEncodingException { return Base64.encodeBytes(strToEncode.getBytes("UTF-8")); }
/** * Encodes a byte array into Base64 notation. * <p> * Example options:<pre> * GZIP: gzip-compresses object before encoding it. * DO_BREAK_LINES: 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.DO_BREAK_LINES )</code> * <p>As of v 2.3, if there is an error with the GZIP stream, * 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 options Specified options * @return The Base64-encoded data as a String * @throws java.io.IOException if there is an error * @throws NullPointerException if source array is null * @see Base64#GZIP * @see Base64#DO_BREAK_LINES * @since 2.0 */ public static String encodeBytes(byte[] source, int options) throws java.io.IOException { return encodeBytes(source, 0, source.length, options); } // end encodeBytes
private void addAuthHeader(URLConnection connection) { if (username == null || password == null) { return; } String auth = String.format("%s:%s", username, password); String encoded = Base64.encodeBytes(auth.getBytes()); connection.setRequestProperty("Authorization", "Basic " + encoded); }
/** * 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
static String buildScrollId(String type, AtomicArray<? extends SearchPhaseResult> searchPhaseResults, @Nullable Map<String, String> attributes) throws IOException { StringBuilder sb = new StringBuilder().append(type).append(';'); sb.append(searchPhaseResults.asList().size()).append(';'); for (AtomicArray.Entry<? extends SearchPhaseResult> entry : searchPhaseResults.asList()) { SearchPhaseResult searchPhaseResult = entry.value; sb.append(searchPhaseResult.id()).append(':').append(searchPhaseResult.shardTarget().nodeId()).append(';'); } if (attributes == null) { sb.append("0;"); } else { sb.append(attributes.size()).append(";"); for (Map.Entry<String, String> entry : attributes.entrySet()) { sb.append(entry.getKey()).append(':').append(entry.getValue()).append(';'); } } BytesRef bytesRef = new BytesRef(sb); return Base64.encodeBytes(bytesRef.bytes, bytesRef.offset, bytesRef.length, Base64.URL_SAFE); }
throw new IOException("Basic auth is only supported for HTTPS!"); String basicAuth = Base64.encodeBytes(aSource.getUserInfo().getBytes(StandardCharsets.UTF_8)); connection.setRequestProperty("Authorization", "Basic " + basicAuth);
public CommitStats(SegmentInfos segmentInfos) { // clone the map to protect against concurrent changes userData = MapBuilder.<String, String>newMapBuilder().putAll(segmentInfos.getUserData()).immutableMap(); // lucene calls the current generation, last generation. generation = segmentInfos.getLastGeneration(); if (segmentInfos.getId() != null) { // id is only written starting with Lucene 5.0 id = Base64.encodeBytes(segmentInfos.getId()); } numDocs = Lucene.getNumDocs(segmentInfos); }