Author(s): Elliotte Rusty Harold
Series: Java series (O'Reilly & Associates)
Edition: 1st ed
Publisher: O'Reilly
Year: 1999
Language: English
Pages: 479
City: Beijing ; Sebastopol
Cover......Page 1
Table of Contents......Page 3
Dedication......Page 7
Correcting Misconceptions......Page 8
Organization of the Book......Page 10
Versions......Page 15
Conventions Used in This Book......Page 16
Request for Comments......Page 18
Acknowledgments......Page 19
I: Basic I/O......Page 20
1.1 What Is a Stream?......Page 21
1.2 Numeric Data......Page 24
1.3 Character Data......Page 27
1.4 Readers and Writers......Page 31
1.5 The Ubiquitous IOException......Page 32
1.6 The Console: System.out, System.in, and System.err......Page 33
1.7 Security Checks on I/O......Page 39
2.2 Writing Bytes to Output Streams......Page 41
2.3 Writing Arrays of Bytes......Page 43
2.4 Flushing and Closing Output Streams......Page 44
2.5 Subclassing OutputStream......Page 45
2.6 A Graphical User Interface for Output Streams......Page 46
3.2 The read( ) Method......Page 49
3.3 Reading Chunks of Data from a Stream......Page 51
3.4 Counting the Available Bytes......Page 52
3.6 Closing Input Streams......Page 53
3.8 Subclassing InputStream......Page 54
3.9 An Efficient Stream Copier......Page 55
II: Data Sources......Page 57
4.1 Reading Files......Page 58
4.2 Writing Files......Page 60
4.3 File Viewer, Part 1......Page 63
5.1 URLs......Page 67
5.2 URL Connections......Page 69
5.3 Sockets......Page 72
5.4 Server Sockets......Page 75
5.5 URLViewer......Page 78
III: Filter Streams......Page 81
6.1 The Filter Stream Classes......Page 82
6.2 The Filter Stream Subclasses......Page 87
6.3 Buffered Streams......Page 88
6.4 PushbackInputStream......Page 90
6.5 Print Streams......Page 91
6.6 Multitarget Output Streams......Page 92
6.7 File Viewer, Part 2......Page 96
7.1 The Data Stream Classes......Page 103
7.2 Reading and Writing Integers......Page 105
7.3 Reading and Writing Floating-Point Numbers......Page 110
7.5 Reading Byte Arrays......Page 113
7.6 Reading and Writing Text......Page 114
7.8 Reading and Writing Little-Endian Numbers......Page 118
7.9 Thread Safety......Page 130
7.10 File Viewer, Part 3......Page 131
8.1 Sequence Input Streams......Page 138
8.2 Byte Array Streams......Page 139
8.3 Communicating Between Threads with Piped Streams......Page 142
9.1 Inflaters and Deflaters......Page 147
9.2 Compressing and Decompressing Streams......Page 159
9.3 Working with Zip Files......Page 166
9.4 Checksums......Page 179
9.5 JAR Files......Page 183
9.6 File Viewer, Part 4......Page 196
10.1 Hash Function Basics......Page 200
10.2 The MessageDigest Class......Page 202
10.3 Digest Streams......Page 210
10.4 Encryption Basics......Page 216
10.5 The Cipher Class......Page 219
10.6 Cipher Streams......Page 233
10.7 File Viewer, Part 5......Page 238
IV: Advanced and Miscellaneous Topics......Page 243
11.1 Reading and Writing Objects......Page 244
11.2 Object Streams......Page 245
11.3 How Object Serialization Works......Page 246
11.5 The Serializable Interface......Page 248
11.6 The ObjectInput and ObjectOutput Interfaces......Page 254
11.7 Versioning......Page 256
11.8 Customizing the Serialization Format......Page 258
11.9 Resolving Classes......Page 267
11.11 Validation......Page 268
11.12 Sealed Objects......Page 270
12.1 Understanding Files......Page 274
12.2 Directories and Paths......Page 281
12.3 The File Class......Page 287
12.4 Filename Filters......Page 306
12.5 File Filters......Page 307
12.6 File Descriptors......Page 308
12.7 Random-Access Files......Page 309
12.8 General Techniques for Cross-Platform File Access Code......Page 311
13.1 File Dialogs......Page 313
13.2 JFileChooser......Page 320
13.3 File Viewer, Part 6......Page 338
14.1 Unicode......Page 344
14.2 Displaying Unicode Text......Page 345
14.3 Unicode Escapes......Page 352
14.4 UTF-8......Page 353
14.5 The char Data Type......Page 355
14.6 Other Encodings......Page 363
14.7 Converting Between Byte Arrays and Strings......Page 364
15.1 The java.io.Writer Class......Page 367
15.2 The OutputStreamWriter Class......Page 368
15.3 The java.io.Reader Class......Page 370
15.4 The InputStreamReader Class......Page 372
15.5 Character Array Readers and Writers......Page 373
15.6 String Readers and Writers......Page 376
15.7 Reading and Writing Files......Page 379
15.8 Buffered Readers and Writers......Page 381
15.9 Print Writers......Page 385
15.10 Piped Readers and Writers......Page 387
15.11 Filtered Readers and Writers......Page 388
15.12 File Viewer Finis......Page 393
16.1 The Old Way......Page 402
16.2 Choosing a Locale......Page 404
16.3 Number Formats......Page 407
16.4 Specifying Width with FieldPosition......Page 415
16.5 Parsing Input......Page 419
16.6 Decimal Formats......Page 421
16.7 An Exponential Number Format......Page 430
17.1 The Architecture of the Java Communications API......Page 436
17.2 Identifying Ports......Page 437
17.3 Communicating with a Device on a Port......Page 444
17.4 Serial Ports......Page 450
17.5 Parallel Ports......Page 459
V: Appendixes......Page 465
A.2 Design Patterns......Page 466
A.4 Network Programming......Page 467
A.6 Encryption and Related Technology......Page 468
A.8 International Character Sets and Unicode......Page 469
A.10 Updates and Breaking News......Page 470
B. Character Sets......Page 472
Colophon......Page 479