2011年7月7日
# uname -a # 查看內(nèi)核/操作系統(tǒng)/CPU信息 # head -n 1 /etc/issue # 查看操作系統(tǒng)版本 # cat /proc/cpuinfo # 查看CPU信息 # hostname # 查看計(jì)算機(jī)名 # lspci -tv # 列出所有PCI設(shè)備 # lsusb -tv # 列出所有USB設(shè)備 # lsmod # 列出加載的內(nèi)核模塊 # env # 查看環(huán)境變量資源 # free -m # 查看內(nèi)存使用量和交換區(qū)使用量 # df -h # 查看各分區(qū)使用情況 # du -sh <目錄名> # 查看指定目錄的大小 # grep MemTotal /proc/meminfo # 查看內(nèi)存總量 # grep MemFree /proc/meminfo # 查看空閑內(nèi)存量 # uptime # 查看系統(tǒng)運(yùn)行時(shí)間、用戶數(shù)、負(fù)載 # cat /proc/loadavg # 查看系統(tǒng)負(fù)載磁盤和分區(qū) # mount | column -t # 查看掛接的分區(qū)狀態(tài) # fdisk -l # 查看所有分區(qū) # swapon -s # 查看所有交換分區(qū) # hdparm -i /dev/hda # 查看磁盤參數(shù)(僅適用于IDE設(shè)備) # dmesg | grep IDE # 查看啟動(dòng)時(shí)IDE設(shè)備檢測(cè)狀況網(wǎng)絡(luò) # ifconfig # 查看所有網(wǎng)絡(luò)接口的屬性 # iptables -L # 查看防火墻設(shè)置 # route -n # 查看路由表 # netstat -lntp # 查看所有監(jiān)聽端口 # netstat -antp # 查看所有已經(jīng)建立的連接 # netstat -s # 查看網(wǎng)絡(luò)統(tǒng)計(jì)信息進(jìn)程 # ps -ef # 查看所有進(jìn)程 # top # 實(shí)時(shí)顯示進(jìn)程狀態(tài)用戶 # w # 查看活動(dòng)用戶 # id <用戶名> # 查看指定用戶信息 # last # 查看用戶登錄日志 # cut -d: -f1 /etc/passwd # 查看系統(tǒng)所有用戶 # cut -d: -f1 /etc/group # 查看系統(tǒng)所有組 # crontab -l # 查看當(dāng)前用戶的計(jì)劃任務(wù)服務(wù) # chkconfig –list # 列出所有系統(tǒng)服務(wù) # chkconfig –list | grep on # 列出所有啟動(dòng)的系統(tǒng)服務(wù)程序 # rpm -qa # 查看所有安裝的軟件包
這篇文章清晰的講述了繼承, 實(shí)現(xiàn), 依賴, 關(guān)聯(lián),組合的概念及他們之間的關(guān)系,以下是原文內(nèi)容:
這是一堂關(guān)于UML基礎(chǔ)知識(shí)的補(bǔ)習(xí)課;現(xiàn)在我們做項(xiàng)目時(shí)間都太緊了,基本上都沒有做過真正的class級(jí)別的詳細(xì)設(shè)計(jì),更別提使用UML來實(shí)現(xiàn)規(guī)范建模了;本篇主要就以前自己一直感覺很迷糊的幾種class之間的關(guān)系進(jìn)行整理,讓我們?cè)谡嬲肬ML進(jìn)行比如類圖設(shè)計(jì)時(shí)能夠更加清晰明了;以下就分別介紹這幾種關(guān)系:
繼承
指的是一個(gè)類(稱為子類、子接口)繼承另外的一個(gè)類(稱為父類、父接口)的功能,并可以增加它自己的新功能的能力,繼承是類與類或者接口與接口之間最常見的關(guān)系;在Java中此類關(guān)系通過關(guān)鍵字extends明確標(biāo)識(shí),在設(shè)計(jì)時(shí)一般沒有爭(zhēng)議性;

實(shí)現(xiàn)
指的是一個(gè)class類實(shí)現(xiàn)interface接口(可以是多個(gè))的功能;實(shí)現(xiàn)是類與接口之間最常見的關(guān)系;在Java中此類關(guān)系通過關(guān)鍵字implements明確標(biāo)識(shí),在設(shè)計(jì)時(shí)一般沒有爭(zhēng)議性;

