当前位置: 首页>>代码示例>>Java>>正文


Java CharEncoding类代码示例

本文整理汇总了Java中org.apache.commons.codec.CharEncoding的典型用法代码示例。如果您正苦于以下问题:Java CharEncoding类的具体用法?Java CharEncoding怎么用?Java CharEncoding使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CharEncoding类属于org.apache.commons.codec包,在下文中一共展示了CharEncoding类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseProp

import org.apache.commons.codec.CharEncoding; //导入依赖的package包/类
private Element parseProp(String value) {
    // valをDOMでElement化
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    DocumentBuilder builder = null;
    Document doc = null;
    try {
        builder = factory.newDocumentBuilder();
        ByteArrayInputStream is = new ByteArrayInputStream(value.getBytes(CharEncoding.UTF_8));
        doc = builder.parse(is);
    } catch (Exception e1) {
        throw PersoniumCoreException.Dav.DAV_INCONSISTENCY_FOUND.reason(e1);
    }
    Element e = doc.getDocumentElement();
    return e;
}
 
开发者ID:personium,项目名称:personium-core,代码行数:17,代码来源:DavCmpFsImpl.java

示例2: sendEmail

import org.apache.commons.codec.CharEncoding; //导入依赖的package包/类
@Async
public void sendEmail(final String to, final String subject, final String content, final boolean isMultipart,
		final boolean isHtml) {

	final MimeMessage mimeMessage = javaMailSender.createMimeMessage();
	try {
		final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8);
		message.setFrom(uaaProperties.getMail().getFrom());
		message.setTo(to);
		message.setSubject(subject);
		message.setText(content, isHtml);
		javaMailSender.send(mimeMessage);
		LOGGER.debug("Sent email to User '{}' with subject '{}'", to, subject);
	} catch (final MessagingException | MailException e) {
		LOGGER.warn("Mail could not be sent to user '{}'", to, e);
	}
}
 
开发者ID:JanLoebel,项目名称:uaa-service,代码行数:18,代码来源:EmailService.java

示例3: getParamMap

import org.apache.commons.codec.CharEncoding; //导入依赖的package包/类
/**
 * 获取请求参数 Map
 */
private Map<String, List<String>> getParamMap(){
	Map<String, List<String>> paramMap = new HashMap<String, List<String>>();
	
	Object msg = DataHolder.getRequest();
	HttpRequest request = (HttpRequest) msg;
	HttpMethod method = request.method();
	if(method.equals(HttpMethod.GET)){
		String uri = request.uri();
		QueryStringDecoder queryDecoder = new QueryStringDecoder(uri, Charset.forName(CharEncoding.UTF_8));
		paramMap = queryDecoder.parameters();
		
	}else if(method.equals(HttpMethod.POST)){
		FullHttpRequest fullRequest = (FullHttpRequest) msg;
		paramMap = getPostParamMap(fullRequest);
	}
	
	return paramMap;
}
 
开发者ID:cyfonly,项目名称:nettice,代码行数:22,代码来源:BaseAction.java

示例4: publish

import org.apache.commons.codec.CharEncoding; //导入依赖的package包/类
@Override
public void publish(String messageBody) {
  if (channel == null || !channel.isOpen()) {
    channel = getChannel();
  }
  if (channel != null && channel.isOpen()) {
    Message message = properties.getSection(Message.class);
    Exchange exchange = properties.getSection(Exchange.class);
    try {
      LOGGER.debug(MSG("Send message."));
      channel.basicPublish(exchange.name, message.routingKey,
          properties.getAMQProperties().getBasicProperties(),
          messageBody.getBytes(CharEncoding.UTF_8));
    } catch (Exception ex) {
      LOGGER.warn(MSG("Error when sending meessage."), ex);
    }
  }
}
 
开发者ID:rinrinne,项目名称:gerrit-rabbitmq-plugin,代码行数:19,代码来源:AMQPSession.java

示例5: commence

import org.apache.commons.codec.CharEncoding; //导入依赖的package包/类
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {

    ServiceError serviceError = ServiceError.NEED_TO_LOGIN;

    if (authException.getClass().isAssignableFrom(BadCredentialsException.class))
        serviceError = ServiceError.BAD_CREDENTIALS;

    response.setContentType(ContentType.APPLICATION_JSON.toString());
    response.setStatus(serviceError.getHttpStatus());
    response.setCharacterEncoding(CharEncoding.UTF_8);

    RestErrorResponse restErrorResponse = new RestErrorResponse(serviceError);
    String errorJson = ObjectMapperUtils.getObjectMapper().writeValueAsString(restErrorResponse);

    PrintWriter out = response.getWriter();
    out.print(errorJson);
    out.flush();
    out.close();
}
 
开发者ID:JakduK,项目名称:jakduk-api,代码行数:21,代码来源:RestAuthenticationEntryPoint.java

