渚嬪錛岃鍙杦ww.kingdart.cn/jaccount/imobile.png 杞崲涓篒mage
鍙堜緥濡傦細璇誨彇www.kingdart.cn/jaccount/readme.txt 杞崲涓篠tring
鍙湪妯℃嫙鍣ㄤ笂鎴愬姛鎴戜篃浼氾紝瑕佹眰鏄湡鏈轟笂鎴愬姛錛?br />
/** * -------------------------------------------------- * 瀛楁杈撳叆嫻? * -------------------------------------------------- * 浠嶥ataInputStream緇ф壙 * 涓昏澧炲姞浜嗕粠鏂囨湰鏍煎紡杈撳叆嫻佷腑璇誨叆鏁版嵁瀛楁鐨勮兘鍔? * -------------------------------------------------- * * @author iwinyeah 鏉庢案瓚? * @version 1.0.0 * */ import java.io.DataInputStream; import java.io.IOException; import java.io.InputStream; public class FieldInputStream extends DataInputStream { public final static int BIN_MODE = 0; public final static int TXT_MODE = 1; int mode; public FieldInputStream(InputStream in, int mode) { super(in); this.mode = mode; } public boolean getBoolean() throws IOException { if (mode == 0) { return readBoolean(); } else { if ("1".equals(next())) { return true; } return false; } } public byte getByte() throws IOException { if (mode == 0) { return readByte(); } else { return (byte) Integer.parseInt(next()); } } public short getShort() throws IOException { if (mode == 0) { return readShort(); } else { return (short) Integer.parseInt(next()); } } public int getInt() throws IOException { if (mode == 0) { return readInt(); } else { return Integer.parseInt(next()); } } public long getLong() throws IOException { if (mode == 0) { return readLong(); } else { return Long.parseLong(next()); } } public String getString() throws IOException { if (mode == 0) { if (read() == 0) { return null; } else { return readUTF(); } } else { return next(); } } // 鍙栦笅涓鏍囪瘑絎? private byte[] buffer = new byte[255]; private int length = 0; private boolean eos = false; private final static int INITIAL = 0; private final static int ESCAPE = 1; private final static int COMMENT_START = 2; private final static int LINE_COMMENT = 3; private final static String WHITESPACE = "\n\r\t"; public String next() throws IOException { length = 0; int c = in.read(); int status = INITIAL; READWHILE: while (c != -1) { // 涓鐩磋鍒版枃浠跺熬 switch (status) { case INITIAL: if (c == '\n' || c == '\t') { // 濡傛灉鏄垎闅旂 break READWHILE; } else if (c == '\\') { status = ESCAPE; // 璁捐漿涔夊瓧絎︽爣蹇? } else if (c == '/') { status = COMMENT_START; // 璁炬敞閲婃爣蹇? } else { if (WHITESPACE.indexOf(c) < 0) { append(c); } } break; case ESCAPE: // 澶勭悊杞箟瀛楃 switch (c) { case 'n': append('\n'); break; case 'r': append('\r'); break; case 't': append('\t'); break; case 'b': append('\b'); break; case 'f': append('\f'); break; default: append(c); break; } status = INITIAL; // 璁炬甯告儏鍐墊爣蹇? break; case COMMENT_START: // 澶勭悊娉ㄩ噴 if (c == '/') { status = LINE_COMMENT; // 鏄寮忔敞閲? } else { status = INITIAL; // 濡傛灉閮戒笉鏄垯鎶婃敞閲婅搗濮嬬鍜屽垰璇誨叆鐨勫瓧絎﹂兘鍔犲叆鍒版爣璇嗙涓? append('/'); append(c); } break; case LINE_COMMENT: if (c == '\n') { status = INITIAL; // 濡傛灉褰撳墠涓鴻娉ㄩ噴鐘舵佸垯瑕佷竴鐩磋鍒拌灝炬墠鎭㈠姝e父鎯呭喌鏍囧織 break READWHILE; } break; } c = in.read(); // 璇誨叆涓嬩竴瀛楃 } if (c == -1) { eos = true; } // 濡傛灉璇誨埌鏂囦歡灝炬椂錛屾爣璇嗙闀垮害澶т簬闆訛紝鍒欒繑鍥炴爣璇嗙錛屽惁鍒欒繑鍥濶ULL鍊? if (length <= 0) { return null; } else { return new String(buffer, 0, length, "UTF-8"); } } // 灝嗚鍏ョ殑瀛楃鍔犲叆緙撳啿鍖? private void append(int c) { // 緙撳啿鍖轟笉瓚蟲椂鑷姩鎵╁睍 if (length >= buffer.length) { byte[] xBuffer = new byte[buffer.length + 16]; System.arraycopy(buffer, 0, xBuffer, 0, buffer.length); buffer = null; buffer = xBuffer; } buffer[length++] = (byte) c; } public boolean eos() { return eos; } }
package util; /** * -------------------------------------------------- * 瀛楁杈撳嚭嫻? * -------------------------------------------------- * 浠嶥ataOutputStream緇ф壙 * 涓昏澧炲姞浜嗗悜杈撳嚭嫻佸啓鍏ユ枃鏈牸寮忕殑鏁版嵁瀛楁鐨勮兘鍔? * 鏂囨湰鏍煎紡嫻佸皢鐢盩AB鍒嗛殧瀛楁錛屽洖杞︽崲琛岀鍒嗛殧璁板綍 * -------------------------------------------------- * * @author iwinyeah 鏉庢案瓚? * @version 1.0.0 * */ import java.io.DataOutputStream; import java.io.IOException; import java.io.OutputStream; public class FieldOutputStream extends DataOutputStream { public final static int BIN_MODE = 0; public final static int TXT_MODE = 1; private final static byte[] fieldSplit = {'\t'}; private final static byte[] recordSplit = {'\r','\n'}; private int mode; private boolean nextEnd = false; public FieldOutputStream(OutputStream out, int mode) { super(out); this.mode = mode; } // 鎺ョ潃鍐欏叆鐨勬槸鍚︽渶鍚庝竴涓瓧孌? // 鍐欑涓涓瓧孌靛墠浠ュ弬鏁癴alse璋冪敤瀹? // 鍐欐渶鍚庝竴涓瓧孌靛墠浠ュ弬鏁癴alse璋冪敤瀹? public void setNextEnd(boolean end){ nextEnd = end; } public void putBoolean(boolean value) throws IOException { if (mode == 0) { writeBoolean(value); } else { out.write(value ? '1' : '0'); out.write(nextEnd ? recordSplit : fieldSplit); } } public void putByte(byte value) throws IOException { if (mode == 0) { writeByte(value); } else { out.write(String.valueOf(value).getBytes("UTF-8")); out.write(nextEnd ? recordSplit : fieldSplit); } } public void putShort(short value) throws IOException { if (mode == 0) { writeShort(value); } else { out.write(String.valueOf(value).getBytes("UTF-8")); out.write(nextEnd ? recordSplit : fieldSplit); } } public void putInt(int value) throws IOException { if (mode == 0) { writeInt(value); } else { out.write(String.valueOf(value).getBytes("UTF-8")); out.write(nextEnd ? recordSplit : fieldSplit); } } public void putLong(long value) throws IOException { if (mode == 0) { writeLong(value); } else { out.write(String.valueOf(value).getBytes("UTF-8")); out.write(nextEnd ? recordSplit : fieldSplit); } } public void putString(String value) throws IOException { if (mode == 0) { if (value == null) { writeByte(0); } else { writeByte(1); writeUTF(value); } } else { if(value != null){ byte[] b = value.getBytes("UTF-8"); for(int i = 0; i < b.length; i++){ if(b[i] == '\n'){ out.write('\\'); out.write('n'); } else if(b[i] == '\r'){ out.write('\\'); out.write('r'); } else if(b[i] == '\t'){ out.write('\\'); out.write('t');} else if(b[i] == '\b'){ out.write('\\'); out.write('b');} else if(b[i] == '\f'){ out.write('\\'); out.write('f'); }else{ out.write(b[i]); } } } out.write(nextEnd ? recordSplit : fieldSplit); } } }
package util; /** * -------------------------------------------------- * 鏃ユ湡杞崲瀵硅薄 * -------------------------------------------------- * 涓昏鎻愪緵鏃ユ湡涓?970-01-01鍚庣殑澶╂暟鐨勮漿鎹㈠拰鍒板瓧絎︿覆鐨勮漿鎹? * -------------------------------------------------- * * @author iwinyeah 鏉庢案瓚? * @version 1.0.0 * */ import java.util.Calendar; import java.util.Date; import java.util.TimeZone; public class DateUtil { private static Calendar _calendar = Calendar.getInstance(); // 鐢ㄤ簬鏃ユ湡璁$畻 private static long MSEC_EVERYDAY = 86400000L; // 涓澶╃殑寰鏁? private static int rawOffset = TimeZone.getDefault().getRawOffset(); /** * 灝嗘棩鏈熻漿鎹負1970-01-01鍚庣殑澶╂暟 * * @param Date * theDate 瑕佽綆楀ぉ鏁扮殑鏃ユ湡 * @return int 鎵浼犲叆鏃ユ湡涓?970-01-01鐩稿樊鐨勫ぉ鏁? */ public static int dateToDay(Date theDate) { return (int) ((theDate.getTime() + rawOffset) / MSEC_EVERYDAY); } /** * 灝?970-01-01鍚庣殑澶╂暟杞崲涓烘棩鏈? * * @param int * 瑕佸彇鐨勬棩鏈熶笌1970-01-01鐩稿樊鐨勫ぉ鏁? * @return Date theDate 涓?970-01-01鐩稿樊鐩稿簲澶╂暟鐨勬棩鏈? */ public static Date dayToDate(int day) { return new Date(day * MSEC_EVERYDAY); } /** * 鍙栦粖澶╀笌1970-01-01鐩稿樊鐨勫ぉ鏁? * * @return int 鍙栦粖澶╀笌1970-01-01鐩稿樊鐨勫ぉ鏁? */ public static int toDay() { return (int) ((System.currentTimeMillis() + rawOffset) / MSEC_EVERYDAY); } /** * 灝嗘棩鏈熻漿鎹負騫存湀鏃ュ瓧絎︿覆 * * @param int * theDay 涓?970-01-01鐩稿樊鐨勫ぉ鏁? * @return String 瀵瑰簲鏃ユ湡騫存湀鏃ュ艦寮忕殑瀛楃涓? */ public static String getYMD(int theDay) { _calendar.setTime(dayToDate(theDay)); return _calendar.get(Calendar.YEAR) % 100 + "/" + (_calendar.get(Calendar.MONTH) + 1 > 9 ? "" : "0") + (_calendar.get(Calendar.MONTH) + 1) + "/" + (_calendar.get(Calendar.DATE) > 9 ? "" : "0") + _calendar.get(Calendar.DATE); } /** * 灝嗘棩鏈熻漿鎹負騫存湀瀛楃涓? * * @param int * theDay 涓?970-01-01鐩稿樊鐨勫ぉ鏁? * @return String 瀵瑰簲鏃ユ湡騫存湀褰㈠紡鐨勫瓧絎︿覆 */ public static String getYM(int theDay) { _calendar.setTime(dayToDate(theDay)); return _calendar.get(Calendar.YEAR) + "/" + (_calendar.get(Calendar.MONTH) + 1 > 9 ? "" : "0") + (_calendar.get(Calendar.MONTH) + 1); } /** * 灝嗘棩鏈熻漿鎹負鏈堟棩瀛楃涓? * * @param int * theDay 涓?970-01-01鐩稿樊鐨勫ぉ鏁? * @return String 瀵瑰簲鏃ユ湡鏈堟棩褰㈠紡鐨勫瓧絎︿覆 */ public static String getMD(int theDay) { _calendar.setTime(dayToDate(theDay)); return (_calendar.get(Calendar.MONTH) + 1 > 9 ? "" : "0") + (_calendar.get(Calendar.MONTH) + 1) + "/" + (_calendar.get(Calendar.DATE) > 9 ? "" : "0") + _calendar.get(Calendar.DATE); } /** * 灝嗘棩鏈熻漿鎹負褰撴湀涓鍙? * * @param int * theDay 涓?970-01-01鐩稿樊鐨勫ぉ鏁? * @return int 瀵瑰簲鏃ユ湡鎵鍦ㄦ湀浠界涓澶╀笌1970-01-01鐩稿樊鐨勫ぉ鏁? */ public static int getMonthFirstDay(int theDay) { _calendar.setTime(dayToDate(theDay)); _calendar.set(Calendar.DAY_OF_MONTH, 1); return (int) (dateToDay(_calendar.getTime())); } /** * 鍙栨棩鏈熸墍鍦ㄥ勾浠? * * @param int * theDay 涓?970-01-01鐩稿樊鐨勫ぉ鏁? * @return int 瀵瑰簲鏃ユ湡鎵鍦ㄥ勾浠? */ public static int getYear(int theDay) { _calendar.setTime(dayToDate(theDay)); return _calendar.get(Calendar.YEAR); } /** * 鍙栨棩鏈熸墍鍦ㄦ湀浠? * * @param int * theDay 涓?970-01-01鐩稿樊鐨勫ぉ鏁? * @return int 瀵瑰簲鏃ユ湡鎵鍦ㄦ湀浠? */ public static int getMonth(int theDay) { _calendar.setTime(dayToDate(theDay)); return _calendar.get(Calendar.MONTH); } /** * 鍙栨棩鏈熸墍鍦ㄥ懆嬈? * * @param int * theDay 涓?970-01-01鐩稿樊鐨勫ぉ鏁? * @return int 瀵瑰簲鏃ユ湡鎵鍦ㄥ懆嬈? */ public static int getWeek(int theDay) { // 1971-01-03鏄槦鏈熸棩,浠庤鏃ュ紑濮嬭綆楀懆嬈? _calendar.setTime(dayToDate(theDay)); return (int) ((_calendar.getTime().getTime() - 172800000L) / 604800000L); } }
// public class Action{ String name; // 鍚嶇О Command command; // 鍛戒護 int code; // 浠g爜 (灝嗙敱璇iew鐨勪紶閫掑埌鍏禖ontroller浣跨敤) Item item; // 鏁版嵁欏? boolean defaultAction; // 鏄惁鏄粯璁ょ殑Action //...鐪佺暐 }
public abstract class AbstractView{ //...鐪佺暐 // 涓鴻View澧炲姞Action public void addAction( final Action action, final boolean active ) { if( !actions.containsKey( action.getName() ) ) { // 灝咥ction瀛樺叆Actions琛ㄤ腑 actions.put( action.getName(), action ); if( active ) { activateAction( action ); } } } // 浣緼ction鐢熸晥鍙敤 private void activateAction( final Action action ) { final Command command = action.getCommand(); activeActions.put( command, action ); final Item item = action.getItem(); if( item == null ) { addCommand( command ); // 璇ction鏄睆騫曠浉鍏崇殑鍛戒護 } else { item.addCommand( command ); // 璇ction鏄暟鎹」鐩稿叧鐨勫懡浠? if( action.isDefaultAction() ) { item.setDefaultCommand( command ); } } } //...鐪佺暐 // 鐢ㄦ埛鎸変笅鐩稿簲鐨勫懡浠ら敭鍚?瑙﹀彂鎵ц涓庡叾鍏寵仈鐨凙ction public void commandAction( final Command command, final Displayable displayable ) { if( !handleAction( command ) ) { if( displayable instanceof Choice ) { AbstractController.commandAction( this, command, (Choice) displayable ); } else { AbstractController.commandAction( this, command ); } } } // 鐢ㄦ埛鍦ㄦ煇涓寚瀹氫簡鍛戒護鐨処tem鎸変笅浜嗗懡浠ゆ寜閽椂瑙﹀彂鎵ц涓庡叾鍏寵仈鐨凙ction public void commandAction( final Command command, final Item item ) { if( !handleAction( command ) ) { AbstractController.commandAction( this, command ); } } // 鏍規嵁鎵瑙﹀彂鐨勫懡浠ゆ煡鎵懼叧鑱旂殑Action,騫舵柊瀹冨彂閫佸埌Controller榪涜澶勭悊 public boolean handleAction( final Command command ) { if( activeActions.containsKey( command ) ) { final Action action = (Action) activeActions.get( command ); // 浠ction浠g爜涓哄弬鏁扮敓鎴怌ontrollerEvent騫朵紶閫掑埌controller澶勭悊 final ControllerEvent event = new ControllerEvent( action.getCode(), this ); controller.handle( event ); return true; } else { return false; } } //...鐪佺暐 }
// 鏂規硶涓 public class firstManager implements Runnable { public void runTask() { (new Thread(this)).start(); } public void run() { System.out.println("\nfirst thread method!"); // Do some thing ... } } // 鏂規硶浜? public class secondManager { private BackTask backTask; private Timer timer; public secondManager() { backTask = new BackTask(); timer = new Timer(); } public void runTask() { timer.schedule(backTask, 0); } private class BackTask extends TimerTask { public void run() { System.out.println("\nsecond thread method!"); // Do some thing ... } } } // 鏂規硶涓? public class thirdManager { private BackTask backTask; private int cmd = 0; public thirdManager() { backTask = new BackTask(); backTask.start(); } public void runTask() { synchronized (backTask) { cmd = 1; backTask.notify(); } } private class BackTask extends Thread { public void run() { while (true) { try { if (cmd == 0) { synchronized (this) { wait(); } continue; } System.out.println("\nthird thread method!"); // Do some thing ... } catch (Exception e) { } cmd = 0; } } } } // 鐢ㄤ緥 public void main(){ firstManager man1 = new firstManager(); secondManager man2 = new secondManager(); thirdManager man3 = new thirdManager(); man1.runTask(); man2.runTask(); man3.runTask(); }
//... 鐪佺暐 public static final String WHITESPACE = "\r\n\t "; public String next(final String delimiters, final boolean keepWhitespace, final boolean allowComments, final boolean reuseDelimiter, final boolean processEscape) throws IOException { try { final StringBuffer token = new StringBuffer(); startLine = endLine; startChar = endChar; int c = in.read(); endChar++; int status = INITIAL; while (c != -1) { // 鑻ヨ繕鏈鍒版枃浠跺熬 if (c == '\n') { endLine++; endChar = 0; } switch (status) { case INITIAL: if (delimiters.indexOf(c) > -1) { // 濡傛灉鏄垎闅旂 lastDelimiter = (char) c; if (isWhiteSpace(c)) { // 濡傛灉鍚屾椂涔熸槸絀虹櫧絎﹀茍涓旀爣璇嗙闀垮害澶т簬闆跺垯榪斿洖鏍囪瘑絎? if (token.length() > 0) { if (reuseDelimiter) { // 濡傛灉瑕侀噸鐢ㄥ垎闅旂鍒欏皢瀹冩帹鍥炶緭鍏ユ祦涓? in.revert((char) c); } return token.toString(); } // 濡傛灉榪樻湭鏈夋暟鎹紝榪樿緇х畫寰涓嬭 } else { // 濡傛灉涓嶆槸絀虹櫧絎﹀垯鏃犺鏍囪瘑絎﹂暱搴︽槸鍚︿負闆訛紝閮借榪斿洖 if (reuseDelimiter) { in.revert((char) c); } return token.toString(); } } else if (processEscape && c == '\\') { status = ESCAPE; // 璁捐漿涔夊瓧絎︽爣蹇? } else if (allowComments && c == '/') { status = COMMENT_START; // 璁炬敞閲婃爣蹇? } else if (isWhiteSpace(c)) { if (keepWhitespace) { // 濡傛灉絀虹櫧絎︿篃瑕佺敤錛屾妸瀹冨姞鍏ユ爣璇嗙涓? token.append((char) c); } } else { token.append((char) c); } break; case ESCAPE: // 澶勭悊杞箟瀛楃 switch (c) { case 'n': token.append('\n'); break; case 'r': token.append('\r'); break; case 't': token.append('\t'); break; case 'b': token.append('\b'); break; case 'f': token.append('\f'); break; default: token.append((char) c); break; } status = INITIAL; // 璁炬甯告儏鍐墊爣蹇? break; case COMMENT_START: // 澶勭悊娉ㄩ噴 if (c == '/') { status = LINE_COMMENT; // 鏄寮忔敞閲? } else if (c == '*') { status = BLOCK_COMMENT; // 鏄潡寮忔敞閲? } else { status = INITIAL; // 濡傛灉閮戒笉鏄垯鎶婃敞閲婅搗濮嬬鍜屽垰璇誨叆鐨勫瓧絎﹂兘鍔犲叆鍒版爣璇嗙涓? token.append('/').append((char) c); } break; case LINE_COMMENT: if (c == '\n') { status = INITIAL; // 濡傛灉褰撳墠涓鴻娉ㄩ噴鐘舵佸垯瑕佷竴鐩磋鍒拌灝炬墠鎭㈠姝e父鎯呭喌鏍囧織 } break; case BLOCK_COMMENT: if (c == '*') { status = COMMENT_END; // 濡傛灉褰撳墠涓哄潡娉ㄩ噴鐘舵佸垯瑕佷竴鐩磋鍒?鍙瘋涓哄潡娉ㄩ噴緇撴潫鐘舵? } break; case COMMENT_END: if (c == '/') { status = INITIAL; // 鍦ㄥ潡緇撴潫鐘舵佷笅璇誨埌/鍒欎負鍧楃粨鏉? } else { status = BLOCK_COMMENT; // 鍚﹀垯鍧楁敞閲婅繕鏈粨鏉燂紝鎭㈠涓哄潡娉ㄩ噴鐘舵? } break; } c = in.read(); // 璇誨叆涓嬩竴瀛楃 } // 濡傛灉璇誨埌鏂囦歡灝炬椂錛屾爣璇嗙闀垮害澶т簬闆訛紝鍒欒繑鍥炴爣璇嗙錛屽惁鍒欒繑鍥濶ULL鍊? return token.length() > 0 ? token.toString() : null; } catch (IOException e) { throw new IOException("Error reading input L=" + startLine + " C=" + startChar); } } //... 鐪佺暐