本文整理汇总了Java中io.netty.util.CharsetUtil.UTF_8属性的典型用法代码示例。如果您正苦于以下问题:Java CharsetUtil.UTF_8属性的具体用法?Java CharsetUtil.UTF_8怎么用?Java CharsetUtil.UTF_8使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类io.netty.util.CharsetUtil
的用法示例。
在下文中一共展示了CharsetUtil.UTF_8属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getParameterMap
/**
* 获取请求参数的Map
* @param request
* @return
*/
public static Map<String, List<String>> getParameterMap(HttpRequest request){
Map<String, List<String>> paramMap = new HashMap<String, List<String>>();
HttpMethod method = request.method();
if(HttpMethod.GET.equals(method)){
String uri = request.uri();
QueryStringDecoder queryDecoder = new QueryStringDecoder(uri, CharsetUtil.UTF_8);
paramMap = queryDecoder.parameters();
}else if(HttpMethod.POST.equals(method)){
FullHttpRequest fullRequest = (FullHttpRequest) request;
paramMap = getPostParamMap(fullRequest);
}
return paramMap;
}
示例2: dotStuff
private String dotStuff(String testString, int chunkSize) throws Exception {
ByteArrayInputStream stream = new ByteArrayInputStream(testString.getBytes(StandardCharsets.UTF_8));
DotStuffingChunkedStream chunkedStream = new DotStuffingChunkedStream(stream, chunkSize);
CompositeByteBuf destBuffer = ALLOCATOR.compositeBuffer();
while (!chunkedStream.isEndOfInput()) {
destBuffer.addComponent(true, chunkedStream.readChunk(ALLOCATOR));
}
byte[] bytes = new byte[destBuffer.readableBytes()];
destBuffer.getBytes(0, bytes);
ReferenceCountUtil.release(destBuffer);
return new String(bytes, CharsetUtil.UTF_8);
}
示例3: encode
public String encode(byte[] bytes) throws Exception {
// 加密验证
int zeroFlag = 0;
byte[] jsonByteFillZero = null;
int len = bytes.length;
if ((len & 0XF) != 0) {
len = ((len >> 4) + 1) << 4;
zeroFlag = len - bytes.length;
jsonByteFillZero = new byte[len];
System.arraycopy(bytes, 0, jsonByteFillZero, 0, bytes.length);
} else {
jsonByteFillZero = bytes;
}
byte[] doFinal = null;
Cipher cipher = Cipher.getInstance(TRANSFORMATION);
cipher.init(Cipher.ENCRYPT_MODE, generateKey, new IvParameterSpec(this.iv));
doFinal = cipher.doFinal(jsonByteFillZero);
byte[] content = new byte[doFinal.length + this.iv.length];
System.arraycopy(this.iv, 0, content, 0, this.iv.length);
System.arraycopy(doFinal, 0, content, this.iv.length, doFinal.length);
byte[] base64Encode = SecurityUtil.base64Encode(content);
String b64Str = new String(base64Encode, CharsetUtil.UTF_8);
String result = b64Str.replace('+', '-').replace('/', '_').replace('=', '.');
if (zeroFlag > 0) {
result = "$" + String.format("%02d", zeroFlag) + result;
}
return result;
}
示例4: decode
public String decode(String source) throws Exception {
String tokenSource = source;
int zeroFlag = 0;
if (tokenSource.startsWith("$")) {
zeroFlag = Integer.parseInt(tokenSource.substring(1, 3));
tokenSource = tokenSource.substring(3);
}
String token = tokenSource.replace('-', '+').replace('_', '/').replace('.', '=');
byte[] base64Decode = SecurityUtil.base64Decode(token.getBytes(CharsetUtil.UTF_8));
byte[] iv = new byte[0X10];
byte[] content = new byte[base64Decode.length - iv.length];
System.arraycopy(base64Decode, 0, iv, 0, iv.length);
System.arraycopy(base64Decode, iv.length, content, 0, content.length);
Cipher cipher = Cipher.getInstance(TRANSFORMATION);
cipher.init(Cipher.DECRYPT_MODE, generateKey, new IvParameterSpec(iv));
byte[] doFinal = cipher.doFinal(content);
// 去补零
int realSize = doFinal.length;
if (zeroFlag > 0) {
realSize = doFinal.length - zeroFlag;
byte[] afterZero = new byte[realSize];
System.arraycopy(doFinal, 0, afterZero, 0, afterZero.length);
return new String(afterZero, CharsetUtil.UTF_8);
} else {
return new String(doFinal, CharsetUtil.UTF_8);
}
}
示例5: getString
/**
* 读取String类型
*
* @param buffer
* @return
*/
protected final String getString() {
byte[] bytes = getByteArray();
if (bytes == null) {
return null;
} else if (bytes.length == 0) {
return "";
} else {
return new String(bytes, CharsetUtil.UTF_8);
}
}
示例6: terminate
private String terminate(String testString, int chunkSize) throws Exception {
ByteArrayInputStream stream = new ByteArrayInputStream(testString.getBytes(StandardCharsets.UTF_8));
CrlfTerminatingChunkedStream chunkedStream = new CrlfTerminatingChunkedStream(stream, chunkSize);
CompositeByteBuf destBuffer = ALLOCATOR.compositeBuffer();
while (!chunkedStream.isEndOfInput()) {
destBuffer.addComponent(true, chunkedStream.readChunk(ALLOCATOR));
}
byte[] bytes = new byte[destBuffer.readableBytes()];
destBuffer.getBytes(0, bytes);
destBuffer.release();
return new String(bytes, CharsetUtil.UTF_8);
}
示例7: dotStuffUsingByteBuf
private String dotStuffUsingByteBuf(String testString, boolean atStartOfLine, boolean appendCRLF) {
ByteBuf sourceBuffer = ALLOCATOR.buffer();
sourceBuffer.writeBytes(testString.getBytes(StandardCharsets.UTF_8));
byte[] previousBytes = atStartOfLine ? null : new byte[] { 'x', 'y' };
ByteBuf destBuffer = DotStuffing.createDotStuffedBuffer(ALLOCATOR, sourceBuffer, previousBytes,
appendCRLF ? MessageTermination.ADD_CRLF : MessageTermination.DO_NOT_TERMINATE);
byte[] bytes = new byte[destBuffer.readableBytes()];
destBuffer.getBytes(0, bytes);
return new String(bytes, CharsetUtil.UTF_8);
}
示例8: extract
private String extract(Object o) {
assertThat(o).isInstanceOf(ByteBuf.class);
ByteBuf buffer = (ByteBuf) o;
byte[] bytes = new byte[buffer.readableBytes()];
buffer.getBytes(0, bytes);
return new String(bytes, CharsetUtil.UTF_8);
}
示例9: StringCodec
public StringCodec() {
this(CharsetUtil.UTF_8);
}
示例10: base64Encode2
public static String base64Encode2(String stringsrc) throws UnsupportedEncodingException {
return new String(base64Encode(stringsrc.getBytes(CharsetUtil.UTF_8)), CharsetUtil.UTF_8);
}
示例11: NetoMessageToJsonEncoder
public NetoMessageToJsonEncoder() {
this(CharsetUtil.UTF_8);
}
示例12: contentToString
public String contentToString(){
return new String(this.content, CharsetUtil.UTF_8);
}
示例13: willMessage
/**
* @deprecated use {@link MqttConnectPayload#willMessageInBytes()} instead
*/
@Deprecated
public String willMessage() {
return willMessage == null ? null : new String(willMessage, CharsetUtil.UTF_8);
}
示例14: password
/**
* @deprecated use {@link MqttConnectPayload#passwordInBytes()} instead
*/
@Deprecated
public String password() {
return password == null ? null : new String(password, CharsetUtil.UTF_8);
}
示例15: getEncoder
/**
* Returns StringEncoder of UTF_8 .
* @return StringEncoder
*/
public static StringEncoder getEncoder() {
return new StringEncoder(CharsetUtil.UTF_8);
}