示例6: testUTF8RoundTrip

import org.apache.commons.codec.CharEncoding; //导入依赖的package包/类
@Test
public void testUTF8RoundTrip() throws Exception {

    final String ru_msg = constructString(RUSSIAN_STUFF_UNICODE);
    final String ch_msg = constructString(SWISS_GERMAN_STUFF_UNICODE);

    final QuotedPrintableCodec qpcodec = new QuotedPrintableCodec();

    assertEquals(
        "=D0=92=D1=81=D0=B5=D0=BC_=D0=BF=D1=80=D0=B8=D0=B2=D0=B5=D1=82",
    qpcodec.encode(ru_msg, CharEncoding.UTF_8)
    );
    assertEquals("Gr=C3=BCezi_z=C3=A4m=C3=A4", qpcodec.encode(ch_msg, CharEncoding.UTF_8));

    assertEquals(ru_msg, qpcodec.decode(qpcodec.encode(ru_msg, CharEncoding.UTF_8), CharEncoding.UTF_8));
    assertEquals(ch_msg, qpcodec.decode(qpcodec.encode(ch_msg, CharEncoding.UTF_8), CharEncoding.UTF_8));
}
 
开发者ID:ManfredTremmel,项目名称:gwt-commons-codec,代码行数:18,代码来源:QuotedPrintableCodecTest.java

示例7: testUTF8RoundTrip

import org.apache.commons.codec.CharEncoding; //导入依赖的package包/类
@Test
public void testUTF8RoundTrip() throws Exception {

    final String ru_msg = constructString(RUSSIAN_STUFF_UNICODE);
    final String ch_msg = constructString(SWISS_GERMAN_STUFF_UNICODE);

    final QCodec qcodec = new QCodec(CharEncoding.UTF_8);

    assertEquals(
        "=?UTF-8?Q?=D0=92=D1=81=D0=B5=D0=BC=5F=D0=BF=D1=80=D0=B8=D0=B2=D0=B5=D1=82?=",
    qcodec.encode(ru_msg)
    );
    assertEquals("=?UTF-8?Q?Gr=C3=BCezi=5Fz=C3=A4m=C3=A4?=", qcodec.encode(ch_msg));

    assertEquals(ru_msg, qcodec.decode(qcodec.encode(ru_msg)));
    assertEquals(ch_msg, qcodec.decode(qcodec.encode(ch_msg)));
}
 
开发者ID:ManfredTremmel,项目名称:gwt-commons-codec,代码行数:18,代码来源:QCodecTest.java

示例8: testUTF8RoundTrip

import org.apache.commons.codec.CharEncoding; //导入依赖的package包/类
@Test
public void testUTF8RoundTrip() throws Exception {

    final String ru_msg = constructString(RUSSIAN_STUFF_UNICODE);
    final String ch_msg = constructString(SWISS_GERMAN_STUFF_UNICODE);

    final URLCodec urlCodec = new URLCodec();
    this.validateState(urlCodec);

    assertEquals(
        "%D0%92%D1%81%D0%B5%D0%BC_%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82",
        urlCodec.encode(ru_msg, CharEncoding.UTF_8)
    );
    assertEquals("Gr%C3%BCezi_z%C3%A4m%C3%A4", urlCodec.encode(ch_msg, CharEncoding.UTF_8));

    assertEquals(ru_msg, urlCodec.decode(urlCodec.encode(ru_msg, CharEncoding.UTF_8), CharEncoding.UTF_8));
    assertEquals(ch_msg, urlCodec.decode(urlCodec.encode(ch_msg, CharEncoding.UTF_8), CharEncoding.UTF_8));
    this.validateState(urlCodec);
}
 
开发者ID:ManfredTremmel,项目名称:gwt-commons-codec,代码行数:20,代码来源:URLCodecTest.java

示例9: getExactTermMatch

import org.apache.commons.codec.CharEncoding; //导入依赖的package包/类
/**
 * Common logic for exact term match
 * @param namespaceIds
 * @param query
 * @param localeCodes
 * @return {@link List}({@link ConceptSearchResultDescriptor})
 * @throws DrugMatchConfigurationException
 * @throws IOException
 */
private List<ConceptSearchResultDescriptor> getExactTermMatch(final Set<String> namespaceIds,
		final Set<Long> constraintIds,
		final Set<String> localeCodes,
		final String query) throws DrugMatchConfigurationException, IOException {
	// construct path
	StringBuilder path = new StringBuilder("/webservice/restricted/v1.0/search/concept/exactSearch?query=");
	path.append(URLEncoder.encode(query, CharEncoding.UTF_8));
	// top point constraints
	for (Long constraintId : constraintIds) {
		path.append("&constraintId=")
			.append(constraintId);
	}
	// namespaces
	for (String namespaceId : namespaceIds) {
		path.append("&namespaceId=")
			.append(URLEncoder.encode(namespaceId, CharEncoding.UTF_8));
	}
	// locale codes
	for (String localeCode : localeCodes) {
		path.append("&contentLocaleCode=")
			.append(URLEncoder.encode(localeCode, CharEncoding.UTF_8));
	}
	// search
	return getConceptSearchResult(path.toString());
}
 
