Java Code Examples for java.io.UnsupportedEncodingException#getCause()

The following examples show how to use java.io.UnsupportedEncodingException#getCause() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpPost.java    From hop with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
String getRequestBodyParamsAsStr( NameValuePair[] pairs, String charset ) throws HopException {
  StringBuffer buf = new StringBuffer();
  try {
    for ( int i = 0; i < pairs.length; ++i ) {
      NameValuePair pair = pairs[ i ];
      if ( pair.getName() != null ) {
        if ( i > 0 ) {
          buf.append( "&" );
        }

        buf.append( URLEncoder.encode( pair.getName(), !StringUtil.isEmpty( charset ) ? charset : DEFAULT_ENCODING ) );
        buf.append( "=" );
        if ( pair.getValue() != null ) {
          buf.append( URLEncoder.encode( pair.getValue(), !StringUtil.isEmpty( charset ) ? charset : DEFAULT_ENCODING ) );
        }
      }
    }
    return buf.toString();
  } catch ( UnsupportedEncodingException e ) {
    throw new HopException( e.getMessage(), e.getCause() );
  }
}
 
Example 2
Source File: HTTPPOST.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
String getRequestBodyParamsAsStr( NameValuePair[] pairs, String charset ) throws KettleException {
  StringBuffer buf = new StringBuffer();
  try {
    for ( int i = 0; i < pairs.length; ++i ) {
      NameValuePair pair = pairs[ i ];
      if ( pair.getName() != null ) {
        if ( i > 0 ) {
          buf.append( "&" );
        }

        buf.append( URLEncoder.encode( pair.getName(), !StringUtil.isEmpty( charset ) ? charset : DEFAULT_ENCODING ) );
        buf.append( "=" );
        if ( pair.getValue() != null ) {
          buf.append( URLEncoder.encode( pair.getValue(), !StringUtil.isEmpty( charset ) ? charset : DEFAULT_ENCODING ) );
        }
      }
    }
    return buf.toString();
  } catch ( UnsupportedEncodingException e ) {
    throw new KettleException( e.getMessage(), e.getCause() );
  }
}
 
Example 3
Source File: AuthCookie.java    From auth0-java-mvc-common with MIT License 5 votes vote down vote up
private static String encode(String valueToEncode) {
    try {
        return URLEncoder.encode(valueToEncode, StandardCharsets.UTF_8.name());
    } catch (UnsupportedEncodingException e) {
        throw new AssertionError("UTF-8 character set not supported", e.getCause());
    }
}
 
Example 4
Source File: TransientCookieStore.java    From auth0-java-mvc-common with MIT License 5 votes vote down vote up
private static String decode(String valueToDecode) {
    try {
        return URLDecoder.decode(valueToDecode, StandardCharsets.UTF_8.name());
    } catch (UnsupportedEncodingException e) {
        throw new AssertionError("UTF-8 character set not supported", e.getCause());
    }
}
 
Example 5
Source File: CalculateHelper.java    From aliyun-tablestore-java-sdk with Apache License 2.0 5 votes vote down vote up
/**
 * 计算字符串的大小(按照UTF-8编码)
 * @param str
 * @return 返回字符串的字节数
 * @throws IllegalStateException
 */
public static int calcStringSizeInBytes(String str) throws IllegalStateException {
    try {
        return str.getBytes("UTF-8").length;
    } catch (UnsupportedEncodingException e) {
        throw new IllegalStateException(e.getMessage(), e.getCause());
    }
}
 
Example 6
Source File: StringUtil.java    From haxademic with MIT License 5 votes vote down vote up
public static String urlEncode(String value) {
    try {
        return URLEncoder.encode(value, StandardCharsets.UTF_8.toString());
    } catch (UnsupportedEncodingException ex) {
        throw new RuntimeException(ex.getCause());
    }
}