org.elasticsearch.common.Base64.encodeBytes()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(6.4k)|赞(0)|评价(0)|浏览(154)

本文整理了Java中org.elasticsearch.common.Base64.encodeBytes()方法的一些代码示例,展示了Base64.encodeBytes()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Base64.encodeBytes()方法的具体详情如下:
包路径:org.elasticsearch.common.Base64
类名称:Base64
方法名:encodeBytes

Base64.encodeBytes介绍

[英]Encodes a byte array into Base64 notation. Does not GZip-compress data.
[中]将字节数组编码为Base64表示法。不压缩数据。

代码示例

代码示例来源:origin: loklak/loklak_server

public void setProfileImage(byte[] image) {
  this.map.put(field_profile_image, Base64.encodeBytes(image));
}

代码示例来源:origin: loklak/loklak_server

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);

代码示例来源:origin: richardwilly98/elasticsearch-river-mongodb

String encodedContent = Base64.encodeBytes(buffer.toByteArray());

代码示例来源:origin: harbby/presto-connectors

@Override
public String toString() {
  return Base64.encodeBytes(id);
}

代码示例来源:origin: mbok/logsniffer

/**
 * 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"));
}

代码示例来源:origin: harbby/presto-connectors

/**
 * 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

代码示例来源:origin: uberVU/elasticsearch-river-github

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);
}

代码示例来源:origin: harbby/presto-connectors

/**
 * 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

代码示例来源:origin: harbby/presto-connectors

/**
 * 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

代码示例来源:origin: harbby/presto-connectors

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);
}

代码示例来源:origin: harbby/presto-connectors

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);

代码示例来源:origin: harbby/presto-connectors

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);
}

相关文章