依賴
可以簡單的理解,就是一個(gè)類A使用到了另一個(gè)類B,而這種使用關(guān)系是具有偶然性的、、臨時(shí)性的、非常弱的,但是B類的變化會(huì)影響到A;比如某人要過河,需要借用一條船,此時(shí)人與船之間的關(guān)系就是依賴;表現(xiàn)在代碼層面,為類B作為參數(shù)被類A在某個(gè)method方法中使用;

關(guān)聯(lián)
他體現(xiàn)的是兩個(gè)類、或者類與接口之間語義級(jí)別的一種強(qiáng)依賴關(guān)系,比如我和我的朋友;這種關(guān)系比依賴更強(qiáng)、不存在依賴關(guān)系的偶然性、關(guān)系也不是臨時(shí)性的,一般是長期性的,而且雙方的關(guān)系一般是平等的、關(guān)聯(lián)可以是單向、雙向的;表現(xiàn)在代碼層面,為被關(guān)聯(lián)類B以類屬性的形式出現(xiàn)在關(guān)聯(lián)類A中,也可能是關(guān)聯(lián)類A引用了一個(gè)類型為被關(guān)聯(lián)類B的全局變量;

聚合
聚合是關(guān)聯(lián)關(guān)系的一種特例,他體現(xiàn)的是整體與部分、擁有的關(guān)系,即has-a的關(guān)系,此時(shí)整體與部分之間是可分離的,他們可以具有各自的生命周期,部分可以屬于多個(gè)整體對(duì)象,也可以為多個(gè)整體對(duì)象共享;比如計(jì)算機(jī)與CPU、公司與員工的關(guān)系等;表現(xiàn)在代碼層面,和關(guān)聯(lián)關(guān)系是一致的,只能從語義級(jí)別來區(qū)分;

組合
組合也是關(guān)聯(lián)關(guān)系的一種特例,他體現(xiàn)的是一種contains-a的關(guān)系,這種關(guān)系比聚合更強(qiáng),也稱為強(qiáng)聚合;他同樣體現(xiàn)整體與部分間的關(guān)系,但此時(shí)整體與部分是不可分的,整體的生命周期結(jié)束也就意味著部分的生命周期結(jié)束;比如你和你的大腦;表現(xiàn)在代碼層面,和關(guān)聯(lián)關(guān)系是一致的,只能從語義級(jí)別來區(qū)分;

對(duì)于繼承、實(shí)現(xiàn)這兩種關(guān)系沒多少疑問,他們體現(xiàn)的是一種類與類、或者類與接口間的縱向關(guān)系;其他的四者關(guān)系則體現(xiàn)的是類與類、或者類與接口間的引用、橫向關(guān)系,是比較難區(qū)分的,有很多事物間的關(guān)系要想準(zhǔn)確定位是很難的,前面也提到,這幾種關(guān)系都是語義級(jí)別的,所以從代碼層面并不能完全區(qū)分各種關(guān)系;但總的來說,后幾種關(guān)系所表現(xiàn)的強(qiáng)弱程度依次為:組合>聚合>關(guān)聯(lián)>依賴;
當(dāng)我們使用靜態(tài)的Scaffolding的時(shí)候, 我們經(jīng)常會(huì)用到一些自定義的validator, 那么我們?cè)鯓幼远x國際化的message呢?
或者說我們定義怎樣的一個(gè)key, Grails能查到它呢?
這里,用戶自定義Validator的key的pattern是:
[Class Name].[Property Name].validator.invalid
我們?cè)陂_發(fā)使時(shí)常會(huì)用到資源文件,這可能是為了多語言、國際化的需要,也可能是使用了國外開源項(xiàng)目的原因,這就需要中文轉(zhuǎn)ascii將中文轉(zhuǎn)換為ASCII 編碼,或者將 ASCII 轉(zhuǎn)換為中文,那么我們就可以使用 JDK 自帶的轉(zhuǎn)換工具 native2ascii 。
for example:
No1、中文轉(zhuǎn)換為 ASCII 編碼
步驟:1 、在 D 盤新建 chinese.txt 文件,內(nèi)容為:
parameter.project.title=這是中文
2、在環(huán)境變量中設(shè)置好 JDK 路徑
3、進(jìn)入 dos 控制臺(tái),并進(jìn)入 D 盤目錄
4、輸入命令: native2ascii -encoding gb2312 chinese.txt ascii.txt 回車
那么在D 盤目錄下生成 ascii.txt 文件,內(nèi)容為:
parameter.project.title=\u8fd9\u662f\u4e2d\u6ascii碼 中文587
No1、 ASCII 編碼轉(zhuǎn)換為中文
步驟:1 、在 D 盤新建 ascii.txt 文件,內(nèi)容為:
parameter.project.title=\u8fd9\u662f\u4e2d\u6ascii碼 中文587
2、在環(huán)境變量中設(shè)置好 JDK 路徑
3、進(jìn)入 dos 控制臺(tái),并進(jìn)入 D 盤目錄
4、輸入命令: native2ascii -reverse -encoding UTF8 ascii.txt chinese.txt 回車
那么在D 盤目錄下生成 chinese.txt 文件,內(nèi)容為:
parameter.project.title=這是中文
1. chkconfig腳本格式:
#!/bin/sh
#chkconfig 2345 55 45
#上面為固定格式:2345 表示運(yùn)行級(jí)別,55表示開機(jī)執(zhí)行順序,45為關(guān)機(jī)順序
#description:this is just a demo of chkconfig script
case “$1” in
start)
<start-script>
;;
Stop)
<stop-script>
;;
Status)
Echo <the information you want to display>
;;
*)
Echo “the usage of the script”
Case
2. 然后將腳本保存,并賦予執(zhí)行權(quán)限,再復(fù)制到/etc/init.d目錄
#chmod a+x <myscript>
#copy <myscript> /etc/init.d
3. 使用chkconfig命令添加成服務(wù)
#chkconfig --add <myscript>
#chkconfig --level 35 <myscript > on
#chkconfig --list <myscript>
4. 然后就可以通過service命令管理了
#service <myscript> start | stop | status
5. 下面是我寫的一個(gè)實(shí)例腳本,大家可以參考一些格式:
#!/bin/sh
#chkconfig: 2345 99 99
#description:the script to set the network at run level 2345
IN=eth0
OUT=eth1
HOST_NAME=cluster1.yang.com
INIP=192.168.10.10
OUTIP=192.168.136.10
MASK=255.255.255.0
IP=/sbin/ip
IFC=/sbin/ifconfig
ROUTE=/sbin/route
#flush the address
case "$1" in
start)
#echo "flush the address..."
#$IP addr flush dev eth0
#$IP addr flush dev eth1
echo "set the address..."
$IFC $IN $INIP netmask $MASK up
$IFC $OUT $OUTIP netmask $MASK up
echo "set the hostname..."
hostname $HOST_NAME
echo "set the default gateway..."
$IP route flush all
$ROUTE add default gw 192.168.136.2
echo "finshed!!!"
;;
stop)
echo "flush the network setting..."
$IP addr flush dev eth0
$IP addr flush dev eth1
echo "flush finshed!!!"
;;
status)
echo "hostname is $HOST_NAME"
$IFC eth0
$IFC eth1
;;
*)
echo "requires start,stop or status"
;;
esac
--------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------
在Linux中chkconfighttpd任務(wù)添加,Apache服務(wù)器的最新穩(wěn)定發(fā)布版本是httpd-2.2..0,官方下載地址是:http://httpd.apache.org/download.cgi。我們通過下面的步驟來快速的搭建一個(gè)web服務(wù)器。
1、下載源碼文件httpd-2.2.0.tar.gz 到linux服務(wù)器的某個(gè)目錄。
2、解壓文件 # tar zxvf httpd-2.2.0.tar.gz .
3、配置 # ./configure –refix=/usr/local/apache //指定安裝目錄,以后要?jiǎng)h除安裝就只需刪除這個(gè)目錄。
4、編譯和安裝。 # make ; make install .
5、編寫啟動(dòng)腳本,把它放到目錄 /etc/rc.d/init.d/里,這里取名為httpd,其內(nèi)容如下:
- #!/bin/bash
- #description:http server
- #chkconfig: 235 98 98
- case "$1" in
- start)
- echo "Starting Apache daemon..."
- /usr/local/apache2/bin/apachectl -k start
- ;;
- stop)
- echo "Stopping Apache daemon..."
- /usr/local/apache2/bin/apachectl -k stop
- ;;
- restart)
- echo "Restarting Apache daemon..."
- /usr/local/apache2/bin/apachectl -k restart
- ;;
- status)
- statusproc /usr/local/apache2/bin/httpd
- ;;
- *)
- echo "Usage: $0 {start|stop|restart|status}"
- exit 1
- ;;
- Esac
注意:#description:http server 這一行必須加上,否則在執(zhí)行命令
# chkconfig –add httpd
時(shí)會(huì)出現(xiàn)“service apache does not support chkconfig”的錯(cuò)誤報(bào)告。
#chkconfig: 2345 98 98 表示在執(zhí)行命令
# chkconfig –add httpd 時(shí)會(huì)在目錄 /etc/rc2.d/ 、/etc/rc3.d/ /etc/rc5.d 分別生成文件 S98httpd和 K98httpd。這個(gè)數(shù)字可以是別的。
6、執(zhí)行命令 # chkconfig –add httpd ,進(jìn)入目錄/etc/rc3.d/檢查是否生成文件 S98httpd及K98httpd.
7、啟動(dòng)服務(wù) # service httpd start .
關(guān)鍵詞final在Java中有多重用途,既可被用于instance變量、static變量
也可用于classes或methods,表示不允許客戶覆寫它們。
當(dāng)一個(gè)方法被聲明成final,在兩個(gè)領(lǐng)域中顯得有位重要:
- class設(shè)計(jì)
- 運(yùn)行期性能
在程序設(shè)計(jì)里,有時(shí)我們不希望我們的方法被重寫或覆蓋,final關(guān)鍵字保證了這一點(diǎn)。
final關(guān)鍵字是怎么影響性能的呢?
當(dāng)我們的方法被聲明成static,final和private, 此方法將成為Inlining(內(nèi)聯(lián)函數(shù))的候選者。此類方法可以在編譯期被靜態(tài)決議(staticallyresolved),而不需要?jiǎng)討B(tài)決議(dynamicResolution)。以方法本體(methodbody)替換方法調(diào)用(methodcall)會(huì)使代碼執(zhí)行速度更快。
將方法聲明為static、final和private會(huì)帶來一些缺點(diǎn):這樣的方法無法通過Subclassing(子類化)進(jìn)行擴(kuò)展。這就束縛了derived class通過class函數(shù)做事情的機(jī)會(huì)。inlined方法只有在被多次調(diào)用的情況下,才會(huì)獲得令人側(cè)目的性能提升。這是因?yàn)楫?dāng)一個(gè)方法被inline后,就不再需要負(fù)擔(dān)方法調(diào)用的額外開銷。因此,方法被調(diào)用愈多次,節(jié)省就愈多。
不過inlining也可能使你的代碼體積變大。如果這個(gè)方法有許多調(diào)用點(diǎn),.class文件的體積便會(huì)膨脹,這是因?yàn)樵局恍璐鎯?chǔ)一份的函數(shù)碼,由于inline而在所有調(diào)用點(diǎn)被復(fù)制了一份。
Java NIO 主要是Channel, SelectionKey, Selector 三個(gè)類之間的關(guān)系,下面的例子就是演示如果使用NIO來處理請(qǐng)求的:
/** *
*/
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);
}
}
There are 5 different steps or milestones in a
products lifecycle from beginning to release. These are:
Stage 1 - First Cycle -
QA Handoff/Acceptance - This is the milestone that determines if a
product is stable enough to be tested against. When a product reaches this stage, it is generally released to QA Testers to begin the testing stage of the produt.
Stage 2 - Alpha phase The product is still in QA review, but the testing scenarios are a little more destructive in nature, in an attempt to start shaking out most of the bugs in a product.
Stage 3 - Beta phase- the product is at a stability level that it can be released to select customers in the customer base for further testing in the 'real world'. This usually shakes out more bugs in a product.
Stage 4 - Release Candidate - This stage is towards the end of the cycle - The product has gone through its testing paces, and is being certified as ready for release.
Stage 5 - GA -The product is ready for the world!
Reference:
http://answers.yahoo.com/question/index?qid=1006020204792
@import url(http://m.tkk7.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
Q:Windows Server 2003 中尋找端口與進(jìn)程的關(guān)聯(lián) A:如果發(fā)現(xiàn)一些從沒見過的端口號(hào),你怎么分辯出該端口是不是木馬開放的端口?或者在進(jìn)程列表中發(fā)現(xiàn)陌生的進(jìn)程時(shí),是否想知道該進(jìn)程在你的系統(tǒng)中開了什么 端口? 一,根據(jù)進(jìn)程查端口號(hào)首先在開始菜單的“運(yùn)行”框中輸入“cmd.exe”進(jìn)入命令提示符窗口,先鍵入“tasklist”命令將列出系統(tǒng)正在運(yùn)行的進(jìn)程 列表,把你要查的進(jìn)程所對(duì)應(yīng)的“PID”號(hào)記下或復(fù)制。把進(jìn)程的PID好記下后,接下來就用這個(gè)PID號(hào)把該進(jìn)程所開的端口顯示出來了。在當(dāng)前的命令符下 繼續(xù)鍵入“netstat -ano | find 1140”命令,其中“netstat -ano”參數(shù)表示以數(shù)字形式顯示所有活動(dòng)的TCP連接以及計(jì)算機(jī)正在偵聽的TCP、UDP端口,并且顯示查找進(jìn)程ID(PID)號(hào);“|find 1140”表示查找進(jìn)程PID為“1140”的TCP連接以及TCP、UDP端口的偵聽情況(在實(shí)際應(yīng)用中,需要把你剛才記下或復(fù)制的PID號(hào)替換掉這里 的1140)。按“回車”鍵后,就會(huì)顯示出該進(jìn)程所開的端口號(hào)。 二,根據(jù)端口號(hào)查進(jìn)程 在命令提示符窗口中輸入“netstat -ano”命令,列出系統(tǒng)當(dāng)前的端口列表,該命令的作用已在上面提過了。-o參數(shù)的作用主要是顯示各端口對(duì)應(yīng)的進(jìn)程PID號(hào),現(xiàn)在把你要查的端口對(duì)應(yīng)的進(jìn) 程PID號(hào)記下或復(fù)制。然后在命令提示符下繼續(xù)輸入tasklist /fi“PID eq 788”(在實(shí)際應(yīng)用中,需要把你復(fù)制或記下的PID號(hào)替換掉這里的788),這行語句/fi參數(shù)表示在“tasklist”中篩選,而“ID eq 788”則是指定篩選的條件,按“回車”鍵后,就會(huì)顯示出端口對(duì)應(yīng)的進(jìn)程。 三,查出進(jìn)程對(duì)應(yīng)的程序 知道了端口和進(jìn)程的關(guān)聯(lián)后,如何再進(jìn)一步查出該進(jìn)程是那個(gè)軟件或程序的進(jìn)程呢?下面的操作就需要用到Windows2000(Server或 Professional版都可以)安裝光盤中的一個(gè)工具。首先在安裝光盤的“Support\Tools\”目錄下,用解壓軟件打開 “support.cab”壓縮包,找到“tlist.exe”文件,將此文件釋放到任一目錄,如“D:\Support”。然后在命令提示符窗口中切換 到此目錄,運(yùn)行“tlist.exe”命令,把要查的進(jìn)程對(duì)應(yīng)的PID號(hào)記下或復(fù)制(第一列就是進(jìn)程的PID號(hào)),然后繼續(xù)輸入“tlist.exe 2012”命令(你輸入的時(shí)候,需要將剛才記下的PID號(hào)替換掉這里的2012),“CmdLine:”后面顯示的就是該進(jìn)程對(duì)應(yīng)的軟件所在的目錄。除此 之外,返回信息中還列出了該進(jìn)程所調(diào)用的文件,得到了這些信息就可以很容易查出進(jìn)程對(duì)應(yīng)的程序了。假如想關(guān)閉某個(gè)進(jìn)程,可把該進(jìn)程的PID號(hào)記下,在命令 提示符下輸入“taskkill/pid 2400”(2400是PID號(hào))就可以將PID號(hào)為2400的進(jìn)程關(guān)閉,如果要強(qiáng)制關(guān)閉該進(jìn)程,只須在這條命令的后面加個(gè)“/f”參數(shù)即可。
來源:
http://www.cn6154.com/ask/question.php?id=2623
@import url(http://m.tkk7.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
1. Win+E - 顯示所有桌面,方便的左右選擇。
2. Alt+Ctrl+Left/Right Arrow -切換桌面
3. Alt+Ctrl+Shift+Left/Right Arrow – 移動(dòng)當(dāng)前窗口到其他桌面
4. Alt + Shift+ Up Arrow – 以很酷的方式顯示當(dāng)前窗口
5. Alt+F9/F10 – 最小化/最大化當(dāng)前窗口
6. Alt+F5 -不最大化當(dāng)前窗口
7. Alt+F7 – 激活當(dāng)前窗口的移動(dòng)選項(xiàng),你可以使用方向鍵移動(dòng)當(dāng)前窗口,甚至移動(dòng)到其他桌面。
8. Alt+F8 – 用方向鍵調(diào)整當(dāng)前窗口大小
9. Ctrl + Alt + D – 顯示桌面/恢復(fù)當(dāng)前窗口
10. Alt+ Tab – 切換窗口
Nautilus
11. Shift+Ctrl+N – 新建文件夾, 很有用
12. Alt + Enter – 查看選擇文件/文件夾的屬性,代替單擊右鍵選擇屬性
13. Ctrl + 1/2 – 改變文件夾視圖查看方式,圖標(biāo)視圖/列表視圖
14. Ctrl + W – 關(guān)閉當(dāng)前Nautilus窗口
15. Ctrl + Shift + W – 關(guān)閉所有Nautilus窗口
16. Ctrl+T – 在Nautilus中新建一個(gè)標(biāo)簽
17. Alt + Up/Down Arrow – 移動(dòng)到父文件夾/選擇的文件夾
18. Alt + Left/Right Arrow – 后退/前進(jìn)
19. Alt + Home -直接移動(dòng)到主文件夾
20. F9 – 開關(guān)顯示Nautilus側(cè)邊欄
21. Ctrl + H -開關(guān)顯示隱藏文件夾
22. Ctrl + Alt + L -鎖屏
23. Alt + F1 – 打開應(yīng)用程序菜單
24. Alt + F2 – 打開運(yùn)行應(yīng)用程序?qū)υ捒?/span>
25. Win + 鼠標(biāo)滾輪 – 放大/縮小屏幕
@import url(http://m.tkk7.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
首先從 JiBX 網(wǎng)站下載 JiBX,當(dāng)前最新版本是 beta 3。解開下載的 zip 文件,里面有一個(gè) lib 目錄,包含了 bcel.jar, jibx-bind.jar, jibx-extras.jar, jibx-run.jar, xpp3.jar 五個(gè) jar 文件。bcel.jar, jibx-bind.jar 只有在 binding compiler 的時(shí)候才用得到。jibx-extras.jar 是一個(gè)可選的工具包,里面有一些測(cè)試和驗(yàn)證的工具類。
1.定義一個(gè)我們將要處理 XML 文件,文件名為 data.xml,內(nèi)容如下:
<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>
這個(gè) XML 文件非常簡單,共有十個(gè)元素,沒有屬性。根元素 customer 有 person, street, city, state, zip, phone 六個(gè)子元素。其中元素 person 有 cust-num, first-name, last-name 三個(gè)子元素。
2.接著定義兩個(gè) Java 類 Customer 和 Person,也采用最簡單的方式,用對(duì)象的域值對(duì)應(yīng)元素,內(nèi)容如下:
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;
}
這個(gè)兩個(gè)類沒有任何方法,夠簡單吧!或許你已經(jīng)看出來了,Customer 類的七個(gè) field 對(duì)應(yīng)的是 XML 文件中 customer 元素的七個(gè)子元素。Person 類的三個(gè) field 對(duì)應(yīng)的是 person 元素的三個(gè)子元素。在 Person 類的 field 的名稱并不是和 person 元素的子元素名稱完全相等,這是遵守 Java 編程規(guī)范 field 命名的需要,雖然不相等,但這不重要,可以在綁定定義文擋中把它們一一對(duì)應(yīng)起來。
3.綁定定義文擋
綁定定義文擋是依據(jù)綁定定義規(guī)范將 XML 數(shù)據(jù)和 Java 對(duì)象綁定的 XML 文擋。文件名為 binding.xml,內(nèi)容如下:
binding.xml 文件中的 name 和 field 屬性分別將 XML 中的元素和 Java 對(duì)象中的 field 一一對(duì)應(yīng)并綁定起來。
<mapping name="customer" class="Customer">
mapping 元素的 name 和 class 屬性將 customer 根元素和 Customer 類綁定在一起。
<structure name="person" field="person">
public Person person;
上面兩行定義了 person 是 Customer 的 field,同時(shí)也把 person 元素和 person 類綁定在一起。
<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.執(zhí)行 Binding Compiler 過程
以下命令是在 Linux 下執(zhí)行,如果是 Windows 平臺(tái)請(qǐng)轉(zhuǎn)換成相應(yīng)的命令
#javac Person.java
#javac -classpath . Customer.java
#java -jar lib/jibx-bind.jar binding.xml
執(zhí)行完后,在當(dāng)前目錄多了四個(gè) class 文件,分別是 Person.class, Customer.class, JiBX_bindingCustomer_access.class, JiBX_bindingFactory.class。
5.執(zhí)行 binding runtime 過程
接著寫一個(gè)簡單的讀取 data.xml 測(cè)試程序 Test.java,內(nèi)容如下:
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());
}
}
}
編譯并運(yùn)行這個(gè)測(cè)試程序
#javac -classpath .:lib/jibx-run.jar Test.java
#java -cp .:lib/jibx-run.jar:lib/xpp3.jar Test
程序運(yùn)行的結(jié)果是
cust-num:123456789
first-name:John
last-name:Smith
street:12345 Happy Lane
@import url(http://m.tkk7.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
最近不知道Groovy在搞什么鬼, Eclipse在線插件的安裝總是有問題。
然后只能在網(wǎng)上找到插件的壓縮包,下載后再安裝就好了。步驟如下:
1. 下載groovy 插件的安裝包,鏈接:
For Eclipse 3.7:
http://dist.springsource.org/release/GRECLIPSE/e3.7/archive-2.5.1.xx-20110628-1600-e37.zip
For Eclipse 3.6:
http://dist.springsource.org/release/GRECLIPSE/e3.6/archive-2.5.1.xx-20110627-1300-e36.zip
2. 進(jìn)入eclipse安裝插件的頁面,點(diǎn)擊Add 添加新的插件,在彈出的對(duì)話框中選擇Archieve
然后選擇下載的壓縮文件,安裝就可以了。
@import url(http://m.tkk7.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
//使用Groovy 稍微改了下
import java.io.File;
import java.io.FileInputStream;
import java.util.zip.GZIPOutputStream
import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream
class Compress {
public static gzipFile(from,to) throws IOException{
def inFile = new FileInputStream(from);
def out = new GZIPOutputStream(new FileOutputStream(to));
byte[] buffer = new byte[4096];
def buffer_read = 0;
while((buffer_read = inFile.read(buffer)) != -1){
// out.write(buffer,0,buffer_read);//use '<<' replace
out << buffer;//use '<<' replace
}
inFile.close();
out.close();
}
public static zipDirectory(dir,zipFile){
File dire = new File(dir);
if(!dire.isDirectory()){
throw new IllegalArgumentException('Compress: not a directory:' + dir);
}
String[] entries = dire.list();
byte[] buffer = new byte[4096];
int bytes_read;
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFile));
entries.each{item ->
File f = new File(dire,item);
if(f.isDirectory()){
return ;
}
FileInputStream in_file = new FileInputStream(f);
ZipEntry entry = new ZipEntry(f.getPath());
out.putNextEntry (entry);
while((bytes_read = in_file.read(buffer)) != -1){
out << buffer;
}
in_file.close();
}
out.close();
}
static main(args) {
def from = args[0];
File from_file = new File(from);
def directory = from_file.isDirectory();
def to = '';
if(directory){
to = from + '.zip';
}else{
to = from + '.gz';
}
if((new File(to)).exists()){
println('Compress: won\'t overwrite existing file:' + to);
System.exit(0);
}
if(directory)
Compress.zipDirectory (from, to);
else
Compress.gzipFile from, to;
}
}
@import url(http://m.tkk7.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
執(zhí)行File.delete()時(shí)最好做一系列的驗(yàn)證。
import java.io.File;
public class Delete {
public Delete() {
// TODO Auto-generated constructor stub
}
/**
* @param args
*/
public static void main(String[] args) {
if(args.length != 1){
System.err.println("Usage:java Delete<file or directory>");
System.exit(0);
}
try{
delet1e(args[0]);
}catch(IllegalArgumentException e){
System.err.println(e.getMessage());
}
}
private static void delet1e(String fileName) {
File f = new File(fileName);
if(!f.exists())
fail("Delete:no such file or firectory:" + fileName);
if(!f.canWrite())
fail("Delete:write protected :" + fileName);
if(f.isDirectory()){
String[] files = f.list();
if(files.length > 0)
fail("Delete:directory not empty:" + fileName);
}
boolean success = f.delete();
if(!success)
fail("Delete: delete failed");
}
private static void fail(String msg)throws IllegalArgumentException {
// TODO Auto-generated method stub
throw new IllegalArgumentException(msg);
}
}