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


Java CharEncoding类代码示例

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


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

示例1: sendEmail

import org.apache.commons.lang3.CharEncoding; //导入依赖的package包/类
void sendEmail(String to, String subject, String content, String from) {
    log.debug("Send email[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}",
        false, true, to, subject, content);

    // Prepare message using a Spring helper
    MimeMessage mimeMessage = javaMailSender.createMimeMessage();
    try {
        MimeMessageHelper message = new MimeMessageHelper(mimeMessage, false, CharEncoding.UTF_8);
        message.setTo(to);
        message.setFrom(from);
        message.setSubject(subject);
        message.setText(content, true);
        javaMailSender.send(mimeMessage);
        log.debug("Sent email to User '{}'", to);
    } catch (Exception e) {
        if (log.isDebugEnabled()) {
            log.warn("Email could not be sent to user '{}'", to, e);
        } else {
            log.warn("Email could not be sent to user '{}': {}", to, e.getMessage());
        }
    }
}
 
开发者ID:xm-online,项目名称:xm-uaa,代码行数:23,代码来源:MailService.java

示例2: sendEmail

import org.apache.commons.lang3.CharEncoding; //导入依赖的package包/类
@Async
public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) {
    log.debug("Send email[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}",
        isMultipart, isHtml, to, subject, content);

    // Prepare message using a Spring helper
    MimeMessage mimeMessage = javaMailSender.createMimeMessage();
    try {
        MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8);
        message.setTo(to);
        message.setFrom(jHipsterProperties.getMail().getFrom());
        message.setSubject(subject);
        message.setText(content, isHtml);
        javaMailSender.send(mimeMessage);
        log.debug("Sent email to User '{}'", to);
    } catch (Exception e) {
        log.warn("Email could not be sent to user '{}'", to, e);
    }
}
 
开发者ID:deepu105,项目名称:spring-io,代码行数:20,代码来源:MailService.java

示例3: sendEmail

import org.apache.commons.lang3.CharEncoding; //导入依赖的package包/类
@Async
public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) {
    log.debug("Send email[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}",
        isMultipart, isHtml, to, subject, content);

    // Prepare message using a Spring helper
    MimeMessage mimeMessage = javaMailSender.createMimeMessage();
    try {
        MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8);
        message.setTo(to);
        message.setFrom(jHipsterProperties.getMail().getFrom());
        message.setSubject(subject);
        message.setText(content, isHtml);
        javaMailSender.send(mimeMessage);
        log.debug("Sent email to User '{}'", to);
    } catch (Exception e) {
        if (log.isDebugEnabled()) {
            log.warn("Email could not be sent to user '{}'", to, e);
        } else {
            log.warn("Email could not be sent to user '{}': {}", to, e.getMessage());
        }
    }
}
 
开发者ID:oktadeveloper,项目名称:jhipster-microservices-example,代码行数:24,代码来源:MailService.java

示例4: sendEmail

import org.apache.commons.lang3.CharEncoding; //导入依赖的package包/类
@Async
public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) {
    log.debug("Send e-mail[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}",
        isMultipart, isHtml, to, subject, content);

    // Prepare message using a Spring helper
    MimeMessage mimeMessage = javaMailSender.createMimeMessage();
    try {
        MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8);
        message.setTo(to);
        message.setFrom(jHipsterProperties.getMail().getFrom());
        message.setSubject(subject);
        message.setText(content, isHtml);
        javaMailSender.send(mimeMessage);
        log.debug("Sent e-mail to User '{}'", to);
    } catch (Exception e) {
        log.warn("E-mail could not be sent to user '{}'", to, e);
    }
}
 
开发者ID:ElectronicArmory,项目名称:Armory,代码行数:20,代码来源:MailService.java

示例5: sendEmail

import org.apache.commons.lang3.CharEncoding; //导入依赖的package包/类
@Async
public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) {
    log.debug("Send email[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}", isMultipart, isHtml, to, subject, content);

    // Prepare message using a Spring helper
    MimeMessage mimeMessage = javaMailSender.createMimeMessage();
    try {
        MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8);
        message.setTo(to);
        message.setFrom(mailFromDisplay);
        message.setSubject(subject);
        message.setText(content, isHtml);
        javaMailSender.send(mimeMessage);
        log.debug("Sent email to User '{}'", to);
    } catch (Exception e) {
        if (log.isDebugEnabled()) {
            log.warn("Email could not be sent to user '{}'", to, e);
        } else {
            log.warn("Email could not be sent to user '{}': {}", to, e.getMessage());
        }
    }
}
 
开发者ID:megadotnet,项目名称:SpringBootDemoApp,代码行数:23,代码来源:MailService.java

示例6: exportFile

import org.apache.commons.lang3.CharEncoding; //导入依赖的package包/类
/**
 * @description 文件下载
 * @param response
 * @param file
 * @throws IOException
 */
