⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sendmms.java

📁 Java library for encoding/decoding MMS messages. Also provides a simlpe client for sending MMS throu
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		int textMaxSize=0;		int maxSize=0;			boolean skip = false;		boolean verbose=false;						//Read the configuration		String confFile = System.getProperty(CONFIG_FILE_PROPERTY, CONFIG_FILE_DEFAULT);		Properties conf = new Properties();		try {			conf.load(new FileInputStream(confFile));		} catch (FileNotFoundException e) {			System.out.println("Configuration file not found: " + confFile);			System.exit(1);		} catch (IOException e1) {			System.out.println("Error reading configuration: " + e1.getMessage());			System.exit(1);		}						//Get the wap gateway info		wapGatewayHost = conf.getProperty(CONFIG_WAP_GATEWAY_HOST);		if (wapGatewayHost == null){			System.out.println("No gateway host specified");			System.exit(1);		}		String wapGatewayPortString = conf.getProperty(CONFIG_WAP_GATEWAY_PORT);		if (wapGatewayPortString == null){			System.out.println("No gateway port specified");			System.exit(1);					}else{			try{					wapGatewayPort = Integer.parseInt(wapGatewayPortString);			}catch (NumberFormatException e){				System.out.println("The specified gateway port is not a number.");				System.exit(1);							}		}		mmsServlet = conf.getProperty(CONFIG_MMS_SERVLET);		if (mmsServlet ==  null){			System.out.println("No mms servlet specified");			System.exit(1);					}						//Get other configurations		senderNumber = conf.getProperty(CONFIG_SENDER_PROPERTY);		if (senderNumber == null){			System.out.println("No sender specified.");			System.exit(1);		}		subject = conf.getProperty(CONFIG_SUBJECT_PROPERTY);		try{			imageMaxSize = Integer.parseInt(conf.getProperty(CONFIG_IMAGE_MAX_SIZE_PROPERTY, CONFIG_IMAGE_MAX_SIZE_DEFAULT));		}catch(Exception e){			System.out.println("Error processing configuration parameter \"" + CONFIG_IMAGE_MAX_SIZE_PROPERTY + "\".");			System.exit(1);		}		try{			textMaxSize = Integer.parseInt(conf.getProperty(CONFIG_TEXT_MAX_SIZE_PROPERTY, CONFIG_TEXT_MAX_SIZE_DEFAULT));		}catch(Exception e){			System.out.println("Error processing configuration parameter \"" + CONFIG_TEXT_MAX_SIZE_PROPERTY + "\".");			System.exit(1);		}		try{		maxSize = Integer.parseInt(conf.getProperty(CONFIG_MMS_MAX_SIZE_PROPERTY, CONFIG_MMS_MAX_SIZE_DEFAULT));		}catch(Exception e){			System.out.println("Error processing configuration parameter \"" + CONFIG_MMS_MAX_SIZE_PROPERTY + "\".");			System.exit(1);		}		try{		skip = Boolean.parseBoolean(conf.getProperty(CONFIG_SKIP_PROPERTY, CONFIG_SKIP_DEFAULT));		}catch(Exception e){			System.out.println("Error processing configuration parameter \"" + CONFIG_SKIP_PROPERTY + "\".");			System.exit(1);		}								/*		 * Parse the command line		 */		if (args.length > 1){			destNumber = args[0];			for (int i=1; i<args.length; i++){				if (args[i].equals(VERBOSE_SWITCH)){					verbose=true;				}else if (args[i].equals(SUBJECT_SWITCH)){					subject = args[++i];				}else if (args[i].equals(TEXT_STRING_SWITCH)){					contentEntries.add(new ContentEntry(args[++i], ContentEntry.TEXT_STRING));				}else if(args[i].equals(TEXT_FILE_SWITCH)){					contentEntries.add(new ContentEntry(args[++i], ContentEntry.TEXT_FILE));									}else if(args[i].equals(IMAGE_FILE_SWITCH)){					contentEntries.add(new ContentEntry(args[++i], ContentEntry.IMAGE_FILE));									}else if(args[i].equals(IMAGE_MAXSIZE_SWITCH)){					try{						imageMaxSize = Integer.parseInt(args[++i]);					}catch (NumberFormatException e){						System.out.println("Value of " + IMAGE_MAXSIZE_SWITCH + " must be an integer value");						System.exit(1);					}				}else if(args[i].equals(TEXT_MAXSIZE_SWITCH)){					try{						textMaxSize = Integer.parseInt(args[++i]);					}catch (NumberFormatException e){						System.out.println("Value of " + TEXT_MAXSIZE_SWITCH + " must be an integer value");						System.exit(1);					}									}else if(args[i].equals(MMS_MAXSIZE_SWITCH)){					try{						textMaxSize = Integer.parseInt(args[++i]);					}catch (NumberFormatException e){						System.out.println("Value of " + TEXT_MAXSIZE_SWITCH + " must be an integer value");						System.exit(1);					}									}else if(args[i].equals(SKIP_OVERSIZE_SWITCH)){					skip = true;				}else{					if(args[i].equals(HELP_SWITCH) || args[i].equals(HELP_SWITCH_L)) printHelp();					else{						System.out.println("Error in the command line: " + args[i] + " is not an option name.");						printHelp();						System.exit(1);					}				}			}		}else{			printHelp();			System.exit(1);					}				if (contentEntries.size() == 0){			System.out.println("No content specified for the mms.");			System.exit(1);		}		//Here the parsing of the command line is finished. Build an MmsSend object		SendMms mmsSend = new SendMms(senderNumber, destNumber, subject, contentEntries);		mmsSend.setTextMaxSize(textMaxSize);		mmsSend.setImageMaxSize(imageMaxSize);		mmsSend.setMmsMaxSize(maxSize);		mmsSend.setSkip(skip);		mmsSend.setVerbose(verbose);				if (verbose) System.out.println("Checking mms contents...");		try{			mmsSend.checkContentEntries();		}catch (SendMmsException e){			System.out.println(e.getMessage());			System.exit(2);		}		if (verbose){			System.out.println("");			System.out.println("-------------------------------------------------");			System.out.println("From: " + senderNumber);			System.out.println("To: " + destNumber);			System.out.println("Subject: " + subject);			Iterator<ContentEntry> i = contentEntries.iterator();			System.out.println("Parts:");			while (i.hasNext()){				ContentEntry e = i.next();				System.out.println("\t"+ e);			}			System.out.println("-------------------------------------------------");						System.out.println();		}						if (verbose) System.out.println("Building mms binary message...");		try {			mmsSend.buildMMS();		} catch (MmsMessageException e) {			e.printStackTrace();			System.exit(3);		} catch (MmsEncodingException e) {			e.printStackTrace();			System.exit(3);		}				if (verbose) System.out.println("Sending mms message...");		try {			mmsSend.sendMMS(wapGatewayHost, wapGatewayPort, mmsServlet);		} catch (IllegalStateException e) {			e.printStackTrace();			System.exit(5);		} catch (IOException e) {			e.printStackTrace();			System.exit(5);		} catch (MmsDecoderException e) {			System.out.println(e.getMessage());			System.exit(4);		} catch (MmsMessageException e) {			System.out.println(e.getMessage());			System.exit(4);		}				if (verbose) System.out.println("Quitting...");		System.exit(0);	}		/**	 * Prints the help	 */	private static void printHelp(){		/*		 * Exit codes:		 * 0: ok		 * 1: error in configuration/arguments		 * 2: error in mms contents		 * 3: error during binary mms building		 * 4: error sending mms		 * 5: other errors (I/O)		 */		System.out.println("sendmms <dest-number> [-s <subject>] [-t <text> | -T <text-file> | -i <image-file> | ...]");		System.out.println("                      [-is <dim> | -ts <dim> | -S <dim> | --skip | -h |-v]");		System.out.println("\n\t-s: defines the subject of the message");		System.out.println("\t-t: adds a mms-part composed by the string <text>");		System.out.println("\t-T: adds a text mms-part composed by the content of <text-file>");		System.out.println("\t-i: adds an image mms-part composed by the content of <image-file>");		System.out.println("\t-is: define the max size of an image content");		System.out.println("\t-ts: define the max size of a text content");		System.out.println("\t-S: define the max size of the mms message");		System.out.println("\t--skip: skips problematic contents");		System.out.println("\t-v: verbose mode");		System.out.println("\t-h | --help: this help");		System.out.println();		System.out.println("Exit status:");		System.out.println("\t0: ok");		System.out.println("\t1: error in configuration/arguments");		System.out.println("\t2: error in mms contents");		System.out.println("\t3: error during binary mms building");		System.out.println("\t4: error sending mms");		System.out.println("\t5: other errors (I/O)");	}	public boolean isVerbose() {		return verbose;	}	public void setVerbose(boolean verbose) {		this.verbose = verbose;	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -