📄 multimediaparser.java
字号:
/*
* JVending - J2ME MMS Client
* Copyright (C) 2004 Shane Isbell
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jvending.messaging.impl.mms;
import java.io.IOException;
import java.util.NoSuchElementException;
import org.jvending.messaging.MultimediaMessage;
import org.jvending.messaging.impl.io.PeekInputStream;
/**
* @author Shane Isbell
* @version 1.0.0a
* @created 04/03/27
*/
public class MultimediaParser {
public void parse(PeekInputStream pis, Object targetObject) {
MultimediaMessage mmm = (MultimediaMessage) targetObject;
HeaderFieldParser hfp = new HeaderFieldParser();
MimeParser mimeParser = new MimeParser();
hfp.parse(pis, mmm);
try {
if (pis.peekByte(1) != -1) mimeParser.parse(pis, mmm);
} catch(IOException e) {
e.printStackTrace();
}
}
private class HeaderFieldParser {
private WspTokenizer tokenizer;
private boolean moreFields = true;
private HeaderFieldAssembler hfa;
private PeekInputStream pis;
public void parse(PeekInputStream pis, Object targetObject) {
this.pis = pis;
MultimediaMessage mmm = (MultimediaMessage) targetObject;
tokenizer = new WspTokenizer(pis);
tokenizer.setDataOctetTokenizer(new MmsDataOctetTokenizer());
hfa = new HeaderFieldAssembler();
hfa.setTokenizer(tokenizer);
try {
Field field = null;
while(this.hasMoreFields()) {
field = this.getNextField();
if(field != null) mmm.setHeader(field.getName(), field.getValue());
}
} catch(Exception e) {
e.printStackTrace();
System.out.println("FieldType:" + fieldType +":" + "WspTokenType:" + wspTokenType);
}
}
private int fieldType;
private WspToken wspTokenType;
//FIX ME!!!!!: Need to include Non-Encoded Headers
private Field getNextField() throws NoSuchElementException, IOException {
if(this.tokenizer == null) throw new NoSuchElementException("Tokenizer is null");
wspTokenType = (WspToken) tokenizer.nextElement();
fieldType = wspTokenType.getIntValue();
if(fieldType == -1) {//HACK: Skip unencoded headers
if(pis.peekByte(1) == -1) {
moreFields = false; //end this guy
} //false alarm: Just String type
return null;
}
Field field = hfa.getField(fieldType);
if(field == null) moreFields = false;//FIX-ME: A Hack - don't like the way this is handled
else if(field.getName().equals("CONTENT_TYPE")) moreFields = false;
return field;
}
private boolean hasMoreFields() {
return moreFields;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -