锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲欧洲日产国码二区首页,亚洲1区2区3区精华液,亚洲制服丝袜中文字幕 http://www.tkk7.com/xiaodong0417/category/51480.htmlJava Study zh-cn Thu, 04 Apr 2013 06:00:58 GMT Thu, 04 Apr 2013 06:00:58 GMT 60 涓枃鍜孉SCII浜掕漿 http://www.tkk7.com/xiaodong0417/archive/2013/04/03/397375.html鐜嬫爲涓?/dc:creator>鐜嬫爲涓?/author>Wed, 03 Apr 2013 13:16:00 GMT http://www.tkk7.com/xiaodong0417/archive/2013/04/03/397375.html http://www.tkk7.com/xiaodong0417/comments/397375.html http://www.tkk7.com/xiaodong0417/archive/2013/04/03/397375.html#Feedback 0 http://www.tkk7.com/xiaodong0417/comments/commentRss/397375.html http://www.tkk7.com/xiaodong0417/services/trackbacks/397375.html 鎴戜滑鍦ㄥ紑鍙戜嬌鏃跺父浼氱敤鍒拌祫婧愭枃浠訛紝榪欏彲鑳芥槸涓轟簡澶氳璦銆佸浗闄呭寲鐨勯渶瑕侊紝涔熷彲鑳芥槸浣跨敤浜嗗浗澶栧紑婧愰」鐩殑鍘熷洜錛岃繖灝遍渶瑕佷腑鏂囪漿ascii灝嗕腑鏂囪漿鎹負 ASCII 緙栫爜錛屾垨鑰呭皢 ASCII 杞崲涓轟腑鏂囷紝閭d箞鎴戜滑灝卞彲浠ヤ嬌鐢?/span> JDK 鑷甫鐨勮漿鎹㈠伐鍏?/span> native2ascii 銆?/span>
for example 錛?/span>
No1 銆佷腑鏂囪漿鎹負 ASCII 緙栫爜
姝ラ錛?/span>1 銆佸湪 D 鐩樻柊寤?/span> chinese.txt 鏂囦歡錛屽唴瀹逛負錛?/span>
parameter.project.title= 榪欐槸涓枃
2 銆佸湪鐜鍙橀噺涓緗ソ JDK 璺緞
3 銆佽繘鍏?/span> dos 鎺у埗鍙幫紝騫惰繘鍏?/span> D 鐩樼洰褰?/span>
4 銆佽緭鍏ュ懡浠わ細 native2ascii -encoding gb2312 chinese.txt ascii.txt 鍥炶濺
閭d箞鍦?/span>D 鐩樼洰褰曚笅鐢熸垚 ascii.txt 鏂囦歡錛屽唴瀹逛負錛?/span>
parameter.project.title=\u8fd9\u662f\u4e2d\u6ascii鐮?涓枃587
No1 銆?/span> ASCII 緙栫爜杞崲涓轟腑鏂?/span>
姝ラ錛?/span>1 銆佸湪 D 鐩樻柊寤?/span> ascii.txt 鏂囦歡錛屽唴瀹逛負錛?/span>
parameter.project.title=\u8fd9\u662f\u4e2d\u6ascii鐮?涓枃587
2 銆佸湪鐜鍙橀噺涓緗ソ JDK 璺緞
3 銆佽繘鍏?/span> dos 鎺у埗鍙幫紝騫惰繘鍏?/span> D 鐩樼洰褰?/span>
4 銆佽緭鍏ュ懡浠わ細 native2ascii -reverse -encoding UTF8 ascii.txt chinese.txt 鍥炶濺
閭d箞鍦?/span>D 鐩樼洰褰曚笅鐢熸垚 chinese.txt 鏂囦歡錛屽唴瀹逛負錛?/span>
parameter.project.title= 榪欐槸涓枃
]]>Java緙栫▼鎶宸т箣final http://www.tkk7.com/xiaodong0417/archive/2012/10/15/389614.html鐜嬫爲涓?/dc:creator>鐜嬫爲涓?/author>Mon, 15 Oct 2012 14:23:00 GMT http://www.tkk7.com/xiaodong0417/archive/2012/10/15/389614.html http://www.tkk7.com/xiaodong0417/comments/389614.html http://www.tkk7.com/xiaodong0417/archive/2012/10/15/389614.html#Feedback 0 http://www.tkk7.com/xiaodong0417/comments/commentRss/389614.html http://www.tkk7.com/xiaodong0417/services/trackbacks/389614.html 鍏抽敭璇峟inal鍦↗ava涓湁澶氶噸鐢ㄩ旓紝鏃㈠彲琚敤浜巌nstance鍙橀噺銆乻tatic鍙橀噺
涔熷彲鐢ㄤ簬classes鎴杕ethods錛岃〃紺轟笉鍏佽瀹㈡埛瑕嗗啓瀹冧滑銆?/div>
褰撲竴涓柟娉曡澹版槑鎴恌inal錛屽湪涓や釜棰嗗煙涓樉寰楁湁浣嶉噸瑕侊細
class璁捐 榪愯鏈熸ц兘 鍦ㄧ▼搴忚璁¢噷錛屾湁鏃舵垜浠笉甯屾湜鎴戜滑鐨勬柟娉曡閲嶅啓鎴栬鐩栵紝final鍏抽敭瀛椾繚璇佷簡榪欎竴鐐廣?/div>
final鍏抽敭瀛楁槸鎬庝箞褰卞搷鎬ц兘鐨勫憿錛?/div>
褰撴垜浠殑鏂規硶琚0鏄庢垚static錛宖inal鍜宲rivate錛?姝ゆ柟娉曞皢鎴愪負Inlining錛堝唴鑱斿嚱鏁?鐨勫欓夎呫傛綾繪柟娉曞彲浠ュ湪緙栬瘧鏈熻闈欐佸喅璁紙staticallyresolved錛夛紝鑰屼笉闇瑕佸姩鎬佸喅璁?dynamicResolution)銆備互鏂規硶鏈綋錛坢ethodbody錛夋浛鎹㈡柟娉曡皟鐢紙methodcall錛変細浣夸唬鐮佹墽琛岄熷害鏇村揩銆?/div>
灝嗘柟娉曞0鏄庝負static銆乫inal鍜宲rivate浼氬甫鏉ヤ竴浜涚己鐐癸細榪欐牱鐨勬柟娉曟棤娉曢氳繃Subclassing(瀛愮被鍖?榪涜鎵╁睍銆傝繖灝辨潫緙氫簡derived class閫氳繃class鍑芥暟鍋氫簨鎯呯殑鏈轟細銆俰nlined鏂規硶鍙湁鍦ㄨ澶氭璋冪敤鐨勬儏鍐典笅錛屾墠浼氳幏寰椾護浜轟晶鐩殑鎬ц兘鎻愬崌銆傝繖鏄洜涓哄綋涓涓柟娉曡inline鍚庯紝灝變笉鍐嶉渶瑕佽礋鎷呮柟娉曡皟鐢ㄧ殑棰濆寮閿銆傚洜姝わ紝鏂規硶琚皟鐢ㄦ剤澶氭錛岃妭鐪佸氨鎰堝銆?/div>
涓嶈繃inlining涔熷彲鑳戒嬌浣犵殑浠g爜浣撶Н鍙樺ぇ銆傚鏋滆繖涓柟娉曟湁璁稿璋冪敤鐐癸紝.class鏂囦歡鐨勪綋縐究浼氳啫鑳錛岃繖鏄洜涓哄師鏈彧闇瀛樺偍涓浠界殑鍑芥暟鐮侊紝鐢變簬inline鑰屽湪鎵鏈夎皟鐢ㄧ偣琚鍒朵簡涓浠姐?/div>
]]>
Java NIO 綆鍗曠粡鍏哥ず渚?/title> http://www.tkk7.com/xiaodong0417/archive/2012/09/26/388634.html鐜嬫爲涓?/dc:creator>鐜嬫爲涓?/author>Wed, 26 Sep 2012 14:40:00 GMT http://www.tkk7.com/xiaodong0417/archive/2012/09/26/388634.html http://www.tkk7.com/xiaodong0417/comments/388634.html http://www.tkk7.com/xiaodong0417/archive/2012/09/26/388634.html#Feedback 0 http://www.tkk7.com/xiaodong0417/comments/commentRss/388634.html http://www.tkk7.com/xiaodong0417/services/trackbacks/388634.html /** * */ package dongzi.nio.exercise.nio;import java.io.IOException;import java.net.InetSocketAddress;import java.net.ServerSocket;import java.nio.ByteBuffer;import java.nio.channels.ClosedChannelException;import java.nio.channels.SelectionKey;import java.nio.channels.Selector;import java.nio.channels.ServerSocketChannel;import java.nio.channels.SocketChannel;import java.util.Iterator;/** * @author kyle * */ public class SelectSockets { private static final int PORT_NUMBER = 1234; /** * @param args */ public static void main(String[] args) { new SelectSockets().go(args); } private void go(String[] args) { int port = PORT_NUMBER; if (args.length > 0) { try { port = Integer.parseInt(args[0]); } catch (Exception e) { } } System.out.println("Listening port: " + PORT_NUMBER); try { Selector selector = Selector.open(); startServer(port, selector); while (true ) { int n = selector.select(); if (n == 0) { continue ; } Iterator it = selector.selectedKeys().iterator(); while (it.hasNext()) { SelectionKey key = (SelectionKey) it.next(); if (key.isAcceptable()) { ServerSocketChannel server = (ServerSocketChannel) key .channel(); SocketChannel channel = server.accept(); registerChannel(selector, channel, SelectionKey.OP_READ); sayHello(channel); } if (key.isReadable()) { readDataFromChannel(key); } } it.remove(); } } catch (IOException e) { e.printStackTrace(); } } private ByteBuffer buffer = ByteBuffer.allocate(1024); private void readDataFromChannel(SelectionKey key) throws IOException { int count = 0; SocketChannel channel = (SocketChannel) key.channel(); buffer.clear(); while ((count = channel.read(buffer)) > 0) { buffer.flip(); while (buffer.hasRemaining()) { System.out.println(buffer.get()); } buffer.clear(); } if (count < 0) { channel.close(); } } private void sayHello(SocketChannel channel) throws IOException { if (channel == null ) { return ; } buffer.clear(); ByteBuffer buffer = ByteBuffer.wrap("Hi, there \r\n".getBytes()); buffer.flip(); channel.write(buffer); } private void registerChannel(Selector selector, SocketChannel channel, int opRead) throws IOException { if (channel == null ) { return ; } channel.configureBlocking(false ); channel.register(selector, opRead); } private void startServer(int port, Selector selector) throws IOException, ClosedChannelException { ServerSocketChannel serverChannel = ServerSocketChannel.open(); serverChannel.configureBlocking(false ); ServerSocket serverSocket = serverChannel.socket(); serverSocket.bind(new InetSocketAddress(port)); serverChannel.register(selector, SelectionKey.OP_ACCEPT); } }
]]> Jibx綆鍗曠ず渚?/title> http://www.tkk7.com/xiaodong0417/archive/2011/11/28/365010.html鐜嬫爲涓?/dc:creator>鐜嬫爲涓?/author>Mon, 28 Nov 2011 09:16:00 GMT http://www.tkk7.com/xiaodong0417/archive/2011/11/28/365010.html http://www.tkk7.com/xiaodong0417/comments/365010.html http://www.tkk7.com/xiaodong0417/archive/2011/11/28/365010.html#Feedback 0 http://www.tkk7.com/xiaodong0417/comments/commentRss/365010.html http://www.tkk7.com/xiaodong0417/services/trackbacks/365010.html 棣栧厛浠?JiBX 緗戠珯涓嬭澆 JiBX錛屽綋鍓嶆渶鏂扮増鏈槸 beta 3銆傝В寮涓嬭澆鐨?zip 鏂囦歡錛岄噷闈㈡湁涓涓?lib 鐩綍錛屽寘鍚簡 bcel.jar, jibx-bind.jar, jibx-extras.jar, jibx-run.jar, xpp3.jar 浜斾釜 jar 鏂囦歡銆俠cel.jar, jibx-bind.jar 鍙湁鍦?binding compiler 鐨勬椂鍊欐墠鐢ㄥ緱鍒般俲ibx-extras.jar 鏄竴涓彲閫夌殑宸ュ叿鍖咃紝閲岄潰鏈変竴浜涙祴璇曞拰楠岃瘉鐨勫伐鍏風被銆?nbsp;
1.瀹氫箟涓涓垜浠皢瑕佸鐞?XML 鏂囦歡錛屾枃浠跺悕涓?data.xml錛屽唴瀹瑰涓嬶細
< customer >
< person >
< cust-num > 123456789 </ cust-num >
< first-name > John </ first-name >
< last-name > Smith </ last-name >
</ person >
< street > 12345 Happy Lane </ street >
< city > Plunk </ city >
< state > WA </ state >
< zip > 98059 </ zip >
< phone > 888.555.1234 </ phone >
</ customer >
榪欎釜 XML 鏂囦歡闈炲父綆鍗曪紝鍏辨湁鍗佷釜鍏冪礌錛屾病鏈夊睘鎬с傛牴鍏冪礌 customer 鏈?person, street, city, state, zip, phone 鍏釜瀛愬厓绱犮傚叾涓厓绱?person 鏈?cust-num, first-name, last-name 涓変釜瀛愬厓绱犮?nbsp;
2.鎺ョ潃瀹氫箟涓や釜 Java 綾?Customer 鍜?Person錛屼篃閲囩敤鏈綆鍗曠殑鏂瑰紡錛岀敤瀵硅薄鐨勫煙鍊煎搴斿厓绱狅紝鍐呭濡備笅錛?nbsp;
public class Customer {
public Person person;
public String street;
public String city;
public String state;
public Integer zip;
public String phone;
}
public class Person {
public int customerNumber;
public String firstName;
public String lastName;
}
榪欎釜涓や釜綾繪病鏈変換浣曟柟娉曪紝澶熺畝鍗曞惂錛佹垨璁鎬綘宸茬粡鐪嬪嚭鏉ヤ簡錛孋ustomer 綾葷殑涓冧釜 field 瀵瑰簲鐨勬槸 XML 鏂囦歡涓?customer 鍏冪礌鐨勪竷涓瓙鍏冪礌銆侾erson 綾葷殑涓変釜 field 瀵瑰簲鐨勬槸 person 鍏冪礌鐨勪笁涓瓙鍏冪礌銆傚湪 Person 綾葷殑 field 鐨勫悕縐板茍涓嶆槸鍜?person 鍏冪礌鐨勫瓙鍏冪礌鍚嶇О瀹屽叏鐩哥瓑錛岃繖鏄伒瀹?Java 緙栫▼瑙勮寖 field 鍛藉悕鐨勯渶瑕侊紝铏界劧涓嶇浉絳夛紝浣嗚繖涓嶉噸瑕侊紝鍙互鍦ㄧ粦瀹氬畾涔夋枃鎸′腑鎶婂畠浠竴涓瀵瑰簲璧鋒潵銆?nbsp;
3.緇戝畾瀹氫箟鏂囨尅
緇戝畾瀹氫箟鏂囨尅鏄緷鎹粦瀹氬畾涔夎鑼冨皢 XML 鏁版嵁鍜?Java 瀵硅薄緇戝畾鐨?XML 鏂囨尅銆傛枃浠跺悕涓?binding.xml錛屽唴瀹瑰涓嬶細
binding.xml 鏂囦歡涓殑 name 鍜?field 灞炴у垎鍒皢 XML 涓殑鍏冪礌鍜?Java 瀵硅薄涓殑 field 涓涓瀵瑰簲騫剁粦瀹氳搗鏉ャ?nbsp;
<mapping name="customer" class="Customer">
mapping 鍏冪礌鐨?name 鍜?class 灞炴у皢 customer 鏍瑰厓绱犲拰 Customer 綾葷粦瀹氬湪涓璧楓?nbsp;
<structure name="person" field="person">
public Person person;
涓婇潰涓よ瀹氫箟浜?person 鏄?Customer 鐨?field錛屽悓鏃朵篃鎶?person 鍏冪礌鍜?person 綾葷粦瀹氬湪涓璧楓?nbsp;
< binding >
< mapping name ="customer" class ="Customer" >
< structure name ="person" field ="person" >
< value name ="cust-num" field ="customerNumber" />
< value name ="first-name" field ="firstName" />
< value name ="last-name" field ="lastName" />
</ structure >
< value name ="street" field ="street" />
< value name ="city" field ="city" />
< value name ="state" field ="state" />
< value name ="zip" field ="zip" />
< value name ="phone" field ="phone" />
</ mapping >
</ binding >
4.鎵ц Binding Compiler 榪囩▼
浠ヤ笅鍛戒護鏄湪 Linux 涓嬫墽琛岋紝濡傛灉鏄?Windows 騫沖彴璇瘋漿鎹㈡垚鐩稿簲鐨勫懡浠?nbsp;
#javac Person.java
#javac - classpath . Customer.java
#java - jar lib / jibx - bind.jar binding.xml
鎵ц瀹屽悗錛屽湪褰撳墠鐩綍澶氫簡鍥涗釜 class 鏂囦歡錛屽垎鍒槸 Person.class, Customer.class, JiBX_bindingCustomer_access.class, JiBX_bindingFactory.class銆?nbsp;
5.鎵ц binding runtime 榪囩▼
鎺ョ潃鍐欎竴涓畝鍗曠殑璇誨彇 data.xml 嫻嬭瘯紼嬪簭 Test.java錛屽唴瀹瑰涓嬶細
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import org.jibx.runtime.JiBXException;
import org.jibx.runtime.IBindingFactory;
import org.jibx.runtime.BindingDirectory;
import org.jibx.runtime.IUnmarshallingContext;
class Test {
public static void main(String[] args) {
try {
IBindingFactory bfact = BindingDirectory.getFactory(Customer. class );
IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
Customer customer = (Customer)uctx.unmarshalDocument( new FileInputStream( " data.xml " ), null );
Person person = customer.person;
System.out.println( " cust-num: " + person.customerNumber);
System.out.println( " first-name: " + person.firstName);
System.out.println( " last-name: " + person.lastName);
System.out.println( " street: " + customer.street);
} catch (FileNotFoundException e){
System.out.println(e.toString());
} catch (JiBXException e){
System.out.println(e.toString());
}
}
}
緙栬瘧騫惰繍琛岃繖涓祴璇曠▼搴?nbsp;
#javac - classpath .:lib / jibx - run.jar Test.java
#java - cp .:lib / jibx - run.jar:lib / xpp3.jar Test
紼嬪簭榪愯鐨勭粨鏋滄槸
cust - num: 123456789
first - name:John
last - name:Smith
street: 12345 Happy Lane
]]>
Java Object 搴忓垪鍖栨垚XML浠ュ強XML鍙嶅簭鍒楀寲鎴怞ava Object http://www.tkk7.com/xiaodong0417/archive/2011/07/04/353665.html鐜嬫爲涓?/dc:creator>鐜嬫爲涓?/author>Mon, 04 Jul 2011 12:55:00 GMT http://www.tkk7.com/xiaodong0417/archive/2011/07/04/353665.html http://www.tkk7.com/xiaodong0417/comments/353665.html http://www.tkk7.com/xiaodong0417/archive/2011/07/04/353665.html#Feedback 0 http://www.tkk7.com/xiaodong0417/comments/commentRss/353665.html http://www.tkk7.com/xiaodong0417/services/trackbacks/353665.html package org.sl.bean;
import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
public class ObjectXmlSerial {
public static void main(String[] args) throws IOException{
UserBean user = new UserBean();
OtherUserInfoBean otherUserInfo = new OtherUserInfoBean();
otherUserInfo.setAddress("姹夊瓧");
otherUserInfo.setEmail("test@test.com");
user.setName("hello");
user.setPassword("world");
user.setOtherUserInfo(otherUserInfo);
ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
BufferedOutputStream bufferOut = new BufferedOutputStream(byteArrayOut);
writeObjectToXML(bufferOut, user);
byte[] bys = byteArrayOut.toByteArray();
byteArrayOut.close();
bufferOut.close();
ByteArrayInputStream byteArrayIn = new ByteArrayInputStream(bys);
BufferedInputStream bufferIn = new BufferedInputStream(byteArrayIn);
UserBean user1 = readObjectFromXML(bufferIn);
byteArrayIn.close();
bufferIn.close();
System.out.println(user1.getName());
System.out.println(user1.getOtherUserInfo().getAddress());
}
public static <T extends Serializable> void writeObjectToXML(OutputStream out, T obj){
XMLEncoder xmlEncoder = null;
try{