开发者ID:IHTSDO,项目名称:drugMatch,代码行数:35,代码来源:VerificationServiceImpl.java

示例10: getEntity

import org.apache.commons.codec.CharEncoding; //导入依赖的package包/类
@Override
public UrlEncodedFormEntity getEntity() throws BoxRestException {
    List<NameValuePair> pairs = new ArrayList<NameValuePair>();
    for (Map.Entry<String, Object> entry : getJSONEntity().entrySet()) {
        Object value = entry.getValue();
        if (value != null && value instanceof String) {
            pairs.add(new BasicNameValuePair(entry.getKey(), (String) entry.getValue()));
        }
    }

    try {
        return new UrlEncodedFormEntity(pairs, CharEncoding.UTF_8);
    }
    catch (UnsupportedEncodingException e) {
        throw new BoxRestException(e);
    }
}
 
开发者ID:mobilesystems,项目名称:box-java-sdk-v2,代码行数:18,代码来源:BoxOAuthRequestObject.java

示例11: getNewFileMultipartEntity

import org.apache.commons.codec.CharEncoding; //导入依赖的package包/类
private static MultipartEntityWithProgressListener getNewFileMultipartEntity(final String parentId, final String name, final File file)
    throws BoxRestException, UnsupportedEncodingException {
    MultipartEntityWithProgressListener me = new MultipartEntityWithProgressListener(HttpMultipartMode.BROWSER_COMPATIBLE);
    me.addPart(Constants.FOLDER_ID, new StringBody(parentId));
    me.addPart(KEY_FILE_NAME, new FileBody(file, KEY_FILE_NAME, "", CharEncoding.UTF_8));
    me.addPart(METADATA, getMetadataBody(parentId, name));
    String date = ISO8601DateParser.toString(new Date(file.lastModified()));
    if (me.getPart(KEY_CONTENT_CREATED_AT) == null) {
        me.addPart(KEY_CONTENT_CREATED_AT, new StringBody(date));
    }
    if (me.getPart(KEY_CONTENT_MODIFIED_AT) == null) {
        me.addPart(KEY_CONTENT_MODIFIED_AT, new StringBody(date));
    }

    return me;
}
 
开发者ID:mobilesystems,项目名称:box-java-sdk-v2,代码行数:17,代码来源:BoxFileUploadRequestObject.java

示例12: parseProp

import org.apache.commons.codec.CharEncoding; //导入依赖的package包/类
private static Element parseProp(String value) {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    DocumentBuilder builder = null;
    Document doc = null;
    try {
        builder = factory.newDocumentBuilder();
        ByteArrayInputStream is = new ByteArrayInputStream(value.getBytes(CharEncoding.UTF_8));
        doc = builder.parse(is);
    } catch (Exception e1) {
        throw PersoniumCoreException.Dav.DAV_INCONSISTENCY_FOUND.reason(e1);
    }
    Element e = doc.getDocumentElement();
    return e;
}
 
开发者ID:personium,项目名称:personium-core,代码行数:16,代码来源:DavRsCmp.java

示例13: sha1

import org.apache.commons.codec.CharEncoding; //导入依赖的package包/类
public static String sha1(String text) {
    try {
        return DigestUtils.sha1Hex(text.getBytes(CharEncoding.UTF_8));
    } catch (UnsupportedEncodingException e) {
        return DigestUtils.sha1Hex(text);
    }
}
 
开发者ID:flyingSprite,项目名称:stalactite,代码行数:8,代码来源:Order019ImproveGenerateSHA.java

示例14: sha256

import org.apache.commons.codec.CharEncoding; //导入依赖的package包/类
public static String sha256(String text) {
    try {
        return DigestUtils.sha256Hex(text.getBytes(CharEncoding.UTF_8));
    } catch (UnsupportedEncodingException e) {
        return DigestUtils.sha256Hex(text);
    }
}
 
开发者ID:flyingSprite,项目名称:stalactite,代码行数:8,代码来源:Order019ImproveGenerateSHA.java

示例15: sha384

import org.apache.commons.codec.CharEncoding; //导入依赖的package包/类
public static String sha384(String text) {
    try {
        return DigestUtils.sha384Hex(text.getBytes(CharEncoding.UTF_8));
    } catch (UnsupportedEncodingException e) {
        return DigestUtils.sha384Hex(text);
    }
}
 
开发者ID:flyingSprite,项目名称:stalactite,代码行数:8,代码来源:Order019ImproveGenerateSHA.java


注:本文中的org.apache.commons.codec.CharEncoding类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。