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

📄 fireio.java

📁 wap浏览器 日程安排 Rss 棋牌游戏
💻 JAVA
字号:
/* * Fire (Flexible Interface Rendering Engine) is a set of graphics widgets for creating GUIs for j2me applications.  * Copyright (C) 2006-2008 Bluevibe (www.bluevibe.net) * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA *  *//* * Created on Sep 14, 2006 * */package gr.fire.util;import java.io.ByteArrayInputStream;import java.io.InputStream;import java.util.Hashtable;import java.util.Vector;import javax.microedition.rms.RecordEnumeration;import javax.microedition.rms.RecordStore;/** * FireIO is a utility class containing a set of I/O supporting methods. * It also acts as a cache for loaded images. If an image is loaded once and is later requested again, the old instance will be returned. * This minimizes the memory requirements of an application GUI, without extra efford on the developer side.   * @author padeler * */public final class FireIO{		private static final boolean NORECORDSTORE=false;	private static final int BUFSIZE=500;	private static Hashtable buffer=new Hashtable();	private static int bufferSize=0;	private static String downloadLocation=null;		private static Object lock = new Object();		private FireIO() throws Exception	{	}		/**	 * Deletes all record stores of this midlet	 */	public static void deleteAll() throws Exception	{		Vector allFiles = list();		for(int i =0 ;i<allFiles.size();++i)		{			String file = (String)allFiles.elementAt(i);			deleteFile(file);		}	}		/**	 * 	 * Lists all record stores of this middlet.	 *  	 * @return	 * 	 */	public static Vector list()  	{		Vector res = new Vector();		try{			String []names = RecordStore.listRecordStores();			if(names!=null)			{				for(int i =0 ;i<names.length;++i)				{					String fileName = names[i];					res.addElement(fileName);				}			}		}catch(Exception e)		{			Log.logError("List Files Error",e);		}		return res;	}		public static void deleteFile(String file) throws Exception	{		synchronized (lock)		{			RecordStore.deleteRecordStore(file);		}	}			static int[] recordStoreSize(String name)	{		RecordStore rs =null;		try{			rs = RecordStore.openRecordStore(name,false);			return new int[]{rs.getSize(),rs.getSizeAvailable()};		}catch(Exception e)		{			Log.logError("Failed to get size for RecordStore "+name,e);		}finally{			try{if(rs!=null) rs.closeRecordStore();}catch(Throwable e){}		}		return new int[]{0,0};	}		public static int total()	{		String recordStores[] = RecordStore.listRecordStores();		if(recordStores!=null)		{			int sum=0;			for(int i =0 ;i<recordStores.length;++i)			{				sum+= recordStoreSize(recordStores[i])[0];			}			return sum;		}		return 0;	}		public static int size(String file)	{		return recordStoreSize(file)[0];	}		public static int free()	{		String recordStores[] = RecordStore.listRecordStores();		if(recordStores!=null && recordStores.length>0)		{			return recordStoreSize(recordStores[0])[1];		}		return 0;	}				public static void write(String file,byte[] buffer) throws Exception	{		RecordStore fr=null;		try{			fr = RecordStore.openRecordStore(file,true,RecordStore.AUTHMODE_PRIVATE,true);			RecordEnumeration re = fr.enumerateRecords(null,null,false);			if(re.hasNextElement())			{				int id = re.nextRecordId();				fr.deleteRecord(id);				}			fr.addRecord(buffer,0,buffer.length);		}finally{			 try{if(fr!=null)fr.closeRecordStore();}catch(Exception e){}		}	}		/**	 * Reads a recordstore and returns a stream to it.	 * @param f	 * @return	 */	public static InputStream read(String f) throws Exception	{		RecordStore fr=null;		try{			fr = RecordStore.openRecordStore(f,false,RecordStore.AUTHMODE_PRIVATE,false);			RecordEnumeration re = fr.enumerateRecords(null,null,false);			if(re.hasNextElement())			{				return new ByteArrayInputStream(re.nextRecord());			}			return null;		}finally{			 try{if(fr!=null)fr.closeRecordStore();}catch(Exception e){}		}	}	public static int getBufferSize()	{		return bufferSize;	}	public static void setBufferSize(int bufferSize)	{		if(bufferSize<0) bufferSize=0;		FireIO.bufferSize = bufferSize;	}	public static String getDownloadLocation()	{		return downloadLocation;	}	public static void setDownloadLocation(String downloadLocation)	{		FireIO.downloadLocation = downloadLocation;	}}

⌨️ 快捷键说明

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