public static void exportFile(HttpServletResponse response, File file) throws IOException {
    String filename = URLEncoder.encode(file.getName(), CharEncoding.UTF_8);
    response.setContentType(HttpUtil.CONTENT_TYPE_APPLICATION_OCTET_STREAM);
    response.setContentLength((int) file.length());
    response.setHeader(HttpUtil.CONTENT_DISPOSITION, "attachment;filename=" + filename);
    response.setHeader(HttpUtil.LOCATION, filename);
    ServletOutputStream out = response.getOutputStream();
    InputStream in = new FileInputStream(file.getPath());
    byte[] buffer = new byte[1024];
    int i;
    while ((i = in.read(buffer)) != -1) {
        out.write(buffer, 0, i);
    }
    in.close();
    out.close();
}
 
开发者ID:tong12580,项目名称:OutsourcedProject,代码行数:23,代码来源:FileManagementUtil.java

示例7: testReadKvPairFrame

import org.apache.commons.lang3.CharEncoding; //导入依赖的package包/类
@Test
public void testReadKvPairFrame() throws IOException {
    String frameStr = "publ 0000000099 0000000410\n" +
            "kv testKey 9\n" +
            "testValue\n" +
            "kv testKey2 10\n" +
            "testValue2\n" +
            "kv testKey 6\n" +
            "foobar\n" +
            "end\n";
    byte[] frameContent = frameStr.getBytes(CharEncoding.UTF_8);
    ByteArrayInputStream in = new ByteArrayInputStream(frameContent);
    Frame frame = Frame.readFromStream(in);

    assertEquals(Command.PUBLISH, frame.getCommand());
    assertEquals(410, frame.getSeqNo());
    assertEquals(3, frame.getKVPairs().size());
    assertEquals("testValue", new String(frame.getFirstValue("testKey"), CharEncoding.UTF_8));
    assertEquals("testValue2", new String(frame.getFirstValue("testKey2"), CharEncoding.UTF_8));
    assertTrue(frame.getRoutingObjects().isEmpty());
    assertTrue(frame.getPayloadObjects().isEmpty());
}
 
开发者ID:SoftwareDefinedBuildings,项目名称:bw2android,代码行数:23,代码来源:FrameTest.java

示例8: testReadPoFrame

import org.apache.commons.lang3.CharEncoding; //导入依赖的package包/类
@Test
public void testReadPoFrame() throws IOException {
    String frameStr = "publ 0000000059 0000000410\n" +
            "po 1.2.3.4: 11\n" +
            "testPayload\n" +
            "end\n";
    byte[] frameContent = frameStr.getBytes(CharEncoding.UTF_8);
    ByteArrayInputStream in = new ByteArrayInputStream(frameContent);
    Frame frame = Frame.readFromStream(in);

    assertEquals(Command.PUBLISH, frame.getCommand());
    assertEquals(410, frame.getSeqNo());
    assertTrue(frame.getKVPairs().isEmpty());
    assertTrue(frame.getRoutingObjects().isEmpty());
    assertEquals(frame.getPayloadObjects().size(), 1);

    PayloadObject.Type expectedType = new PayloadObject.Type(new byte[]{1, 2, 3, 4});
    byte[] expectedContents = "testPayload".getBytes(CharEncoding.UTF_8);
    PayloadObject expectedPayload = new PayloadObject(expectedType, expectedContents);
    assertEquals(expectedPayload, frame.getPayloadObjects().get(0));
}
 
开发者ID:SoftwareDefinedBuildings,项目名称:bw2android,代码行数:22,代码来源:FrameTest.java

示例9: testReadRoFrame

import org.apache.commons.lang3.CharEncoding; //导入依赖的package包/类
@Test
public void testReadRoFrame() throws IOException {
    String frameStr = "pers 0000000046 0000000410\n" +
            "ro 255 6\n" +
            "testRO\n" +
            "end\n";
    byte[] frameContent = frameStr.getBytes(CharEncoding.UTF_8);
    ByteArrayInputStream in = new ByteArrayInputStream(frameContent);
    Frame frame = Frame.readFromStream(in);

    assertEquals(Command.PERSIST, frame.getCommand());
    assertEquals(410, frame.getSeqNo());
    assertTrue(frame.getKVPairs().isEmpty());
    assertTrue(frame.getPayloadObjects().isEmpty());
    assertEquals(frame.getRoutingObjects().size(), 1);

    RoutingObject expectedRo = new RoutingObject(255, "testRO".getBytes(CharEncoding.UTF_8));
    assertEquals(expectedRo, frame.getRoutingObjects().get(0));
}
 
开发者ID:SoftwareDefinedBuildings,项目名称:bw2android,代码行数:20,代码来源:FrameTest.java

示例10: testWriteKvPairFrame

