UTF

您所在的位置:网站首页 北京旅游手抄报英语内容 UTF

UTF

2022-05-09 05:27| 来源: 网络整理| 查看: 265

import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.net.URLDecoder; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; InputStream requestInputStream = request.getInputStream(); String requestJson = IOUtils.toString(requestInputStream, "UTF-8");

 

URLDecoder.decode(reqBean.getToken(), "UTF-8") String url = "%2fvod%2fhls%2fbWVkaWEy%4dS8y%4dDE1%4dTEw%4djIyNTAwODAwNV8xODcyay5tcDQ%3d%5f0000%2ets%3fdur%3d6%26tokenekot%3d268nEYoBbVgJqb%4dAcnV%4d"; String ss = URLDecoder.decode(url,"UTF-8"); System.out.println(ss);

 

request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8");

 

@RequestMapping(value = "/rest", produces = "application/xml;", method = RequestMethod.POST) @ResponseBody public String rest(@RequestBody String body, HttpServletRequest request, HttpServletResponse response) { }

 

// HTTP请求消息头 CONTENT_TYPE_VALUE String requestHeaderContentTypeValue = "text/html;charset=utf-8";

 

HttpClient httpClient = new HttpClient(); PostMethod method = new PostMethod(SERVER_URL); // method.set String requestJson = "{\"token\":\"630584331\",\"type\":\"2\",\"sendMode\":\"0\",\"receiveId\":\"644991187\",\"receiveClassId\":\"\",\"subjectId\":\"\",\"sendTime\":\"\",\"messageContent\":\"奥看科技和宝贝测试通知\"}"; // String requestJson = // "{\"token\":\"628366322\",\"type\":\"2\",\"sendMode\":\"0\",\"receiveId\":\"641628755\",\"receiveClassId\":\"\",\"subjectId\":\"\",\"sendTime\":\"\",\"messageContent\":\"奥看科技和宝贝测试通知\"}"; RequestEntity requestEntity = new ByteArrayRequestEntity(requestJson.getBytes("UTF-8"), "UTF-8"); method.setRequestEntity(requestEntity); method.setRequestHeader("Content-Type","application/json;charset=UTF-8"); method.setRequestHeader("Authorization", "Digest username=" + "11111" + ",[email protected],nonce=4a568c428a037e2f849526a7dc65ef25,uri=" + SERVER_URL + ",response=147b13265f33e63bf17f25f47bcc8560,cnonce=00000001,opaque=5ccc069c403ebaf9f0171e9517f40e41,qop=auth,nc=00000001"); httpClient.executeMethod(method);

 

EnCodeCharsetUtil

