当前位置: 首页>>代码示例>>Java>>正文


Java StringUtils类代码示例

本文整理汇总了Java中org.apache.commons.codec.binary.StringUtils的典型用法代码示例。如果您正苦于以下问题:Java StringUtils类的具体用法?Java StringUtils怎么用?Java StringUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


StringUtils类属于org.apache.commons.codec.binary包,在下文中一共展示了StringUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getSubjectIdentification

import org.apache.commons.codec.binary.StringUtils; //导入依赖的package包/类
public static String getSubjectIdentification( Row row ) {
    String name = row.getAs( "Defendant Name" );
    String gender = row.getAs( "Gender" );
    String race = row.getAs( "Race" );
    String dob = row.getAs( "DOB" );

    StringBuilder sb = new StringBuilder();
    sb
            .append( encoder.encodeToString( StringUtils.getBytesUtf8( name ) ) )
            .append( "|" )
            .append( encoder.encodeToString( StringUtils.getBytesUtf8( gender ) ) )
            .append( "|" )
            .append( encoder.encodeToString( StringUtils.getBytesUtf8( race ) ) )
            .append( "|" )
            .append( encoder.encodeToString( StringUtils.getBytesUtf8( dob ) ) );
    return sb.toString();
}
 
开发者ID:dataloom,项目名称:integrations,代码行数:18,代码来源:ClerkOfCourtsDemo2010.java

示例2: authenticateUsernamePasswordInternal

