|
The Java
I/O System
Creating a good input/output (I/O) system is one of the more difficult tasks for the language designer.
|
|
Tweak your IO performance for faster runtime
Although poor performance claims have plagued Java for some time, Java programs can run just as quickly as programs written in C and C++ if developers pay attention to performance issues throughout the development cycle.
|
|
Introduction to Java I/O
This tutorial is an overview of Java I/O and all the classes in the java.io package.
|
|
New I/O APIs
The new I/O (NIO) APIs introduced in v 1.4 provide new features and improved performance in the areas of buffer management, scalable network and file I/O, character-set support, and regular-expression matching
|
|
Getting started with new I/O (NIO)
The new input/output (NIO) library, introduced with JDK 1.4, provides high-speed, block-oriented I/O in standard Java code. This hands-on tutorial covers the NIO library in great detail, from the high-level concepts to under-the-hood programming detail. You'll learn about crucial I/O elements like buffers and channels, and examine how standard I/O works in the updated library.
|
|
Merlin brings nonblocking I/O to the Java platform
The Java technology platform is long overdue for a nonblocking I/O mechanism. Fortunately, Merlin (JDK 1.4) has a magic wand for almost every occasion, and unblocking blocked I/O is this magician's specialty. Software engineers Aruna Kalagnanam and Balu G introduce the nonblocking features of Merlin's new I/O package, java.nio (NIO), and employ a socket-programming example to show you just what NIO can do.
|
|
The Servlet API and NIO: Together at last
Think it's impossible to combine NIO and the Servlet API? Think again. In this article, Java developer Taylor Cowan shows you how to apply the producer/consumer model to consumer nonblocking I/O, thus easing the Servlet API into a whole new compatibility with NIO. In the process, you'll see what it takes to build an actual Servlet-based Web server that implements NIO; and you'll find out how that server stacks up against a standard Java I/O server (Tomcat 5.0) in an enterprise environment.
|
|
Selectors
In this chapter, we’ll explore selectors. Selectors provide the ability to do readiness
seletion, which enables multiplexed I/O. s described in Chapter 1, readiness selec-tion
and multiplexing make it possible for a single thread to efficiently manage many
I/O channels simultaneously. C/C++ coders have had the POSIX select( ) and/or
poll( ) system calls in their toolbox for many years. Most other operating systems
provide similar functionality. But readiness selection was never available to Java pro-grammers
until JDK 1.4. Programmers whose primary body of experience is in the
Java environment may not have encountered this I/O model before.
|
|
Wrestling with Java NIO
This column takes the XI project to the next step. Here, Benoît reports his findings with the new Java technology APIs -- in particular, the regular expression engine and the New I/O (also known as NIO). Although the XI is not yet operational, you get a glimpse of what it will look like soon.
|
|
Turning streams inside out, Part 1: Reading from an output stream
The Java I/O framework is, in general, extremely versatile. The same framework supports file access, network access, character conversion, compression, encryption and so forth.
|
|
Turning streams inside out, Part 2: Optimizing internal Java I/O
The Java I/O framework is, in general, extremely versatile. The same framework supports file access, network access, character conversion, compression, encryption and so forth.
|
|
The ins and outs of Merlin's new I/O buffers
A series of buffer classes underpins the Java 2 Platform Standard Edition's new I/O (NIO) packages. The classes' data containers form the foundation of other NIO operations like nonblocking reads over socket channels.
|
|
Java I/O
java.io is set of Objects that are an
abstraction for streaming system resources
such as files.
|
|
Programming with JavaI/O Streams
Most programs use data in one form or another, whether it is as input, output, or both. The sources of input and output can vary between a local file, a socket on the network, a database, variables in memory, or another program. Even the type of data can vary between objects, characters, multimedia, and others.
|
|
Lecture 2: Java IO Streams
Network programming is essentially Input/Output (I/O) programming.
|
|
Overview of Input and Output Streams
The java.io package contains two classes, InputStream and OutputStream, from which most of the other classes in the package derive.
|
|
Network Streams
From its first days, Java has had the network in mind, more so than any other common programming language. Java is the first programming language to provide as much support for network I/O as it does for file I/O, perhaps even more--Java's URL, URLConnection, Socket, and ServerSocket classes are all fertile sources of streams. The exact type of the stream used by a network connection is typically hidden inside the undocumented sun classes. Thus, network I/O relies primarily on the basic InputStream and OutputStream methods, which you can wrap with any higher-level stream that suits your needs: buffering, cryptography, compression, or whatever your application requires.
|
|
Java I/O Slides
|
|
Java 1.1 IO streams
At this point you might be scratching your head, wondering if there is another design for IO streams that could require more typing. Could someone have come up with an odder design?” Prepare yourself: Java 1.1 makes some significant modifications to the IO stream library.
|
|
Read and write data with Java's I/O streams
The Java input/output (I/O) facilities provide a simple, standardized API for reading and writing character and byte data from various data sources. In this article, we'll explore the I/O classes, interfaces, and operations provided by the Java platform. Let's start by taking a look at Java streams
|
|
Programming With Java's I/O Streams Part 1
Most programs use data in one form or another, whether it is as input, output, or both. The sources of input and output can vary between a local file, a socket on the network, a database, in memory, or another program. Even the type of data can vary between objects, characters, multimedia, and more.
|
|
Using Streams to Implement Pipes
The java.io package contains two classes, PipedInputStreamand PipedOutputStream, that implement the input and output components of a pipe. Pipes are used to channel the output from one program (or thread) into the input of another.
|
|
Using Streams to Read and Write Files
File streams are perhaps the easist streams to understand. Simply put, FileInputStream) represents an input (output) stream on a file that lives on the native file system. You can create a file stream from the filename, a Fileobject, or a FileDescriptorobject. Use file streams to read data from or write data to files on the file system.
|
|
Using Streams to Read and Write Memory Locations
Use ByteArrayInputStreamand ByteArrayOutputStreamto read and write 8-bit data. You create these streams on an existing byte array and then use the read() and write() methods to read from or write data to the array in memory.
|
|
Using Streams to Concatenate Files
The SequenceInputStreamcreates a single input stream from multiple input sources. This example program, Concatenate, uses SequenceInputStream to implement a concatenation utility that sequentially concatenates files together in the order they are listed on the command line.
|
|
Working with Filtered Streams
You attach a filtered stream to another stream to filter the data as it's read from or written to the original stream. The java.io package contains these filtered streams which are subclasses of either FilterInputStream or FilterOutputStream:
|
|
Using DataInputStream and DataOutputStream
This page shows you how to use the java.io DataInputStream and DataOutputStream classes. It features an example, DataIOTest, that reads and writes tabular data (invoices for Java merchandise).
|
|
Writing Your Own Filtered Streams
This page shows you how to implement your own filtered streams through an example that implements a matched pair of filtered input and output streams. Many thanks to David Connelly from the Java team for providing us with this example.
|
|
Working with Random Access Files
The input and output streams that you've been learning about so far in this lesson have been sequential access streams--streams whose contents must be read or written sequentially. While still incredibly useful, sequential access files are a consequence of sequential medium such as magnetic tape. Random access files, on the other hand, permit nonsequential, or random, access to the contents of a file.
|
|
Using Random Access Files
The RandomAccessFile class implements both the DataInput and DataOutput interfaces and therefore can be used for both reading and writing. RandomAccessFile is similar to FileInputStream and FileOutputStream in that you specify a file on the native file system to open when you create it.
|
|
Writing Filters for Random Access Files
Let's rewrite the example from Writing Your Own Filtered Streams so that it works on RandomAccessFiles. Because RandomAccessFile implements the DataInput and DataOutput interfaces, a side benefit is that the filtered stream will also work with other DataInput and DataOutput streams including some sequential access streams (such as DataInputStream and DataOutputStream).
|
|
Java IO Performance
BOTH client and server programs often use the java.io package. While this
package is designed with ease of use in mind, developers new to the platform
often make mistakes that can lead to poor I/O performance. Fortunately, a better
understanding of this package can lead to major improvements in I/O
performance.
|