package com.online.schedule.service.common; import java.io.UnsupportedEncodingException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * 字符处理工具类 * * @author YiZhichao * @version [版本号, 2014-11-10] * @see [相关类/方法] * @since [产品/模块版本] */ public class EnCodeCharsetUtil { /** 定义日志对象 */ public static final Log LOG = LogFactory.getLog(EnCodeCharsetUtil.class); public static String convertCharset(String s) { if (s != null) { try { int length = s.length(); byte[] buffer = new byte[length]; // 0x81 to Unicode 0x0081, 0x8d to 0x008d, 0x8f to 0x008f, 0x90 to 0x0090, and 0x9d to 0x009d. for (int i = 0; i < length; ++i) { char c = s.charAt(i); // if (c == 0x0080) // { // buffer[i] = (byte)0x80; // } // else if (c == 0x0081) { buffer[i] = (byte)0x81; } else if (c == 0x008d) { buffer[i] = (byte)0x8d; } else if (c == 0x008f) { buffer[i] = (byte)0x8f; } else if (c == 0x0090) { buffer[i] = (byte)0x90; } else if (c == 0x009d) { buffer[i] = (byte)0x9d; } else { buffer[i] = Character.toString(c).getBytes("CP1252")[0]; } } String result = new String(buffer, "UTF-8"); return result; } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } return null; } public static String convertCharsetByte(byte[] buffer) { if (buffer != null) { try { // 0x81 to Unicode 0x0081, 0x8d to 0x008d, 0x8f to 0x008f, 0x90 to 0x0090, and 0x9d to 0x009d. for (int i = 0; i < buffer.length; ++i) { char c = (char)buffer[i]; if (c == 0x0081) { buffer[i] = (byte)0x81; } else if (c == 0x008d) { buffer[i] = (byte)0x8d; } else if (c == 0x008f) { buffer[i] = (byte)0x8f; } else if (c == 0x0090) { buffer[i] = (byte)0x90; } else if (c == 0x009d) { buffer[i] = (byte)0x9d; } else { buffer[i] = Character.toString(c).getBytes("CP1252")[0]; } } String result = new String(buffer, "UTF-8"); return result; } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } return null; } public static void main(String[] args) { // String str = "5月9日下午,市教育局局长王建华来我校现场调研、协调,陪同调研的有市教育局副局长李枫、发展计划处处长莫岳平及建设方金茂投资(长沙)有限公司执行总经理张志超、副总经理干萍、学校筹建部总经理皮军。我校校长叶双秋、党总支书记曹共平、副校长王剑湘、赵忠科热情接待了调研考察组一行。

王建华局长一到学校就考察了学校的建设工地现场。随后,王建华局长在我校项目指挥部召开了座谈会。会上,王建华局长询问了学校工程建设进度,学校投资建设方金茂投资(长沙)有限公司学校筹建部总经理皮军对此作了具体介绍。皮军表示,我校项目将于6月底基本完工,在8月15日前可以达到让学生入学的条件。张志超总经理表示,建设方一定会在保质保量的前提下推进工程建设的进度,积极协调各方,确保今年九月份如期开学。

叶双秋校长在会上感谢市教育局王建华局长一行及金茂投资(长沙)有限公司在我校筹备工作进入100天倒计时之际莅临我校考察,对我校筹备工作给予的关心和支持。我校将按市教育局要求确保学校后期教育教学设施配套工作在8月15日前如期完成,顺利开学。

最后,王建华局长感谢了建设方夜以继日地施工建设,充分肯定了我校的筹备工作,对学校后期的建设及筹备工作提出了以下要求:一是希望学校建设方安全、文明施工,建成优质工程;二是要求学校积极配合建设方,按轻重缓急合理铺排项目;三是教育局相关处室要全力支持学校筹备工作,确保学校教育教学设备设施及优秀师资队伍如期到位,今年九月正式开学。

"; // String str = "周南梅溪湖中学学生宿舍及教室直饮净水检测报告"; String str = "江彬杰"; // String str1 = "周å�—梅溪湖中学学生宿èˆ�å�Šæ•™å®¤ç›´é¥®å‡€æ°´æ£€æµ‹æŠ¥å‘Š"; // String str3 = "周å—梅溪湖中学学生宿èˆåŠæ•™å®¤ç›´é¥®å‡€æ°´æ£€æµ‹æŠ¥å‘Š"; // 周南梅溪湖中学学生宿舍及教室直饮净水检测报告 // String str3 = "长沙市教育局副局长王建林æ�¥æ ¡è§†å¯ŸæŒ‡å¯¼å·¥ä½œ"; String ch = EnCodeCharsetUtil.convertCharset(str); System.out.println(ch); // String ch = } }

输出 江彬杰

 

Encodes

/** * Copyright (c) 2005-2012 springside.org.cn */ package com.smart.plat.framework.utils; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.net.URLEncoder; import org.apache.commons.codec.DecoderException; import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Hex; import org.apache.commons.lang3.StringEscapeUtils; /** * 封装各种格式的编码解码工具类. * 1.Commons-Codec的 hex/base64 编码 * 2.自制的base62 编码 * 3.Commons-Lang的xml/html escape * 4.JDK提供的URLEncoder * @version 2013-01-15 */ public class Encodes { private static final String DEFAULT_URL_ENCODING = "UTF-8"; private static final char[] BASE62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".toCharArray(); /** * Hex编码. */ public static String encodeHex(byte[] input) { return new String(Hex.encodeHex(input)); } /** * Hex解码. */ public static byte[] decodeHex(String input) { try { return Hex.decodeHex(input.toCharArray()); } catch (DecoderException e) { throw Exceptions.unchecked(e); } } /** * Base64编码. */ public static String encodeBase64(byte[] input) { return new String(Base64.encodeBase64(input)); } /** * Base64编码. */ public static String encodeBase64(String input) { try { return new String(Base64.encodeBase64(input.getBytes(DEFAULT_URL_ENCODING))); } catch (UnsupportedEncodingException e) { return ""; } } // /** // * Base64编码, URL安全(将Base64中的URL非法字符'+'和'/'转为'-'和'_', 见RFC3548). // */ // public static String encodeUrlSafeBase64(byte[] input) { // return Base64.encodeBase64URLSafe(input); // } /** * Base64解码. */ public static byte[] decodeBase64(String input) { return Base64.decodeBase64(input.getBytes()); } /** * Base64解码. */ public static String decodeBase64String(String input) { try { return new String(Base64.decodeBase64(input.getBytes()), DEFAULT_URL_ENCODING); } catch (UnsupportedEncodingException e) { return ""; } } /** * Base62编码。 */ public static String encodeBase62(byte[] input) { char[] chars = new char[input.length]; for (int i = 0; i < input.length; i++) { chars[i] = BASE62[((input[i] & 0xFF) % BASE62.length)]; } return new String(chars); } /** * Html 转码. */ public static String escapeHtml(String html) { return StringEscapeUtils.escapeHtml4(html); } /** * Html 解码. */ public static String unescapeHtml(String htmlEscaped) { return StringEscapeUtils.unescapeHtml4(htmlEscaped); } /** * Xml 转码. */ public static String escapeXml(String xml) { return StringEscapeUtils.escapeXml10(xml); } /** * Xml 解码. */ public static String unescapeXml(String xmlEscaped) { return StringEscapeUtils.unescapeXml(xmlEscaped); } /** * URL 编码, Encode默认为UTF-8. */ public static String urlEncode(String part) { try { return URLEncoder.encode(part, DEFAULT_URL_ENCODING); } catch (UnsupportedEncodingException e) { throw Exceptions.unchecked(e); } } /** * URL 解码, Encode默认为UTF-8. */ public static String urlDecode(String part) { try { return URLDecoder.decode(part, DEFAULT_URL_ENCODING); } catch (UnsupportedEncodingException e) { throw Exceptions.unchecked(e); } } }

 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3