import org.apache.commons.codec.binary.StringUtils; //导入依赖的package包/类
@Override
protected HandlerResult authenticateUsernamePasswordInternal(final UsernamePasswordCredential credential,
                                                             final String originalPassword)
        throws GeneralSecurityException, PreventedException {
    if (this.users == null || this.users.isEmpty()) {
        throw new FailedLoginException("No user can be accepted because none is defined");
    }
    final String username = credential.getUsername();
    final String cachedPassword = this.users.get(username);

    if (cachedPassword == null) {
        LOGGER.debug("[{}] was not found in the map.", username);
        throw new AccountNotFoundException(username + " not found in backing map.");
    }

    if (!StringUtils.equals(credential.getPassword(), cachedPassword)) {
        throw new FailedLoginException();
    }
    final List<MessageDescriptor> list = new ArrayList<>();
    return createHandlerResult(credential, this.principalFactory.createPrincipal(username), list);
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:22,代码来源:AcceptUsersAuthenticationHandler.java

示例3: initializeAwsAuthorizationData

import org.apache.commons.codec.binary.StringUtils; //导入依赖的package包/类
private void initializeAwsAuthorizationData(String region) throws SdkClientException {
  final Regions awsRegion = Regions.fromName(region);
  AmazonECR ecr = AmazonECRClientBuilder.standard().withRegion(awsRegion).build();

  GetAuthorizationTokenResult authTokenResult = ecr.getAuthorizationToken(
      new GetAuthorizationTokenRequest()
  );
  AuthorizationData authData = authTokenResult.getAuthorizationData().get(0);

  String[] userAuthData = StringUtils.newStringUtf8(Base64.decodeBase64(
      authData.getAuthorizationToken())
  ).split(":");
  registryUsername = userAuthData[0];
  registryPassword = userAuthData[1];
  registryUrl = authData.getProxyEndpoint();
}
 
开发者ID:tsiq,项目名称:magic-beanstalk,代码行数:17,代码来源:AwsEcrAuthData.java

示例4: JWTDecoder

import org.apache.commons.codec.binary.StringUtils; //导入依赖的package包/类
public JWTDecoder(String jwt, EncodeType encodeType) throws Exception {
    parts = TokenUtils.splitToken(jwt);
    final JWTParser converter = new JWTParser();
    String headerJson = null;
    String payloadJson = null;
    switch (encodeType) {
        case Base16:
            headerJson = URLDecoder.decode(new String(Hex.decodeHex(parts[0])), "UTF-8");
            payloadJson = URLDecoder.decode(new String(Hex.decodeHex(parts[1])), "UTF-8");
            break;
        case Base32:
            Base32 base32 = new Base32();
            headerJson = URLDecoder.decode(new String(base32.decode(parts[0]), "UTF-8"));
            payloadJson = URLDecoder.decode(new String(base32.decode(parts[1]), "UTF-8"));
            break;
        case Base64:
            headerJson = StringUtils.newStringUtf8(Base64.decodeBase64(parts[0]));
            payloadJson = StringUtils.newStringUtf8(Base64.decodeBase64(parts[1]));
            break;
    }
    header = converter.parseHeader(headerJson);
    payload = converter.parsePayload(payloadJson);
}
 
开发者ID:GJWT,项目名称:javaOIDCMsg,代码行数:24,代码来源:JWTDecoder.java

示例5: client

import org.apache.commons.codec.binary.StringUtils; //导入依赖的package包/类
@Profile("kubernetes")
@Bean
/*
 * Load the CloudantClient from the Kubernetes Secrets file.
 * This method is only loaded when the kubernetes profile is activated
 */
public CloudantClient client() throws IOException {

	String secrets = readKubeSecretsFiles();
	String secretsJson = StringUtils.newStringUtf8(Base64.decodeBase64(secrets));
	ObjectMapper mapper = new ObjectMapper();
	Map<String, Object> map = new HashMap<String, Object>();

	// convert JSON string to Map
	map = mapper.readValue(secretsJson, new TypeReference<Map<String, String>>(){});

	String username = (String) map.get("username");
	String password = (String) map.get("password");
	String url = "http://" + map.get("username") + ".cloudant.com";

	return ClientBuilder.url(new URL(url))
			.username(username)
			.password(password)
			.build();
}
 
开发者ID:IBM,项目名称:spring-boot-continuous-delivery,代码行数:26,代码来源:Application.java

示例6: encodeText

import org.apache.commons.codec.binary.StringUtils; //导入依赖的package包/类
/**
 * Applies an RFC 1522 compliant encoding scheme to the given string of text with the given charset.
 * <p>
 * This method constructs the "encoded-word" header common to all the RFC 1522 codecs and then invokes
 * {@link #doEncoding(byte [])} method of a concrete class to perform the specific encoding.
 *
 * @param text
 *            a string to encode
 * @param charset
 *            a charset to be used
 * @return RFC 1522 compliant "encoded-word"
 * @throws EncoderException
 *             thrown if there is an error condition during the Encoding process.
 * @see <a href="http://download.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
 */
protected String encodeText(final String text, final Charset charset) throws EncoderException {
    if (text == null) {
        return null;
    }
    final StringBuilder buffer = new StringBuilder();
    buffer.append(PREFIX);
    buffer.append(charset);
    buffer.append(SEP);
    buffer.append(this.getEncoding());
    buffer.append(SEP);
    final byte [] rawData = this.doEncoding(text.getBytes(charset));
    buffer.append(StringUtils.newStringUsAscii(rawData));
    buffer.append(POSTFIX);
    return buffer.toString();
}
 
开发者ID:HTBridge,项目名称:pivaa,代码行数:31,代码来源:RFC1522Codec.java

示例7: desEncode

import org.apache.commons.codec.binary.StringUtils; //导入依赖的package包/类
/**
 * DES算法,加密
 *
 * @param data 待加密字符串
 * @param key  加密私钥,长度不能够小于8位
 * @return 加密后字符串
 * @throws Exception
 */
public static String desEncode(String key, String data) {
    if (data == null)
        return null;
    try {
        DESKeySpec dks = new DESKeySpec(StringUtils.getBytesUtf8(key));
        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
        //key的长度不能够小于8位字节
        Key secretKey = keyFactory.generateSecret(dks);
        Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
        IvParameterSpec iv = new IvParameterSpec(StringUtils.getBytesUtf8("12345678"));
        AlgorithmParameterSpec paramSpec = iv;
        cipher.init(Cipher.ENCRYPT_MODE, secretKey, paramSpec);
        byte[] bytes = cipher.doFinal(StringUtils.getBytesUtf8(data));
        return Hex.encodeHexString(bytes);
    } catch (Exception e) {
        throw new RuntimeException("des加密失败", e);
    }
}
 
开发者ID:yangshuai0711,项目名称:dingding-app-server,代码行数:27,代码来源:EncryptUtils.java

示例8: desDecode

import org.apache.commons.codec.binary.StringUtils; //导入依赖的package包/类
/**
 * DES算法,解密
 *
 * @param data 待解密字符串
 * @param key  解密私钥,长度不能够小于8位
 * @return 解密后的字符串
 * @throws Exception 异常
 */
public static String desDecode(String key, String data) {
    if (data == null)
        return null;
    try {
        DESKeySpec dks = new DESKeySpec(StringUtils.getBytesUtf8(key));
        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
        //key的长度不能够小于8位字节
        Key secretKey = keyFactory.generateSecret(dks);
        Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
        IvParameterSpec iv = new IvParameterSpec(StringUtils.getBytesUtf8("12345678"));
        AlgorithmParameterSpec paramSpec = iv;
        cipher.init(Cipher.DECRYPT_MODE, secretKey, paramSpec);
        byte[] bytes = Hex.decodeHex(data.toCharArray());
        return StringUtils.newStringUtf8(cipher.doFinal(bytes));
    } catch (Exception e) {
        throw new RuntimeException("des解密失败", e);
    }
}
 
开发者ID:yangshuai0711,项目名称:dingding-app-server,代码行数:27,代码来源:EncryptUtils.java

示例9: zoneTestTest

import org.apache.commons.codec.binary.StringUtils; //导入依赖的package包/类
@Test
public void zoneTestTest() throws Exception {
       final String ZONETestDateInBRST = "2014-12-31T23:59:59-02:00"; // arbitrary zone, BRST=Brazil, better if not local.
	final String ZONETestDateInZulu = "2015-01-01T01:59:59Z";
	final String ZONETestDateInET   = "2014-12-31T20:59:59-05:00";
	TemporalInstant instant = new TemporalInstantRfc3339(DateTime.parse(ZONETestDateInBRST));
	
	Assert.assertEquals("Test our test Zulu, ET  strings.", ZONETestDateInET,   DateTime.parse(ZONETestDateInZulu).withZone(DateTimeZone.forID("-05:00")).toString(ISODateTimeFormat.dateTimeNoMillis()));
       Assert.assertEquals("Test our test BRST,Zulu strings.", ZONETestDateInZulu, DateTime.parse(ZONETestDateInBRST).withZone(DateTimeZone.UTC).toString(ISODateTimeFormat.dateTimeNoMillis()));
       
	Assert.assertTrue("Key must be normalized to time zone Zulu: "+instant.getAsKeyString(),  instant.getAsKeyString().endsWith("Z"));
	Assert.assertEquals("Key must be normalized from BRST -02:00", ZONETestDateInZulu, instant.getAsKeyString());
	Assert.assertArrayEquals(StringUtils.getBytesUtf8(instant.getAsKeyString()),  instant.getAsKeyBytes());

	Assert.assertTrue(   "Ignore original time zone.", ! ZONETestDateInBRST.equals( instant.getAsReadable(DateTimeZone.forID("-07:00"))));
	Assert.assertEquals( "Use original time zone.",      ZONETestDateInBRST, instant.getAsDateTime().toString(TemporalInstantRfc3339.FORMATTER));
       Assert.assertEquals( "Time at specified time zone.", ZONETestDateInET,   instant.getAsReadable(DateTimeZone.forID("-05:00")));
	
       instant = new TemporalInstantRfc3339(DateTime.parse(ZONETestDateInZulu));
	Assert.assertEquals("expect a time with specified time zone.",  ZONETestDateInET, instant.getAsReadable(DateTimeZone.forID("-05:00")));
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:22,代码来源:TemporalInstantTest.java

示例10: serialize

import org.apache.commons.codec.binary.StringUtils; //导入依赖的package包/类
/**
 * Returns the Base64 encoded serialized string representing the variable.
 * 
 * @param variable the variable to serialize
 * @return the Base64 encoded serialized string representing the variable
 * @throws java.io.IOException if the variable count not be serialized
 */
private String serialize(Variable variable) throws IOException {
	ObjectOutputStream oos = null;
	
	try {
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		oos = new ObjectOutputStream(baos);
		oos.writeObject(variable);
		
		//encode without calling Base64#encodeBase64String as versions 
		//prior to 1.5 chunked the output
		byte[] encoding = Base64.encodeBase64(baos.toByteArray(), false);
		return StringUtils.newStringUtf8(encoding);
	} finally {
		if (oos != null) {
			oos.close();
		}
	}
}
 
开发者ID:Matsemann,项目名称:eamaster,代码行数:26,代码来源:ResultFileWriter.java

示例11: encodeText

import org.apache.commons.codec.binary.StringUtils; //导入依赖的package包/类
protected String encodeText(String text, String charset)
/*  15:    */     throws EncoderException, UnsupportedEncodingException
/*  16:    */   {
/*  17: 84 */     if (text == null) {
/*  18: 85 */       return null;
/*  19:    */     }
/*  20: 87 */     StringBuffer buffer = new StringBuffer();
/*  21: 88 */     buffer.append("=?");
/*  22: 89 */     buffer.append(charset);
/*  23: 90 */     buffer.append('?');
/*  24: 91 */     buffer.append(getEncoding());
/*  25: 92 */     buffer.append('?');
/*  26: 93 */     byte[] rawdata = doEncoding(text.getBytes(charset));
/*  27: 94 */     buffer.append(StringUtils.newStringUsAscii(rawdata));
/*  28: 95 */     buffer.append("?=");
/*  29: 96 */     return buffer.toString();
/*  30:    */   }
 
开发者ID:xiwc,项目名称:confluence.keygen,代码行数:18,代码来源:RFC1522Codec.java

示例12: encode

import org.apache.commons.codec.binary.StringUtils; //导入依赖的package包/类
@Override
public String encode() {
    StringBuilder sb = new StringBuilder();
    sb.append(keyMethod);
    sb.append(':');
    sb.append(StringUtils.newStringUtf8(Base64.encodeBase64(key, false)));
    if (lifetime > 0) {
        sb.append('|');
        sb.append(lifetime);
    }
    if (mkiLength > 0) {
        sb.append('|');
        sb.append(mki);
        sb.append(':');
        sb.append(mkiLength);
    }
    return sb.toString();
}
 
开发者ID:ibauersachs,项目名称:sdes4j,代码行数:19,代码来源:SrtpKeyParam.java

示例13: httpGet

import org.apache.commons.codec.binary.StringUtils; //导入依赖的package包/类
/**
 * Issues a HTTP Get request to the provided url and returns the response
 * @param requestUrl the request url
 * @return the response
 * @throws IOException if there are problems with the http get request.
 */
byte[] httpGet(String requestUrl)
    throws IOException {
  GetMethod getMethod = new GetMethod(requestUrl);
  try {
    int responseCode = this.httpClient.executeMethod(getMethod);
    LOGGER.debug("Received response code: {} for the get request on the url: {}", responseCode, requestUrl);
    byte[] response = getMethod.getResponseBody();
    if (responseCode != HttpStatus.SC_OK) {
      throw new SamzaException(
          String.format("Received response code: %s for get request on: %s, with message: %s.", responseCode,
              requestUrl, StringUtils.newStringUtf8(response)));
    }
    return response;
  } finally {
    getMethod.releaseConnection();
  }
}
 
开发者ID:apache,项目名称:samza,代码行数:24,代码来源:YarnRestJobStatusProvider.java

示例14: httpGet

import org.apache.commons.codec.binary.StringUtils; //导入依赖的package包/类
/**
 * This method initiates http get request on the request url and returns the
 * response returned from the http get.
 * @param requestUrl url on which the http get request has to be performed.
 * @return the http get response.
 * @throws IOException if there are problems with the http get request.
 */
private byte[] httpGet(String requestUrl) throws IOException {
  GetMethod getMethod = new GetMethod(requestUrl);
  try {
    int responseCode = httpClient.executeMethod(getMethod);
    LOG.debug("Received response code: {} for the get request on the url: {}", responseCode, requestUrl);
    byte[] response = getMethod.getResponseBody();
    if (responseCode != HttpStatus.SC_OK) {
      throw new SamzaException(String.format("Received response code: %s for get request on: %s, with message: %s.",
                                             responseCode, requestUrl, StringUtils.newStringUtf8(response)));
    }
    return response;
  } finally {
    getMethod.releaseConnection();
  }
}
 
开发者ID:apache,项目名称:samza,代码行数:23,代码来源:JobsClient.java

示例15: deflate

import org.apache.commons.codec.binary.StringUtils; //导入依赖的package包/类
public static byte[] deflate(final String data) throws SCSException {
    final byte[] toDeflate = StringUtils.getBytesUtf8(data);
    final Deflater deflater = new Deflater();
    final byte[] tmp = new byte[4096];

    deflater.setInput(toDeflate);
    deflater.finish();
    final int outSize = deflater.deflate(tmp);
    if(!deflater.finished()) {
        throw new SCSException("Can not deflate session data. Data is too large.");
    }
    deflater.end();

    final byte[] out = new byte[outSize];
    System.arraycopy(tmp, 0, out, 0, outSize);
    return out;
}
 
开发者ID:brainysmith,项目名称:scs-lib,代码行数:18,代码来源:DeflateUtils.java


注:本文中的org.apache.commons.codec.binary.StringUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。