📄 loadrecorder.java
字号:
package loader.recorder;
import java.util.*;
import java.io.*;
/**
LoadRecorder records the information of every loader, including the loading resource's properties.
ResourceURL-->records the actual resource location.
DestinationFile-->when completed, the resource will be saved in this file.
ThreadSize-->remember how many threads that the loader manager starts.
Thread(i)-->records the current loading value, end position and start position.
*/
public class LoadRecorder extends Hashtable<String, List<String>> implements Recorder {
public LoadRecorder(){
super();
}
public LoadRecorder( Map<String, List<String>> h ){
super( h );
System.out.println( "create recorder." );
}
/*
call by loader manager to store information.
manager set these properties through put methos of Map class.
*/
synchronized public List<String> put( String key, List<String> value ){
return super.put( key, value );
}
synchronized public List<String> get( int index ){
return super.get( index );
}
public List<String> getList( String str ){
List<String> l = new ArrayList<String>();
StringTokenizer st = new StringTokenizer( str, "," );
while (st.hasMoreTokens()) {
l.add( st.nextToken() );
}
return l;
}
public String getString( List<String> l ){
String str = "";
int i;
for( i=0; i<l.size()-1; i++ ){
str += ( l.get( i ) + ",");
}
str += l.get( i );
return str;
}
public List<String> getList( String[] strs ){
List<String> l = new ArrayList<String>();
for( int i=0; i<strs.length; i++ ){
l.add( strs[i] );
}
return l;
}
/*
call by loader to record his activities.
*/
synchronized public void log( String name, int value ){
List<String> l = get( name );
int pre = 0;
try{
pre = Integer.parseInt( l.get( 0 ) );
}catch( Exception e ){}
pre += value;
l.remove( 0 );
l.add( 0, ""+pre );
}
/*
persist this instance. log all of the information.
*/
public void log( File file ) throws Exception {
PrintWriter out = new PrintWriter( file );
Set<String> keys = keySet();
Iterator<String> i = keys.iterator();
while( i.hasNext() ){
String key = i.next();
out.print( key + "=" );
out.println( getString( get( key ) ) );
}
out.flush();
out.close();
}
public LoadRecorder load( File file ) throws Exception {
Properties pros = new Properties();
FileInputStream fin = new FileInputStream( file );
pros.load( fin );
Enumeration enume = pros.propertyNames();
while( enume.hasMoreElements() ){
String name = ( String) enume.nextElement();
String value = pros.getProperty( name );
put( name, getList( value ) );
}
fin.close();
return this;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -