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

📄 files.java

📁 实现图书管理
💻 JAVA
字号:
package mypkg.jspsmart.upload;

import java.io.IOException;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Hashtable;

/**
 * An abstract representation of an uploaded file. This is a dependant object
 * which can't be directly instantiate.
 * 
 * @author jimshen
 * 
 */
public class Files {

	private Hashtable files;

	private int counter;

	Files() {
		files = new Hashtable();
		counter = 0;
	}

	protected void addFile(File file) {
		if (file == null) {
			throw new IllegalArgumentException("File cannot be null.");
		} else {
			files.put(new Integer(counter), file);
			counter++;
			return;
		}
	}

	/**
	 * Returns the file object corresponding to the index.
	 * 
	 * @param index
	 *            index of the input file
	 * @return a file
	 */
	public File getFile(int index) {
		if (index < 0) {
			throw new IllegalArgumentException(
					"File's index cannot be a negative value (1210).");
		}
		File file = (File) files.get(new Integer(index));
		if (file == null) {
			throw new IllegalArgumentException(
					"Files' name is invalid or does not exist (1205).");
		} else {
			return file;
		}
	}

	/**
	 * Returns the number of files in the collection.
	 * 
	 * @return the number of files
	 */
	public int getCount() {
		return counter;
	}

	/**
	 * Returns the size of all files of the collection
	 * 
	 * @return the size of all files
	 * @throws IOException
	 */
	public long getSize() throws IOException {
		long l = 0L;
		for (int i = 0; i < counter; i++) {
			l += getFile(i).getSize();
		}
		return l;
	}

	/**
	 * Returns a Collection to browse the files.
	 * 
	 * @return the Collection
	 * 
	 */
	public Collection getCollection() {
		return files.values();
	}

	/**
	 * Returns an Enumeration to browse the files.
	 * 
	 * @return the Enumeration
	 */
	public Enumeration getEnumeration() {
		return files.elements();
	}
}

⌨️ 快捷键说明

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