<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-17  評論-6  文章-1  trackbacks-0
      2006年5月10日
    find   basedir   -name   CVS   |xargs   rm   -rf  
    posted @ 2007-04-17 14:32 小鐵匠 閱讀(323) | 評論 (0)編輯 收藏


    ??? public void doFilter(ServletRequest request, ServletResponse response,
    ??????????? FilterChain chain) throws IOException, ServletException {

    ??????? HttpServletRequest req = (HttpServletRequest) request;

    ??????? int length = req.getContentLength();
    ??????? if (length > 0) {
    ??????????? BufferedRequestWrapper bufferedRequest = new BufferedRequestWrapper(req,length);

    ??????????? InputStream is = bufferedRequest.getInputStream();
    ??????????? byte[] content = new byte[length];
    ???????????
    ??????????? int pad = 0;
    ??????????? while(pad < length){
    ??????????????? pad += is.read(content, pad, length);
    ??????????? }

    ????????????request = bufferedRequest;
    ??????? }
    ??????? chain.doFilter(request, response);??????
    ??? }


    BufferedRequestWrapper .java

    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.InputStream;

    import javax.servlet.ServletInputStream;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletRequestWrapper;

    public class BufferedRequestWrapper extends HttpServletRequestWrapper {

    ??? ByteArrayInputStream bais;

    ??? BufferedServletInputStream bsis;

    ??? byte[] buffer;

    ??? public BufferedRequestWrapper(HttpServletRequest req,int length) throws IOException {
    ??????? super(req);
    ??????? // Read InputStream and store its content in a buffer.
    ??????? InputStream is = req.getInputStream();
    ??????? buffer = new byte[length];

    ??????? int pad = 0;
    ??????? while(pad < length){
    ??????????? pad += is.read(buffer, pad, length);
    ??????? }
    ??? }

    ??? public ServletInputStream getInputStream() {
    ??????? try {
    ??????????? // Generate a new InputStream by stored buffer
    ??????????? bais = new ByteArrayInputStream(buffer);
    ??????????? // Istantiate a subclass of ServletInputStream
    ??????????? // (Only ServletInputStream or subclasses of it are accepted by the
    ??????????? // servlet engine!)
    ??????????? bsis = new BufferedServletInputStream(bais);
    ??????? } catch (Exception ex) {
    ??????????? ex.printStackTrace();
    ??????? } finally {
    ??????? }
    ??????? return bsis;
    ??? }

    }




    BufferedServletInputStream .java

    import java.io.*;
    import javax.servlet.ServletInputStream;

    /*
    ?Subclass of ServletInputStream needed by the servlet engine.
    ?All inputStream methods are wrapped and are delegated to
    ?the ByteArrayInputStream (obtained as constructor parameter)!
    ?*/
    public class BufferedServletInputStream extends ServletInputStream {

    ??? ByteArrayInputStream bais;

    ??? public BufferedServletInputStream(ByteArrayInputStream bais) {
    ??????? this.bais = bais;
    ??? }

    ??? public int available() {
    ??????? return bais.available();
    ??? }

    ??? public int read() {
    ??????? return bais.read();
    ??? }

    ??? public int read(byte[] buf, int off, int len) {
    ??????? return bais.read(buf, off, len);
    ??? }

    }

    posted @ 2006-10-25 17:01 小鐵匠 閱讀(2739) | 評論 (1)編輯 收藏
    $ gcc -o x11fred -L/usr/openwin/lib x11fred.c -lX11
    will compile and link a program called x11fred using the version of the library libX11 found in the
    /usr/openwin/lib directory.
    posted @ 2006-07-10 14:54 小鐵匠 閱讀(421) | 評論 (0)編輯 收藏

    有發送人名稱中文支持,支持bytes格式附件,附件中文支持

    ? public static boolean send(String fromName, String fromAddr, String to, String subject, String
    ???????????????????????????? body, String fileName, byte[] file) throws
    ????? Exception {
    ??????? //發送人名稱,用base64編碼,再加上特殊標志
    ??????? fromName = "=?GB2312?B?" + new String(base64.encode((fromName).getBytes()))? + "?=";
    ??? Properties props = new Properties();
    ??? Session session = Session.getInstance(props, null);
    ??? props.put("mail.smtp.host", Constants.mailhost);
    ??? props.put("mail.smtp.auth", "false");?
    ??? Message msg = new MimeMessage(session);
    ????? msg.setFrom(new InternetAddress(fromAddr,fromName));
    //后面的BodyPart將加入到此處創建的Multipart中
    ??? Multipart mp = new MimeMultipart();
    // Create the message part
    ??? BodyPart messageBodyPart = new MimeBodyPart();

    ??? // Fill the message
    ??? messageBodyPart.setText(body);

    ??? mp.addBodyPart(messageBodyPart);

    ????? /*發送附件*/
    ???? if (file != null && file.length > 0) {
    ?????? //利用枚舉器方便的遍歷集合
    ???????? MimeBodyPart mbp = new MimeBodyPart();?
    //???????? File fileTmp = null;
    ???????? //得到數據源
    //???????? FileDataSource fds = new FileDataSource(fileTmp);
    ???????? //得到附件本身并至入BodyPart
    ???????? mbp.setDataHandler(new DataHandler(new ByteArrayDataSource(file,"application/octet-stream")));
    ???????? //得到文件名同樣至入BodyPart
    ???????? mbp.setFileName(MimeUtility.encodeWord(fileName,"GB2312",null));
    ???????? mp.addBodyPart(mbp);
    ???? }
    ???
    ??? //Multipart加入到信件
    ??? msg.setContent(mp);

    ??? msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
    ??? msg.setSubject(subject);

    ??? msg.setHeader("X-Mailer", "personal Email Sender");
    ??? msg.setSentDate(new Date());

    ??? Transport transport = session.getTransport("smtp");

    ??? //添加認證信息
    ??? transport.connect(Constants.mailhost, Constants.user, Constants.pwd);
    ??? transport.sendMessage(msg, msg.getRecipients(Message.RecipientType.TO));
    ??? transport.close();
    ??? return true;
    ? }




    import java.io.*;
    import javax.activation.*;

    public class ByteArrayDataSource implements DataSource {
    ??? /** * Data to write. */
    ??? private byte[] _data;

    ??? /** * Content-Type. */
    ??? private String _type;

    ??? /* Create a datasource from an input stream */
    ??? public ByteArrayDataSource(InputStream is, String type) {
    ??????? _type = type;
    ??????? try {
    ??????????? ByteArrayOutputStream os = new ByteArrayOutputStream();
    ??????????? int ch;

    ??????????? // XXX : must be made more efficient by
    ??????????? // doing buffered reads, rather than one byte reads
    ??????????? while ((ch = is.read()) != -1)
    ??????????????? os.write(ch);
    ??????????? _data = os.toByteArray();
    ??????? } catch (IOException ioe) {
    ??????? }
    ??? }

    ??? /* Create a datasource from a byte array */
    ??? public ByteArrayDataSource(byte[] data, String type) {
    ??????? _data = data;
    ??????? _type = type;
    ??? }

    ??? /* Create a datasource from a String */
    ??? public ByteArrayDataSource(String data, String type) {
    ??????? try {
    ??????????? // Assumption that the string contains only ascii
    ??????????? // characters ! Else just pass in a charset into this
    ??????????? // constructor and use it in getBytes()
    ??????????? _data = data.getBytes("iso-8859-1");
    ??????? } catch (UnsupportedEncodingException uee) {
    ??????? }
    ??????? _type = type;
    ??? }

    ??? 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";
    ??? }
    }

    posted @ 2006-05-10 18:02 小鐵匠 閱讀(642) | 評論 (1)編輯 收藏
    主站蜘蛛池模板: 美女裸体无遮挡免费视频网站| 4480yy私人影院亚洲| 亚洲av午夜电影在线观看| 美女视频黄的全免费视频| 亚洲国产成人久久| 青草草色A免费观看在线| 亚洲国产精品综合久久网各| 亚洲精品国产免费| 亚洲福利一区二区| 妞干网在线免费视频| 自拍偷自拍亚洲精品播放| 无码不卡亚洲成?人片| 美女被免费视频网站a国产| 亚洲国产成人手机在线观看| 国产又黄又爽又刺激的免费网址| 国产精品亚洲一区二区在线观看| 免费在线观看黄色毛片| 国产一二三四区乱码免费| 久久久久亚洲AV成人无码| 日韩中文字幕精品免费一区| 亚洲日韩一中文字暮| 国产亚洲福利一区二区免费看| 一级毛片无遮挡免费全部| 亚洲精品视频在线| 成人免费在线视频| 在线视频网址免费播放| 亚洲欧洲高清有无| 亚洲国产香蕉人人爽成AV片久久 | 国产成人无码区免费A∨视频网站 国产成人涩涩涩视频在线观看免费 | 亚洲国产成人精品无码区花野真一| 国产成人精品免费视频大全五级| 久久精品免费网站网| 亚洲欧洲精品在线| 男人的天堂亚洲一区二区三区| 免费国产黄网站在线看| 亚洲视频手机在线| 亚洲av麻豆aⅴ无码电影| 99在线观看精品免费99| 国产成人 亚洲欧洲| 亚洲三级电影网址| 亚洲欧洲精品成人久久曰影片|