O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Java I/O, NIO and NIO.2

Book Description

Java I/O, NIO, and NIO.2 is a power-packed book that accelerates your mastery of Java's various I/O APIs. In this book, you'll learn about classic I/O APIs (File, RandomAccessFile, the stream classes and related types, and the reader/writer classes). Next, you'll learn about NIO's buffer, channel, selector, regular expression, charset, and formatter APIs. Finally, you'll discover NIO.2's offerings in terms of an improved file system interface, asynchronous I/O, and the completion of socket channel functionality.

After reading and using thi book, you'll gain the accelerated knowledge and skill level to really build applications with efficient data access, especially for today's cloud computing streaming data needs.

Table of Contents

  1. Cover
  2. Title
  3. Copyright
  4. Dedication
  5. Contents at a Glance
  6. Contents
  7. About the Author
  8. About the Technical Reviewers
  9. Acknowledgments
  10. Introduction
  11. Part I: Getting Started with I/O
    1. Chapter 1: I/O Basics and APIs
      1. Classic I/O
        1. File System Access and the File Class
        2. Accessing File Content via RandomAccessFile
        3. Streaming Data via Stream Classes
        4. JDK 1.1 and the Writer/Reader Classes
      2. NIO
        1. Buffers
        2. Channels
        3. Selectors
        4. Regular Expressions
        5. Charsets
        6. Formatter
      3. NIO.2
        1. Improved File System Interface
        2. Asynchronous I/O
        3. Completion of Socket Channel Functionality
      4. Summary
  12. Part II: Classic I/O APIs
    1. Chapter 2: File
      1. Constructing File Instances
      2. Learning About Stored Abstract Paths
      3. Learning About a Path’s File or Directory
      4. Listing File System Root Directories
      5. Obtaining Disk Space Information
      6. Listing Directories
      7. Creating/Modifying Files and Directories
      8. Setting and Getting Permissions
      9. Exploring Miscellaneous Capabilities
      10. Summary
    2. Chapter 3: RandomAccessFile
      1. Exploring RandomAccessFile
      2. Using RandomAccessFile
      3. Summary
    3. Chapter 4: Streams
      1. Stream Classes Overview
      2. Touring the Stream Classes
        1. OutputStream and InputStream
        2. ByteArrayOutputStream and ByteArrayInputStream
        3. FileOutputStream and FileInputStream
        4. PipedOutputStream and PipedInputStream
        5. FilterOutputStream and FilterInputStream
        6. BufferedOutputStream and BufferedInputStream
        7. DataOutputStream and DataInputStream
        8. Object Serialization and Deserialization
        9. PrintStream
      3. Revisiting Standard I/O
      4. Summary
    4. Chapter 5: Writers and Readers
      1. Writer and Reader Classes Overview
      2. Writer and Reader
      3. OutputStreamWriter and InputStreamReader
      4. FileWriter and FileReader
      5. BufferedWriter and BufferedReader
      6. Summary
  13. Part III: New I/O APIs
    1. Chapter 6: Buffers
      1. Introducing Buffers
      2. Buffer and its Children
      3. Buffers in Depth
        1. Buffer Creation
        2. Buffer Writing and Reading
        3. Flipping Buffers
        4. Marking Buffers
        5. Buffer Subclass Operations
        6. Byte Ordering
        7. Direct Byte Buffers
      4. Summary
    2. Chapter 7: Channels
      1. Introducing Channels
      2. Channel and Its Children
      3. Channels in Depth
        1. Scatter/Gather I/O
        2. File Channels
        3. Socket Channels
        4. Pipes
      4. Summary
    3. Chapter 8: Selectors
      1. Selector Fundamentals
      2. Selector Demonstration
      3. Summary
    4. Chapter 9: Regular Expressions
      1. Pattern, PatternSyntaxException, and Matcher
      2. Character Classes
      3. Capturing Groups
      4. Boundary Matchers and Zero-Length Matches
      5. Quantifiers
      6. Practical Regular Expressions
      7. Summary
    5. Chapter 10: Charsets
      1. A Brief Review of the Fundamentals
      2. Working with Charsets
      3. Charsets and the String Class
      4. Summary
    6. Chapter 11: Formatter
      1. Exploring Formatter
      2. Exploring Formattable and FormattableFlags
      3. Summary
  14. Part IV: More New I/O APIs
    1. Chapter 12: Improved File System Interface
      1. Architecting a Better File Class
        1. File Systems and File System Providers
      2. Locating Files with Paths
        1. Getting a Path and Accessing Its Name Elements
        2. Relative and Absolute Paths
        3. Normalization, Relativization, and Resolution
        4. Additional Capabilities
      3. Performing File System Tasks with Files
        1. Accessing File Stores
        2. Managing Attributes
        3. Managing Files and Directories
        4. Managing Symbolic and Hard Links
        5. Walking the File Tree
        6. Working with Additional Capabilities
      4. Using Path Matchers and Watch Services
        1. Matching Paths
        2. Watching Directories
      5. Summary
    2. Chapter 13: Asynchronous I/O
      1. Asynchronous I/O Overview
      2. Asynchronous File Channels
      3. Asynchronous Socket Channels
        1. AsynchronousServerSocketChannel
        2. AsynchronousSocketChannel
      4. Asynchronous Channel Groups
        1. What About AsynchronousFileChannel?
      5. Summary
    3. Chapter 14: Completion of Socket Channel Functionality
      1. Binding and Option Configuration
      2. Channel-Based Multicasting
      3. Summary
  15. Part V: Appendices
    1. Appendix A: Answers to Exercises
      1. Chapter 1: I/O Basics and APIs
      2. Chapter 2: File
      3. Chapter 3: RandomAccessFile
      4. Chapter 4: Streams
      5. Chapter 5: Writers and Readers
      6. Chapter 6: Buffers
      7. Chapter 7: Channels
      8. Chapter 8: Selectors
      9. Chapter 9: Regular Expressions
      10. Chapter 10: Charsets
      11. Chapter 11: Formatter
      12. Chapter 12: Improved File System Interface
      13. Chapter 13: Asynchronous I/O
      14. Chapter 14: Completion of Socket Channel Functionality
    2. Appendix B: Sockets and Network Interfaces
      1. Sockets
        1. Socket Addresses
        2. Socket Options
        3. Socket and ServerSocket
        4. DatagramSocket and MulticastSocket
      2. Network Interfaces
      3. Using Network Interfaces with Sockets
  16. Index