當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。