private 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(), charset ) ); buf.append( "=" ); if ( pair.getValue() != null ) { buf.append( URLEncoder.encode( pair.getValue(), charset ) ); } } } return buf.toString(); } catch ( UnsupportedEncodingException e ) { throw new KettleException( e.getMessage(), e.getCause() ); } }
/** * 计算字符串的大小(按照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()); } } }
@Override public byte[] decode(final String data) throws ValidateException { checkValid(() -> data != null && !data.isEmpty()); try { return data.getBytes(CHARSET); } catch (UnsupportedEncodingException e) { throw new UnexpectedException(e.getCause()); } }
public static String keywordEncoding(String keyword){ try { keyword = URLEncoder.encode(keyword, "utf-8"); } catch (UnsupportedEncodingException e) { LoggerHandler.getInstance().writeLogger("URL编码错误!" + e.getCause(), Constant.LOG_LEVEL_ERROR); } return keyword; }
@Override public String encode(byte[] data) throws ValidateException { checkValid(() -> data != null && data.length > 0); try { return new String(data, CHARSET); } catch (UnsupportedEncodingException e) { throw new UnexpectedException(e.getCause()); } } }
LOG.error("UnsupportedEncodingException occurred when deciding whether a redirection is required", exception); exceptionCaught(ctx, exception.getCause()); } catch (MalformedURLException exception) { LOG.error("MalformedURLException occurred when deciding whether a redirection is required", exception);
this.pluginMain = globals.load(new InputStreamReader(this.pluginFile.getResource(this.descriptor.getMain()), "UTF-8"), this.descriptor.getMain()); } catch (UnsupportedEncodingException e) { throw new InvalidPluginException("File could not be loaded using UTF-8.", e.getCause());