files.java

来自「JSP聊天系统」· Java 代码 · 共 77 行

JAVA
77
字号
package org.ehotsoft.yekki.upload;

import java.io.IOException;
import java.util.*;

public class Files
{

    private Upload parent;
    private Hashtable files;
    private int counter;

    Files() {

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

    protected void addFile( File newFile ) {

        if( newFile == null ) {

            throw new IllegalArgumentException( "newFile cannot be null." );
        }
		else {

            files.put( new Integer( counter ), newFile );
            counter++;
            
			return;
        }
    }

    public File getFile( int index ) {

        if( index < 0 ) {

            throw new IllegalArgumentException( "File's index cannot be a negative value ( 1210 )." );
        }

		File retval = ( File )files.get( new Integer( index ) );
        
		if( retval == null )
            throw new IllegalArgumentException( "Files' name is invalid or does not exist ( 1205 )." );
        else
            return retval;
    }

    public int getCount() {

        return counter;
    }

    public long getSize()
        throws IOException {

        long tmp = 0L;

        for( int i = 0; i < counter; i++ ) {

            tmp += getFile( i ).getSize();
		}

        return tmp;
    }

    public Collection getCollection() {

        return files.values();
    }

    public Enumeration getEnumeration() {

        return files.elements();
    }
}

⌨️ 快捷键说明

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