本文整理了Java中org.apache.commons.lang3.StringUtils.toEncodedString()
方法的一些代码示例,展示了StringUtils.toEncodedString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringUtils.toEncodedString()
方法的具体详情如下:
包路径:org.apache.commons.lang3.StringUtils
类名称:StringUtils
方法名:toEncodedString
[英]Converts a byte[]
to a String using the specified character encoding.
[中]使用指定的字符编码将byte[]
转换为字符串。
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* Tests {@link StringUtils#toEncodedString(byte[], Charset)}
*
* @see StringUtils#toEncodedString(byte[], Charset)
*/
@Test
public void testToEncodedString() {
final String expectedString = "The quick brown fox jumps over the lazy dog.";
String encoding = SystemUtils.FILE_ENCODING;
byte[] expectedBytes = expectedString.getBytes(Charset.defaultCharset());
// sanity check start
assertArrayEquals(expectedBytes, expectedString.getBytes());
// sanity check end
assertEquals(expectedString, StringUtils.toEncodedString(expectedBytes, Charset.defaultCharset()));
assertEquals(expectedString, StringUtils.toEncodedString(expectedBytes, Charset.forName(encoding)));
encoding = "UTF-16";
expectedBytes = expectedString.getBytes(Charset.forName(encoding));
assertEquals(expectedString, StringUtils.toEncodedString(expectedBytes, Charset.forName(encoding)));
}
代码示例来源:origin: uber/chaperone
private void processAuditMsg(final MessageAndMetadata mm) throws Exception {
JSONObject record = JSON.parseObject(StringUtils.toEncodedString((byte[]) mm.message(), Charset.forName("UTF-8")));
String topicName = record.getString(AuditMsgField.TOPICNAME.getName());
if (blacklistedTopics.contains(topicName)) {
logger.debug("Topic={} is blacklisted", topicName);
return;
}
if (deduplicator != null) {
String uuid = record.getString(AuditMsgField.UUID.getName());
String host = record.getString(AuditMsgField.HOSTNAME.getName());
if (deduplicator.isDuplicated(topicName, mm.partition(), mm.offset(), host, uuid)) {
return;
}
}
if (enablePersistentStore) {
auditReporter.submit(mm.topic(), mm.partition(), mm.offset(), record);
}
}
代码示例来源:origin: dswarm/dswarm
/**
* Gets the filter expression.
*
* @return the filter expression
*/
public String getExpression() {
expression = StringUtils.toEncodedString(expressionString, Charsets.UTF_8);
return expression;
}
代码示例来源:origin: org.finra.herd/herd-core
/**
* Decodes and return the base64 encoded string.
*
* @param base64EncodedText the base64 encoded string
*
* @return the decoded string
*/
public static String decodeBase64(String base64EncodedText)
{
return StringUtils.toEncodedString(Base64.getDecoder().decode(base64EncodedText.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8);
}
代码示例来源:origin: FINRAOS/herd
/**
* Decodes and return the base64 encoded string.
*
* @param base64EncodedText the base64 encoded string
*
* @return the decoded string
*/
public static String decodeBase64(String base64EncodedText)
{
return StringUtils.toEncodedString(Base64.getDecoder().decode(base64EncodedText.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8);
}
代码示例来源:origin: dswarm/dswarm
/**
* Gets the attribute path as JSON object (a list of Attributes)
*
* @return the attribute path as JSON object
*/
@JsonIgnore
public String getAttributePathAsJSONObjectString() {
initAttributePath(false);
refreshAttributePathString();
return StringUtils.toEncodedString(attributePath, Charsets.UTF_8);
}
代码示例来源:origin: dswarm/dswarm
/**
* Gets the key attribute path for a given key attribute path identifier.
*
* @param uuid a key attribute path identifier
* @return the matched key attribute path or null
*/
public AttributePath getKeyAttributePath(final String uuid) {
if (null == uuid) {
return null;
}
if (null == utilisedKeyAttributePaths) {
return null;
}
if (StringUtils.toEncodedString(keyAttributePaths, Charsets.UTF_8).isEmpty()) {
return null;
}
final List<AttributePath> keyAttributePathsFiltered = Lambda.filter(
Lambda.having(Lambda.on(AttributePath.class).getUuid(), Matchers.equalTo(uuid)), utilisedKeyAttributePaths);
if (keyAttributePathsFiltered == null || keyAttributePathsFiltered.isEmpty()) {
return null;
}
return keyAttributePathsFiltered.get(0);
}
代码示例来源:origin: zc-zh-001/ShadowSocks-Share
String ssrLinks = StringUtils.toEncodedString(Base64.decodeBase64(base64ssrLinks), StandardCharsets.UTF_8);
String[] ssrLinkList = ssrLinks.split("\n");
代码示例来源:origin: hansiming/JobHunter
/**
* Return all the fields and associated values in a hash.
*
* @param key
* @return
*/
public Map<String, Object> getObjectMap(String key) {
Map<String, Object> value = null;
Jedis jedis = null;
try {
jedis = getResource();
if (jedis.exists(getBytesKey(key))) {
value = Maps.newHashMap();
Map<byte[], byte[]> map = jedis.hgetAll(getBytesKey(key));
for (Map.Entry<byte[], byte[]> e : map.entrySet()) {
value.put(StringUtils.toEncodedString(e.getKey(), null), toObject(e.getValue()));
}
LOOGER.debug("getObjectMap {} = {}", key, value);
}
} catch (Exception e) {
LOOGER.warn("getObjectMap {} = {}", key, value, e);
} finally {
returnResource(jedis);
}
return value;
}
代码示例来源:origin: dswarm/dswarm
/**
* Initialises the function description from the string that holds the serialised JSON object of the function description.
*
* @param fromScratch flag that indicates, whether the function description should be initialised from scratch or not
*/
private void initFunctionDescription(final boolean fromScratch) {
if (functionDescription == null && !functionDescriptionInitialized) {
if (functionDescriptionString == null) {
Function.LOG.debug("function description JSON string is null");
if (fromScratch) {
functionDescription = new ObjectNode(DMPPersistenceUtil.getJSONFactory());
}
functionDescriptionInitialized = true;
return;
}
try {
functionDescription = DMPPersistenceUtil.getJSON(StringUtils.toEncodedString(functionDescriptionString, Charsets.UTF_8));
} catch (final DMPException e) {
Function.LOG.debug("couldn't parse function description JSON string for function '" + getUuid() + "'");
}
functionDescriptionInitialized = true;
}
}
代码示例来源:origin: dswarm/dswarm
parametersJSON = DMPPersistenceUtil.getJSONArray(StringUtils.toEncodedString(parametersString, Charsets.UTF_8));
代码示例来源:origin: dswarm/dswarm
parameterMappingsJSON = DMPPersistenceUtil.getJSON(StringUtils.toEncodedString(parameterMappingsString, Charsets.UTF_8));
代码示例来源:origin: dswarm/dswarm
/**
* Initialises the attributes from the string that holds the serialised JSON object of the attributes.
*
* @param fromScratch flag that indicates, whether the attributes should be initialised from scratch or not
*/
private void initAttributes(final boolean fromScratch) {
if (attributes == null && !attributesInitialized) {
if (attributesString == null) {
Resource.LOG.debug("attributes JSON string is null");
if (fromScratch) {
attributes = new ObjectNode(DMPPersistenceUtil.getJSONFactory());
}
attributesInitialized = true;
return;
}
try {
attributes = DMPPersistenceUtil.getJSON(StringUtils.toEncodedString(attributesString, Charsets.UTF_8));
} catch (final DMPException e) {
Resource.LOG.debug("couldn't parse attributes JSON string for resource '" + getUuid() + "'");
}
attributesInitialized = true;
}
}
代码示例来源:origin: dswarm/dswarm
/**
* Initialises the configuration parameters from the string that holds the serialised JSON object of the configuration
* parameters.
*
* @param fromScratch flag that indicates, whether the configuration parameters should be initialised from scratch or not
*/
private void initParameters(final boolean fromScratch) {
if (parameters == null && !parametersInitialized) {
if (parametersString == null) {
Configuration.LOG.debug("parameters JSON string is null");
if (fromScratch) {
parameters = new ObjectNode(DMPPersistenceUtil.getJSONFactory());
}
parametersInitialized = true;
return;
}
try {
parameters = DMPPersistenceUtil.getJSON(StringUtils.toEncodedString(parametersString, Charsets.UTF_8));
} catch (final DMPException e) {
Configuration.LOG.debug("couldn't parse parameters JSON string for configuration '" + getUuid() + "'");
}
parametersInitialized = true;
}
}
代码示例来源:origin: dswarm/dswarm
orderedAttributesJSON = DMPPersistenceUtil.getJSONArray(StringUtils.toEncodedString(attributePath, Charsets.UTF_8));
代码示例来源:origin: dswarm/dswarm
orderedKeyAttributePathsJSON = DMPPersistenceUtil.getJSONArray(StringUtils.toEncodedString(keyAttributePaths, Charsets.UTF_8));
代码示例来源:origin: dswarm/dswarm
private void initializedAttributePaths(final boolean fromScratch) {
if (orderedAttributePathsJson == null && !isOrderedAttributePathsInitialized) {
if (attributePathsJsonString == null) {
Schema.LOG.debug("attribute paths JSON is null for {}", getUuid());
if (fromScratch) {
orderedAttributePathsJson = new ArrayNode(DMPPersistenceUtil.getJSONFactory());
orderedAttributePaths = Maps.newLinkedHashMap();
isOrderedAttributePathsInitialized = true;
}
return;
}
try {
orderedAttributePaths = Maps.newLinkedHashMap();
orderedAttributePathsJson = DMPPersistenceUtil.getJSONArray(StringUtils.toEncodedString(attributePathsJsonString, Charsets.UTF_8));
if (orderedAttributePathsJson != null) {
for (final JsonNode attributePathIdNode : orderedAttributePathsJson) {
final SchemaAttributePathInstance attributePath = getAttributePath(attributePathIdNode.asText());
if (attributePath != null && !orderedAttributePaths.containsKey(attributePath.getAttributePath().toAttributePath())) {
orderedAttributePaths.put(attributePath.getAttributePath().toAttributePath(), attributePath);
}
}
}
} catch (final DMPException e) {
Schema.LOG.debug("couldn't parse attribute path JSON for attribute path '" + getUuid() + "'", e);
}
isOrderedAttributePathsInitialized = true;
}
}
代码示例来源:origin: FINRAOS/herd
@Test
public void testDecodeBase64()
{
// Test decode using hard coded values.
assertEquals("UT_SomeText", HerdStringUtils.decodeBase64("VVRfU29tZVRleHQ="));
// Test decode using random string and encoder.
String encodedText = StringUtils.toEncodedString(Base64.getEncoder().encode(STRING_VALUE.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8);
assertEquals(STRING_VALUE, HerdStringUtils.decodeBase64(encodedText));
}
代码示例来源:origin: cn.home1/oss-lib-errorhandle-spring-boot-1.4.1.RELEASE
final Exception result;
if (ResolvedErrorException.isResolvedError(responseHeaders)) {
final String info = toEncodedString(responseBody, UTF_8);
try {
代码示例来源:origin: cn.home1/oss-lib-errorhandle-spring-boot-1.4.2.RELEASE
final Exception result;
if (ResolvedErrorException.isResolvedError(responseHeaders)) {
final String info = toEncodedString(responseBody, UTF_8);
try {
内容来源于网络,如有侵权,请联系作者删除!