stephansun对《Pro Java 7 NIO.2》的笔记(5)

stephansun
stephansun (认真你就输了...)

读过 Pro Java 7 NIO.2

Pro Java 7 NIO.2
  • 书名: Pro Java 7 NIO.2
  • 作者: Anghel Leonard
  • 页数: 296
  • 出版社: Apress
  • 出版年: 2011-12-6
  • 第96页

    勘误:

    if ((ext.equalsIgnoreCase("txt")) 
    || (ext.equalsIgnoreCase("xml")
    || ext.equalsIgnoreCase("html"))
    || ext.equalsIgnoreCase("htm") 
    || ext.equalsIgnoreCase("xhtml")
    || ext.equalsIgnoreCase("rtf")) {
            searchInText(file);
    }

    应该改为:

    if ((ext.equalsIgnoreCase("txt")) 
    || (ext.equalsIgnoreCase("xml")                                      
    || ext.equalsIgnoreCase("html"))
    || ext.equalsIgnoreCase("htm") 
    || ext.equalsIgnoreCase("xhtml")
    || ext.equalsIgnoreCase("rtf")) {
            found = searchInText(file);
    }

    这个代码块的上下文还有几个if分支也需要加上`found =`

    2013-10-16 14:56:54 回应
  • 第154页
    Locking a Channel's File
    引自第154页

    这一节的例子有问题,我使用Groovy得不到书中描述的效果,还用线程实现也不能。 最后从网上把随书源代码下载下来,编译java文件,运行。还是不能出现书中描述的

    You should find that the second application can write into vamos.txt only after the lock is released, after 2 minutes.
    引自第154页

    坑爹

    2013-10-16 21:54:39 回应
  • 第165页
    FileChannel and Non-direct Buffer vs. FileChannel and Direct Buffer it seems that for buffers smaller than 256KB, the non-direct buffer is much faster, while for buffers larger than 256KB, the direct buffer is slightly faster. ... FileChannel.transferTo() vs. FileChannel.transferFrom() vs. FileChannel.map() it looks like transferTo() and transferFrom() are almost the same over seven consecutive runs, while FileChannel.map() is the slowest solution. ... The three different Files.copy()approaches the fastest Files.copy() method is Path to Path, followed by Path to OutputStream, and finally InputStream to Path. ... FileChannel and Non-direct Buffer vs. FileChannel.transferTo() vs. Path to Path Since we did not specify a buffer size for FileChannel.transferTo() and Path to Path we take as the reference the average time over the seven runs. As you can see, Files.copy() with Path to Path seams to be the fastest solution for copying a file. ...
    引自第165页
    2013-10-16 22:01:10 回应
  • 第225页

    发现在测试AsynchronousFileChannel的时候,用Groovy运行这一节的代码的结果完全跟书中描述的不一样。换用jdk7编译运行则跟书中结果一样。 Groovy对AsynchronousFileChannel的支持有BUG?

    2013-10-17 17:16:35 回应
  • 第216页
    In summary, I/O processing that is expected to take a large amount of time can be optimized by using asynchronous I/O. For relatively fast I/O opertions, synchronous I/O would be better because the overhead of processing kernel I/O requests and kernel signals may make asynchronous I/O less beneficial.
    引自第216页
    2014-07-14 10:03:57 回应