Java NIO.pdf

(3005 KB) Pobierz
Java NIO
99135051.001.png
Java™ NIO
Ron Hitchens
Publisher: O’Reilly
First Edition August 2002
ISBN: 0-596-00288-2, 312 pages
Java NIO explores the new I/O capabilities of version 1.4 in detail and shows you how to put
these features to work to greatly improve the efficiency of the Java code you write. This
compact volume examines the typical challenges that Java programmers face with I/O and
shows you how to take advantage of the capabilities of the new I/O features. You'll learn how
to put these tools to work using examples of common, real-world I/O problems and see how
the new features have a direct impact on responsiveness, scalability, and reliability.
Because the NIO APIs supplement the I/O features of version 1.3, rather than replace them,
you'll also learn when to use new APIs and when the older 1.3 I/O APIs are better suited to
your particular application.
Table of Contents
Dedication ............................................................................................................................. 1
Preface ................................................................................................................................... 2
Organization ....................................................................................................................... 3
Who Should Read This Book............................................................................................. 5
Software and Versions ....................................................................................................... 5
Conventions Used in This Book......................................................................................... 6
How to Contact Us ............................................................................................................. 7
Acknowledgments .............................................................................................................. 8
Chapter 1. Introduction ..................................................................................................... 10
1.1 I/O Versus CPU Time ................................................................................................ 10
1.2 No Longer CPU Bound .............................................................................................. 11
1.3 Getting to the Good Stuff ........................................................................................... 12
1.4 I/O Concepts............................................................................................................... 13
1.5 Summary .................................................................................................................... 21
Chapter 2. Buffers ..............................................................................................................22
2.1 Buffer Basics .............................................................................................................. 23
2.2 Creating Buffers ......................................................................................................... 36
2.3 Duplicating Buffers .................................................................................................... 38
2.4 Byte Buffers ............................................................................................................... 40
2.5 Summary .................................................................................................................... 52
Chapter 3. Channels........................................................................................................... 54
3.1 Channel Basics ........................................................................................................... 55
3.2 Scatter/Gather............................................................................................................. 62
3.3 File Channels.............................................................................................................. 67
3.4 Memory-Mapped Files ............................................................................................... 80
3.5 Socket Channels ......................................................................................................... 91
3.6 Pipes ......................................................................................................................... 109
3.7 The Channels Utility Class....................................................................................... 114
3.8 Summary .................................................................................................................. 115
Chapter 4. Selectors ......................................................................................................... 117
4.1 Selector Basics ......................................................................................................... 117
4.2 Using Selection Keys ............................................................................................... 125
4.3 Using Selectors......................................................................................................... 128
4.4 Asynchronous Closability ........................................................................................ 137
4.5 Selection Scaling ...................................................................................................... 138
4.6 Summary .................................................................................................................. 143
Chapter 5. Regular Expressions ..................................................................................... 145
5.1 Regular Expression Basics ....................................................................................... 145
5.2 The Java Regular Expression API............................................................................ 147
5.3 Regular Expression Methods of the String Class..................................................... 168
5.4 Java Regular Expression Syntax .............................................................................. 169
5.5 An Object-Oriented File Grep.................................................................................. 172
5.6 Summary .................................................................................................................. 178
Chapter 6. Character Sets ............................................................................................... 180
6.1 Character Set Basics................................................................................................. 180
6.2 Charsets .................................................................................................................... 182
6.3 The Charset Service Provider Interface ................................................................... 201
6.4 Summary .................................................................................................................. 214
Appendix A. NIO and the JNI......................................................................................... 215
Appendix B. Selectable Channels SPI ............................................................................ 217
Appendix C. NIO Quick Reference ................................................................................ 220
C.1 Package java.nio ...................................................................................................... 220
C.2 Package java.nio.channels ....................................................................................... 227
C.3 Package java.nio.channels.spi ................................................................................. 240
C.4 Package java.nio.charset.......................................................................................... 242
C.5 Package java.nio.charset.spi .................................................................................... 246
C.6 Package java.util.regex ............................................................................................ 246
Colophon ........................................................................................................................... 250
Java NIO
Dedication
To my wife, Karen.
What would I do without you?
1
Zgłoś jeśli naruszono regulamin