本文整理汇总了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());
}
}
}
示例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);
}
}
示例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());
}
}
}
示例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);
}
}
示例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());
}
}
}
示例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();
}
示例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());
}
示例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));
}
示例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));
}
示例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);
}
示例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);
}
示例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);
}
示例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
}
示例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();
}
}
示例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);
}
}