import org.apache.commons.lang3.CharEncoding; //导入依赖的package包/类
@Test
public void testWriteKvPairFrame() throws IOException {
    Frame.Builder builder = new Frame.Builder(Command.PUBLISH, 1600);
    builder.addKVPair("testKey1", "testValue1");
    builder.addKVPair("testKey2", "testValue2");
    Frame frame = builder.build();

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    frame.writeToStream(out);
    String frameStr = out.toString(CharEncoding.UTF_8);

    String expectedFrameStr = "publ 0000000000 0000001600\n" +
            "kv testKey1 10\n" +
            "testValue1\n" +
            "kv testKey2 10\n" +
            "testValue2\n" +
            "end\n";
    assertEquals(expectedFrameStr, frameStr);
}
 
开发者ID:SoftwareDefinedBuildings,项目名称:bw2android,代码行数:20,代码来源:FrameTest.java

示例11: testWritePoFrame

import org.apache.commons.lang3.CharEncoding; //导入依赖的package包/类
@Test
public void testWritePoFrame() throws IOException {
    Frame.Builder builder = new Frame.Builder(Command.SUBSCRIBE, 1840);
    PayloadObject.Type type = new PayloadObject.Type(42);
    PayloadObject po = new PayloadObject(type, "testPayload".getBytes(CharEncoding.UTF_8));
    builder.addPayloadObject(po);
    Frame frame = builder.build();

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    frame.writeToStream(out);
    String frameStr = out.toString(CharEncoding.UTF_8);

    String expectedFrameStr = "subs 0000000000 0000001840\n" +
            "po :42 11\n" +
            "testPayload\n" +
            "end\n";
    assertEquals(expectedFrameStr, frameStr);
}
 
开发者ID:SoftwareDefinedBuildings,项目名称:bw2android,代码行数:19,代码来源:FrameTest.java

示例12: testWriteRoFrame

import org.apache.commons.lang3.CharEncoding; //导入依赖的package包/类
@Test
public void testWriteRoFrame() throws IOException {
    Frame.Builder builder = new Frame.Builder(Command.PUBLISH, 1234);
    RoutingObject ro = new RoutingObject(99, "testRO".getBytes(CharEncoding.UTF_8));
    builder.addRoutingObject(ro);
    Frame frame = builder.build();

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    frame.writeToStream(out);
    String frameStr = out.toString(CharEncoding.UTF_8);

    String expectedFrameStr = "publ 0000000000 0000001234\n" +
            "ro 99 6\n" +
            "testRO\n" +
            "end\n";
    assertEquals(expectedFrameStr, frameStr);
}
 
开发者ID:SoftwareDefinedBuildings,项目名称:bw2android,代码行数:18,代码来源:FrameTest.java

示例13: testPublish

import org.apache.commons.lang3.CharEncoding; //导入依赖的package包/类
@Test
public void testPublish() throws IOException, InterruptedException {
    sem.acquire(); // Block until the subscribe operation is complete

    PublishRequest.Builder builder = new PublishRequest.Builder(BW_URI);

    for (String msg : expectedMessages) {
        builder.clearPayloadObjects();
        PayloadObject.Type poType = new PayloadObject.Type(POAllocations.PODFText);
        byte[] poContents = msg.getBytes(CharEncoding.UTF_8);
        PayloadObject po = new PayloadObject(poType, poContents);
        builder.addPayloadObject(po);

        PublishRequest request = builder.build();
        client.publish(request, responseHandler);
    }

    sem.acquire(); // Wait until all published messages have been received
}
 
开发者ID:SoftwareDefinedBuildings,项目名称:bw2android,代码行数:20,代码来源:BosswaveClientTest.java

示例14: onResultReceived

import org.apache.commons.lang3.CharEncoding; //导入依赖的package包/类
@Override
public void onResultReceived(BosswaveResult result) {
    assertEquals(result.getPayloadObjects().size(), 1);
    byte[] messageContent = result.getPayloadObjects().get(0).getContent();
    String messageText;
    try {
        messageText = new String(messageContent, CharEncoding.UTF_8);
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException("Platform doesn't support UTF-8", e);
    }
    assertTrue(expectedMessages.contains(messageText));
    counter++;

    if (counter == expectedMessages.size()) {
        sem.release();
    }
}
 
开发者ID:SoftwareDefinedBuildings,项目名称:bw2android,代码行数:18,代码来源:BosswaveClientTest.java

示例15: sendEmail

import org.apache.commons.lang3.CharEncoding; //导入依赖的package包/类
@Async
public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) {
    log.debug("Send email[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}",
        isMultipart, isHtml, to, subject, content);

    // Prepare message using a Spring helper
    MimeMessage mimeMessage = javaMailSender.createMimeMessage();
    try {
        MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8);

        message.setTo(to);
        message.setFrom(jHipsterProperties.getMail().getFrom());
        message.setSubject(subject);
        message.setText(content, isHtml);
        javaMailSender.send(mimeMessage);
        log.debug("Sent email to User '{}'", to);
    } catch (Exception e) {
        log.warn("Email could not be sent to user '{}'", to, e);
    }
}
 
开发者ID:benoyprakash,项目名称:java-hostel,代码行数:21,代码来源:MailService.java


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