📄 contententry.java
字号:
/* * Copyright (C) 2008 Andrea Zito * * This file is part of SendMMS. * * jMmsLib is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of * the License, or (at your option) any later version. * * SendMMS 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 General Public License for more details. * * You should have received a copy of the GNU General Public * License along with SendMMS. If not, see <http://www.gnu.org/licenses/>. */ package net.sourceforge.jmmslib.sendmms;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.IOException;import java.io.RandomAccessFile;import java.io.UnsupportedEncodingException;/** * Helper class for loading contents. * * @author Andrea Zito * */public class ContentEntry { public static final int TEXT_STRING = 0; public static final int TEXT_FILE = 1; public static final int IMAGE_FILE = 2; private String s; private int type; byte[] content = null; String stringContent = null; String fileName = null; public ContentEntry(String s, int type){ this.s = s; this.type = type; } public String getS() { return s; } public int getType() { return type; } public byte[] getContent(){ return content; } public String toString(){ switch(type){ case TEXT_STRING: return "TEXT_STRING: " + stringContent; case TEXT_FILE: return "TEXT_FILE: " + fileName; case IMAGE_FILE: return "TEXT_IMAGE: " + fileName; default: return "UNKNOWN"; } } public void loadContent() throws SendMmsException{ switch(type){ case TEXT_STRING: try { stringContent = s; content = s.getBytes("US-ASCII"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } break; case TEXT_FILE: FileReader fr; fileName = s; StringBuffer text = new StringBuffer(); try { fr = new FileReader(s); char[] buffer = new char[1024]; int i; do{ i = fr.read(buffer); if (i>0)text.append(buffer, 0, i); else break; }while(true); } catch (FileNotFoundException e) { throw new SendMmsException("File " + s + " not found"); } catch (IOException e) { e.printStackTrace(); } try { content = text.toString().getBytes("US-ASCII"); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); } case IMAGE_FILE: FileInputStream fin; RandomAccessFile f; fileName = s; try { fin = new FileInputStream(s); f = new RandomAccessFile(s,"r"); } catch (FileNotFoundException e) { throw new SendMmsException("File " + s + " not found"); } long size=0; try { size = f.length(); } catch (IOException e) { e.printStackTrace(); } if (size > Integer.MAX_VALUE) throw new SendMmsException("File " + s + " too big"); content = new byte[(int)size]; try { fin.read(content); } catch (IOException e) { e.printStackTrace(); } } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -