adsense from aus

Tuesday, June 17, 2008

NIO file copying

public class FileUtils{
public static void copyFile(File in, File out)
throws IOException
{
FileChannel inChannel = new
FileInputStream(in).getChannel();
FileChannel outChannel = new
FileOutputStream(out).getChannel();
try {
inChannel.transferTo(0, inChannel.size(),
outChannel);
}
catch (IOException e) {
throw e;
}
finally {
if (inChannel != null) inChannel.close();
if (outChannel != null) outChannel.close();
}
}

public static void main(String args[]) throws IOException{
FileUtils.copyFile(new File(args[0]),new File(args[1]));
}
}



for larger file ( 64mb above )

try {
// magic number for Windows, 64Mb - 32Kb)
int maxCount = (64 * 1024 * 1024) - (32 * 1024);
long size = inChannel.size();
long position = 0;
while (position < size) {
position +=
inChannel.transferTo(position, maxCount, outChannel);
}

references:
1. http://www.javalobby.org/java/forums/t17036.html
2. http://www.rgagnon.com/javadetails/java-0064.html

books, I am going to read

这该死的青春
广州朝九晚五

Monday, June 9, 2008

牛奶的生产过程--残忍

  物质不灭,能量守恒,天上不会下牛奶。现在我们知道,我们喝的奶,都来自一种叫做奶牛的动物。那么,奶牛为什么会产奶呢?

  这个问题很多人不知道,我以前也比较含糊。现在我终于可以确认,奶牛之所以产奶,是因为它生小牛了。没有哪一种哺乳类动物的雌性个体会平白无故地天天从乳房里向外淌奶。那么,奶牛为什么会生小牛呢?因为它怀孕了。 

奶牛为什么怀孕呢?

  这个问题很多人都想当然地以为自己知道——其实是因为,它被人工受精了!

  进而,奶牛为什么会不断地产奶呢?

  因为它不断地生小牛。

  奶牛为什么不断地生小牛呢?

  因为它不断地怀孕。

  奶牛怎么会不断地怀孕呢?

  因为它不断地被人工受精。

  同肉类食品一样,我们现在饮用的牛奶,都来自于工厂化的养殖业,而不是来自传统的人畜共生的畜牧业。乳业流水线上的奶牛,可能一辈子都没见过公牛,却不停地生小牛,不停地被挤奶。

  甚至,在先进的乳业工厂里,奶牛根本看不到自己的孩子,小牛也见不到它们的母亲,一生下来就母子分离。一部分小母牛被人喂养成奶牛,重复她母亲的命运;一部分小牛被卖出去当肉牛饲养,这算是幸运的;还有一部分小牛,直接进了生化工厂,变成了各种血清、蛋白和酶!

Monday, June 2, 2008

货币战争

简介 · · · · · ·
  为什么你不知道美联储是私有的中央银行?
  为什么华尔街风险资本会选中希特勒作为“投资”对象?
  为什么美国总统遇刺的比例高于美军诺曼底登陆一线部队的伤亡率?
  自1694年英格兰银行成立以来的300年间,几乎每一场世界重大变故背后,都能看到国际金融资本势力的身影。他们通过左右一国的经济命脉掌握国家的政治命运,通过煽动政治事件、诱发经济危机,控制着世界财富的流向与分配。可以说,一部世界金融史,就是一部谋求主宰人类财富的阴谋史。
  通过描摹国际金融集团及其代言人在世界金融史上翻云覆雨的过程,本书揭示了对金钱的角逐如何主导着西方历史的发展与国家财富的分配,通过再现统治世界的精英俱乐部在政治与经济领域不断掀起金融战役的手段与结果,本书旨在告诫人们警惕潜在的金融打击,为迎接一场“不流血”的战争做好准备。
  随着中国金融的全面开放,国际银行家将大举深入中国的金融腹地。昨天发生在西方的故事,今天会在中国重演吗?

狂人加盟 蓝黑军团

(CNN) -- Italian champions Inter Milan appointed Jose Mourinho as their new coach on Monday in succession to Roberto Mancini.

今天, 我最欣赏的足球教练 Mourinho 加盟 我最喜欢的足球俱乐部。 盼望这一天很久了。

New Inter Era will come soon.

Mourinho:




Mancini:

Sunday, June 1, 2008

Java instance of subclass

class Base{
int x = 2;
int mmethod(){
return x;
}
}

class Subclass extends Base{
int x = 3;
int mmethod(){
return x;
}
}

public class test3{

public static void main(String[] args){
Base b = new Subclass();
System.out.println(b.x);
System.out.println(b.mmethod());
}
}




When you call an instance method, it is the type of the current object - i.e. the Subclass object - that it used to resolve the call. However, when you call a data member, it is the type of the reference - Base in you example - NOT the type of the current object that is used to resolve the call.

So, becuase you have declared the varibla eb as type Base, that classes data members will be called. Because the variable b holds a reference to an object that is of type Superclass, that - the Superclass object, methods will be called.

Hope that helps.

Here is the source code:

download