本文整理汇总了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);
}
}
开发者ID:baidu,项目名称:Elasticsearch,代码行数:18,代码来源:Id.java
示例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);
}
开发者ID:baidu,项目名称:Elasticsearch,代码行数:11,代码来源:CommitStats.java
示例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;
}
开发者ID:baidu,项目名称:Elasticsearch,代码行数:72,代码来源:HttpDownloadHelper.java
示例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);
}
}
开发者ID:sirensolutions,项目名称:siren-join,代码行数:10,代码来源:WrapperQueryVisitor.java
示例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;
}
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:15,代码来源:ElasticsearchDataMap.java
示例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);
}
开发者ID:uberVU,项目名称:elasticsearch-river-github,代码行数:9,代码来源:GitHubRiver.java
示例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;
}
}
开发者ID:mitallast,项目名称:elasticsearch-webdav-plugin,代码行数:9,代码来源:UrlWebdavClient.java
示例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);
}
开发者ID:baidu,项目名称:Elasticsearch,代码行数:6,代码来源:DistributedTranslog.java
示例10: toString
import org.elasticsearch.common.Base64; //导入依赖的package包/类
@Override
public String toString() {
return Base64.encodeBytes(id);
}
开发者ID:baidu,项目名称:Elasticsearch,代码行数:5,代码来源:Engine.java
示例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"));
}
开发者ID:logsniffer,项目名称:logsniffer,代码行数:12,代码来源:JstlFunctionsLibrary.java
注:本文中的org.elasticsearch.common.Base64类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论