本文整理汇总了Java中org.elasticsearch.common.Base64类的典型用法代码示例。如果您正苦于以下问题:Java Base64类的具体用法?Java Base64怎么用?Java Base64使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Base64类属于org.elasticsearch.common包,在下文中一共展示了Base64类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encode
import org.elasticsearch.common.Base64; //导入依赖的package包/类
private static String encode(List<BytesRef> values, int clusteredByPosition) {
try (BytesStreamOutput out = new BytesStreamOutput(estimateSize(values))) {
int size = values.size();
out.writeVInt(size);
if (clusteredByPosition >= 0) {
out.writeBytesRef(ensureNonNull(values.get(clusteredByPosition)));
}
for (int i = 0; i < size; i++) {
if (i != clusteredByPosition) {
out.writeBytesRef(ensureNonNull(values.get(i)));
}
}
return Base64.encodeBytes(out.bytes().toBytes());
} catch (IOException e) {
throw Throwables.propagate(e);
}
}
示例2: getDocumentId
import org.elasticsearch.common.Base64; //导入依赖的package包/类
@Override
public String getDocumentId(BytesReference contentBytes) {
if (generateId) {
// if we need to generate an _id for the event, get an MD5 hash for
// the serialized
// event bytes.
String hashId = null;
try {
byte[] bytes = contentBytes.toBytes();
if (contentBytes.length() > 0 && null != bytes) {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] thedigest = md.digest(bytes);
hashId = Base64.encodeBytes(thedigest, Base64.URL_SAFE);
// remove padding
if (hashId.endsWith("=="))
hashId = hashId.substring(0, hashId.length()-2);
}
} catch (NoSuchAlgorithmException | IOException e) {
Integer hash = contentBytes.hashCode();
hashId = hash.toString();
}
if (null != hashId && !hashId.isEmpty())
return hashId;
}
return null;
}
开发者ID:gigya,项目名称:flume-ng-elasticsearch-ser-ex,代码行数:27,代码来源:ExtendedElasticSearchLogStashEventSerializer.java
示例3: CommitStats
import org.elasticsearch.common.Base64; //导入依赖的package包/类
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);
}
示例4: openConnection
import org.elasticsearch.common.Base64; //导入依赖的package包/类
private URLConnection openConnection(URL aSource) throws IOException {
// set up the URL connection
URLConnection connection = aSource.openConnection();
// modify the headers
// NB: things like user authentication could go in here too.
if (hasTimestamp) {
connection.setIfModifiedSince(timestamp);
}
// in case the plugin manager is its own project, this can become an authenticator
boolean isSecureProcotol = "https".equalsIgnoreCase(aSource.getProtocol());
boolean isAuthInfoSet = !Strings.isNullOrEmpty(aSource.getUserInfo());
if (isAuthInfoSet) {
if (!isSecureProcotol) {
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);
}
if (connection instanceof HttpURLConnection) {
((HttpURLConnection) connection).setInstanceFollowRedirects(false);
connection.setUseCaches(true);
connection.setConnectTimeout(5000);
}
connection.setRequestProperty("ES-Version", Version.CURRENT.toString());
connection.setRequestProperty("ES-Build-Hash", Build.CURRENT.hashShort());
connection.setRequestProperty("User-Agent", "elasticsearch-plugin-manager");
// connect to the remote site (may take some time)
connection.connect();
// First check on a 301 / 302 (moved) response (HTTP only)
if (connection instanceof HttpURLConnection) {
HttpURLConnection httpConnection = (HttpURLConnection) connection;
int responseCode = httpConnection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_MOVED_PERM ||
responseCode == HttpURLConnection.HTTP_MOVED_TEMP ||
responseCode == HttpURLConnection.HTTP_SEE_OTHER) {
String newLocation = httpConnection.getHeaderField("Location");
URL newURL = new URL(newLocation);
if (!redirectionAllowed(aSource, newURL)) {
return null;
}
return openConnection(newURL);
}
// next test for a 304 result (HTTP only)
long lastModified = httpConnection.getLastModified();
if (responseCode == HttpURLConnection.HTTP_NOT_MODIFIED
|| (lastModified != 0 && hasTimestamp && timestamp >= lastModified)) {
// not modified so no file download. just return
// instead and trace out something so the user
// doesn't think that the download happened when it
// didn't
return null;
}
// test for 401 result (HTTP only)
if (responseCode == HttpURLConnection.HTTP_UNAUTHORIZED) {
String message = "HTTP Authorization failure";
throw new IOException(message);
}
}
//REVISIT: at this point even non HTTP connections may
//support the if-modified-since behaviour -we just check
//the date of the content and skip the write if it is not
//newer. Some protocols (FTP) don't include dates, of
//course.
return connection;
}
示例5: parseQuery
import org.elasticsearch.common.Base64; //导入依赖的package包/类
protected Map<String, Object> parseQuery(String source) {
try {
byte[] bytes = Base64.decode(source);
return this.parseQuery(new BytesArray(bytes, 0, bytes.length));
}
catch (IOException e) {
throw new ElasticsearchParseException("Failed to parse source [" + source + "]", e);
}
}
示例6: get
import org.elasticsearch.common.Base64; //导入依赖的package包/类
public byte[] get(Object key) {
ElasticsearchSample s = index.get(key);
if (s == null) {
return null;
}
Object data = s.get(DATA);
byte[] bytes;
try {
bytes = Base64.decode(String.valueOf(data).getBytes());
} catch (IOException e) {
throw new RuntimeException(e);
}
return bytes;
}
示例7: addAuthHeader
import org.elasticsearch.common.Base64; //导入依赖的package包/类
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);
}
示例8: UrlWebdavClient
import org.elasticsearch.common.Base64; //导入依赖的package包/类
public UrlWebdavClient(String username, String password) {
if (username != null && password != null) {
String credentials = username + ":" + password;
this.basicAuth = "Basic " + Base64.encodeBytes(credentials.getBytes());
} else {
basicAuth = null;
}
}
示例9: getLogName
import org.elasticsearch.common.Base64; //导入依赖的package包/类
private static String getLogName(String indexName, String indexUUID, int shardId) {
// index name may contains invalid characters that dl not recognized
String encodedIndexName = Base64.encodeBytes(indexName.getBytes());
return String.format("%s_%s_%d", encodedIndexName, indexUUID, shardId);
}
示例10: toString
import org.elasticsearch.common.Base64; //导入依赖的package包/类
@Override
public String toString() {
return Base64.encodeBytes(id);
}
示例11: btoa
import org.elasticsearch.common.Base64; //导入依赖的package包/类
/**
* 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"));
}