bytearraydatasource.java
来自「展示使用J2EE容器实现安全机制」· Java 代码 · 共 56 行
JAVA
56 行
package com.jdon.mailer.ejb;import java.io.ByteArrayInputStream;import java.io.InputStream;import java.io.IOException;import java.io.OutputStream;import java.io.UnsupportedEncodingException;import java.util.Date;import javax.activation.DataSource;/** * Used to create a DataSource for the mail message. * @see MailHelper */class ByteArrayDataSource implements DataSource { private byte[] data; // data for mail message private String type; // content type/mime type /** * Create a DataSource from a String * @param data is the contents of the mail message * @param type is the mime-type such as text/html */ ByteArrayDataSource(String data, String type) { try { this.data = data.getBytes("UTF-8"); } catch (UnsupportedEncodingException uex) { } this.type = type; } //DataSource interface methods public InputStream getInputStream() throws IOException { if (data == null) throw new IOException("no data"); return new ByteArrayInputStream(data); } public OutputStream getOutputStream() throws IOException { throw new IOException("cannot do this"); } public String getContentType() { return type; } public String getName() { return "dummy"; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?