Kimi's NutShell

          我荒廢的今日,正是昨日殞身之人祈求的明日

          BlogJava 新隨筆 管理
            141 Posts :: 0 Stories :: 75 Comments :: 0 Trackbacks

          package com.telecom.communication;

          import java.io.BufferedInputStream;
          import java.io.File;
          import java.io.FileNotFoundException;
          import java.io.FileOutputStream;
          import java.io.IOException;
          import java.io.InputStream;
          import java.io.OutputStream;
          import java.net.URL;
          import java.sql.Connection;
          import java.sql.ResultSet;
          import java.sql.Statement;
          import java.util.ArrayList;

          import javax.activation.DataHandler;

          import org.apache.axis.attachments.ManagedMemoryDataSource;
          import org.apache.axis.types.URI;
          import org.apache.struts.upload.FormFile;

          import cn.com.chinatelecom.www.schema.ctcc.common.v2_1.SimpleReference;
          import cn.com.chinatelecom.www.schema.ctcc.multimedia_messaging.v2_2.MessagePriority;
          import cn.com.chinatelecom.www.wsdl.ctcc.multimedia_messaging.send.v2_2._interface.SendMessage;
          import cn.com.chinatelecom.www.wsdl.ctcc.multimedia_messaging.send.v2_2.service.SendMessageServiceLocator;

          import com.telecom.dao.DBLinker;
          import com.telecom.util.AttachPart;
          import com.telecom.util.Sequence;

          public class MMS_send {
          ?public MMS_send() {

          ?}

          ?private AttachPart attachmentParts[];

          ?private static SimpleReference _receipt_request;

          ???public void saveMmsMessage(String filepath, AttachPart[] ap,String mmsRoad) {
          ??for (int i = 0; i < ap.length; i++) {
          ???AttachPart part = ap[i];
          ???try {
          ????String s=saveAttachmentMessage(part.getContent().getInputStream(), part
          ??????.getContentType(), mmsRoad, filepath);
          ????System.out.println("last s:"+s);

          ???} catch (Exception e) {

          ????e.printStackTrace();

          ???}
          ??}

          ?}

          ?public String saveAttachmentMessage(InputStream in, String contentType,
          ???String fileName, String folderPath) throws Exception {
          ??System.out.println("FileName: "+fileName);
          ??// 打開多媒體庫
          ??File file = new File(folderPath + "/mmsImage");
          ??// 如果媒體庫不存在則建設(shè)多媒體庫
          ??if (!file.exists()) {
          ???file.mkdirs();
          ??}
          ??// 將圖片存放到多媒體庫,并保存其信息到數(shù)據(jù)庫
          ??String filePath = file.getAbsolutePath();

          ??BufferedInputStream bin = null;
          ??OutputStream os = null;

          ??try {
          ???bin = new BufferedInputStream(in);
          ???file = new File(filePath + "/" + fileName);
          ???if (!file.exists()) {
          ????file.createNewFile();
          ???}
          ???os = new FileOutputStream(file);
          ???byte[] bytes = new byte[1];
          ???int beginIndex = 0;
          ???int endIndex = beginIndex + 1;
          ???while (true) {
          ????int _read = bin.read(bytes, beginIndex, endIndex);
          ????if (_read == -1) {
          ?????break;
          ????}
          ????os.write(bytes);
          ???}
          ???String contextPathFileName = "mmsImage/" + fileName;
          ???bin.close();
          ???in.close();
          ???os.close();
          ???return contextPathFileName;
          ??} catch (IOException e) {
          ???e.printStackTrace();
          ???throw new Exception();
          ??} catch (Exception e) {
          ???e.printStackTrace();
          ???throw new Exception();
          ??} finally {
          ???try {
          ????bin.close();
          ????in.close();
          ????os.close();
          ???} catch (IOException e) {
          ????throw new Exception();
          ???}

          ??}
          ?}

          ?public AttachPart buildEMAttachmentPartFromFile(FormFile mmsFile) {
          ??AttachPart attchmentPart = new AttachPart();
          ??try {
          ???InputStream in = mmsFile.getInputStream();
          ???String contentType = mmsFile.getContentType();
          ???if ("image/pjpeg".equals(contentType))
          ????contentType = "image/jpeg";
          ???ManagedMemoryDataSource source = new ManagedMemoryDataSource(
          ?????mmsFile.getInputStream(), 16384, contentType, true);
          ???attchmentPart.setContent(source);
          ???attchmentPart.setContentType(mmsFile.getContentType());
          ???String fileName = mmsFile.getFileName();
          ???String suffix = fileName.substring(fileName.indexOf('.'));
          ???attchmentPart.setFileName(Sequence.getID("") + suffix);
          ??} catch (FileNotFoundException e) {
          ???e.printStackTrace();
          ??} catch (IOException e) {
          ???e.printStackTrace();
          ??}
          ??return attchmentPart;
          ?}

          ?public static void main(String[] args) {
          ??Sag_sms s = new Sag_sms();
          ??try {
          ???s.sendSmsBySAG("13977770119", "法律", "1004");
          ??} catch (Exception ex) {
          ???ex.printStackTrace();
          ??} finally {
          ??}

          ?}

          }

          posted on 2007-07-06 16:53 Kimi 閱讀(778) 評論(0)  編輯  收藏 所屬分類: Java
          主站蜘蛛池模板: 中西区| 宁远县| 甘孜| 青田县| 商洛市| 黑山县| 濮阳市| 昌平区| 龙岩市| 东源县| 互助| 友谊县| 保定市| 七台河市| 阳春市| 江北区| 临城县| 枣强县| 精河县| 乌恰县| 普定县| 浏阳市| 呼伦贝尔市| 柳州市| 保德县| 兴仁县| 寿阳县| 九龙城区| 丰顺县| 白水县| 抚松县| 共和县| 稷山县| 齐河县| 隆子县| 金平| 凉城县| 宜城市| 宣威市| 普定县| 安顺市|