Java NIO

Free Download

Authors:

Edition: 1st ed

ISBN: 9780596002886, 0596002882

Size: 1 MB (1475904 bytes)

Pages: 275/275

File format:

Language:

Publishing Year:

Category: Tags: , ,

Ron Hitchens9780596002886, 0596002882

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 :
Table of Content……Page 2
Dedication……Page 3
Preface……Page 4
Organization……Page 5
Who Should Read This Book……Page 7
Conventions Used in This Book……Page 8
Font Conventions……Page 9
How to Contact Us……Page 10
Acknowledgments……Page 11
Table?1-1. Throughput rate, processing versus I/O time……Page 13
1.2 No Longer CPU Bound……Page 14
1.3 Getting to the Good Stuff……Page 15
1.4.1 Buffer Handling……Page 16
Figure 1-1. Simplified I/O buffer handling……Page 17
Figure 1-3. Multiply mapped memory space……Page 18
Figure 1-5. Physical memory as a paging-area cache……Page 19
1.4.4 File I/O……Page 20
Figure 1-6. User memory mapped to filesystem pages……Page 22
Figure 1-7. Exclusive-lock request blocked by shared locks……Page 23
1.4.5 Stream I/O……Page 24
1.5 Summary……Page 25
Figure 2-1. The Buffer family tree……Page 26
2.1.1 Attributes……Page 27
2.1.2 Buffer API……Page 28
2.1.3 Accessing……Page 29
Figure 2-3. Buffer after five put()s……Page 30
Figure 2-5. Buffer after being flipped……Page 31
2.1.6 Draining……Page 32
Example 2-1. Filling and draining buffers……Page 33
Figure 2-7. Buffer after compaction……Page 34
Figure 2-8. A buffer with a mark set……Page 35
2.1.9 Comparing……Page 36
Figure 2-11. Two buffers considered to be unequal……Page 37
2.1.10 Bulk Moves……Page 38
2.2 Creating Buffers……Page 41
2.3 Duplicating Buffers……Page 44
Figure 2-13. Creating a slice buffer……Page 45
2.4 Byte Buffers……Page 46
Figure 2-14. Big-endian byte order……Page 48
Figure 2-15. Little-endian byte order……Page 49
2.4.2 Direct Buffers……Page 51
2.4.3 View Buffers……Page 52
Figure 2-16. A CharBuffer view of a ByteBuffer……Page 53
Example 2-2. Creating a char view of a ByteBuffer……Page 54
2.4.4 Data Element Views……Page 55
Figure 2-17. A ByteBuffer containing some data……Page 56
Example 2-3. Utility routines for getting/putting unsigned values……Page 57
2.5 Summary……Page 59
Figure 3-1. Channels act as conduits to I/O services……Page 61
3.1 Channel Basics……Page 62
3.1.2 Using Channels……Page 64
Figure 3-3. The ByteChannel interfaces……Page 65
Example 3-1. Copying data between channels……Page 66
3.1.3 Closing Channels……Page 68
3.2 Scatter/Gather……Page 70
Figure 3-4. Scatter/gather interfaces……Page 71
Figure 3-6. A scattering read using four buffers……Page 72
Example 3-2. Collecting many buffers in a gathering write……Page 73
3.3 File Channels……Page 75
Figure 3-7. FileChannel family tree……Page 76
Table?3-1. File I/O API comparison chart……Page 78
Figure 3-8. A disk file with two holes……Page 82
3.3.2 File Locking……Page 83
Example 3-3. Shared- and exclusive-lock interaction……Page 86
3.4 Memory-Mapped Files……Page 89
Example 3-4. Composing HTTP replies with mapped files and gathering writes……Page 94
Example 3-5. Three types of memory-mapped buffers……Page 96
3.4.1 Channel-to-Channel Transfers……Page 99
Example 3-6. File concatenation using channel transfer……Page 100
3.5 Socket Channels……Page 101
Figure 3-9. The socket channel family tree……Page 102
3.5.1 Nonblocking Mode……Page 103
3.5.2 ServerSocketChannel……Page 105
Example 3-7. A nonblocking accept() with ServerSocketChannel……Page 106
3.5.3 SocketChannel……Page 107
Example 3-8. Concurrent-connection establishment……Page 109
3.5.4 DatagramChannel……Page 111
Example 3-9. Time-service client using DatagramChannel……Page 115
Example 3-10. DatagramChannel time server……Page 119
Figure 3-10. The Pipe family tree……Page 121
Figure 3-11. A pipe is a pair of looped channels……Page 123
Example 3-11. Worker thread writing to a pipe……Page 124
Table?3-2. Summary of java.nio.channels.Channels utility methods……Page 126
3.8 Summary……Page 127
4.1 Selector Basics……Page 129
4.1.1 The Selector, SelectableChannel, and SelectionKey Classes……Page 131
Figure 4-1. Selection class family tree……Page 132
Figure 4-2. Relationships of the selection classes……Page 134
4.1.2 Setting Up Selectors……Page 136
4.2 Using Selection Keys……Page 138
4.3.1 The Selection Process……Page 142
4.3.2 Stopping the Selection Process……Page 145
4.3.3 Managing Selection Keys……Page 146
Example 4-1. Using select() to service multiple channels……Page 147
4.3.4 Concurrency……Page 151
4.5 Selection Scaling……Page 152
Example 4-2. Servicing channels with a thread pool……Page 153
4.6 Summary……Page 158
5.1 Regular Expression Basics……Page 160
5.2.1 The CharSequence Interface……Page 163
Example 5-1. CharSequence interface examples……Page 164
5.2.2 The Pattern Class……Page 165
Table?5-1. Flag values affecting regular expression compilation……Page 167
Table?5-2. Matrix of split() behavior……Page 169
Example 5-2. Splitting strings with Pattern……Page 170
Example 5-3. Split matrix styelsheet……Page 172
5.2.3 The Matcher Class……Page 173
Example 5-4. Simple file grep……Page 174
Example 5-5. Extracting matched expressions……Page 175
Figure 5-2. start(), end(), and group() values……Page 177
Table?5-3. Regular expression capture groups of A((B)(C(D)))……Page 178
Example 5-6. Regular expression replacement……Page 180
Example 5-7. Backslashes in regular expressions……Page 182
Example 5-8. Regular expression append/replace……Page 184
5.3 Regular Expression Methods of the String Class……Page 185
5.4 Java Regular Expression Syntax……Page 186
Table?5-7. Java regular expression syntax quick reference……Page 187
Example 5-9. Object-oriented grep……Page 190
5.6 Summary……Page 196
6.1 Character Set Basics……Page 198
Figure 6-1. Characters encoded as UTF-8……Page 199
Table?6-1. Required charsets……Page 200
Example 6-1. Encoding with the standard charsets……Page 201
Figure 6-2. The charset classes……Page 205
6.2.2 Comparing Charsets……Page 208
6.2.3 Charset Encoders……Page 209
6.2.3.1 The CoderResult class……Page 215
6.2.4 Charset Decoders……Page 217
Example 6-2. Charset decoding……Page 219
Table?6-4. Legal characters for charset names……Page 222
6.3.1 Creating Custom Charsets……Page 223
6.3.2 Providing Your Custom Charsets……Page 226
Example 6-3. The custom Rot13 charset……Page 229
Example 6-4. Custom charset provider……Page 233
6.4 Summary……Page 235
Appendix A. NIO and the JNI……Page 237
Appendix B. Selectable Channels SPI……Page 240
C.1.1 Buffer……Page 243
C.1.4 ByteBuffer……Page 244
C.1.5 ByteOrder……Page 245
C.1.6 CharBuffer……Page 246
C.1.8 FloatBuffer……Page 247
C.1.9 IntBuffer……Page 248
C.1.11 LongBuffer……Page 249
C.1.14 ShortBuffer……Page 250
C.2.2 AsynchronousCloseException……Page 251
C.2.6 Channels……Page 252
C.2.8 ClosedChannelException……Page 253
C.2.11 DatagramChannel……Page 254
C.2.12 FileChannel……Page 255
C.2.14 FileLockInterruptionException……Page 256
C.2.17 IllegalSelectorException……Page 257
C.2.21 NonWritableChannelException……Page 258
C.2.24 OverlappingFileLockException……Page 259
C.2.27 ScatteringByteChannel……Page 260
C.2.29 SelectionKey……Page 261
C.2.31 ServerSocketChannel……Page 262
C.2.33 UnresolvedAddressException……Page 263
C.3.1 AbstractInterruptibleChannel……Page 264
C.3.4 AbstractSelector……Page 265
C.4.1 CharacterCodingException……Page 266
C.4.3 CharsetDecoder……Page 267
C.4.4 CharsetEncoder……Page 268
C.4.7 CodingErrorAction……Page 269
C.4.10 UnmappableCharacterException……Page 270
C.6.1 Matcher……Page 271
C.6.2 Pattern……Page 272
Colophon……Page 273

Reviews

There are no reviews yet.

Be the first to review “Java NIO”
Shopping Cart
Scroll to Top