Java I/O, NIO and NIO.2

By Jeff Friesen

Java I/O, NIO, and NIO.2 is a power-packed booklet that speeds up your mastery of Java's quite a few I/O APIs. during this e-book, you'll know about vintage I/O APIs (File, RandomAccessFile, the circulation sessions and similar kinds, and the reader/writer classes). subsequent, you'll know about NIO's buffer, channel, selector, standard expression, charset, and formatter APIs. ultimately, you'll notice NIO.2's choices when it comes to a better dossier approach interface, asynchronous I/O, and the finishing touch of socket channel functionality.

After analyzing and utilizing thi publication, you'll achieve the speeded up wisdom and ability point to truly construct purposes with effective facts entry, specifically for today's cloud computing streaming facts needs.

What you’ll learn
How to set permissions and extra with the vintage dossier class
How to construct a flat dossier database with RandomAccessFile
Get to understand the byte array, dossier, clear out, and other forms of streams
Master serialization and externalization
Discover personality streams and their linked writers/readers
Tour the buffer APIs
Work with channels to move buffers to and from I/O services
Find out approximately selectors and readiness selection
Master average expressions
Discover charsets and their organization with Java's String< class
Take benefit of the formatter API to create formatted output
How to customise the formatter API
Explore the enhanced dossier process interface
Discover asynchronous I/O and its organization with futures and final touch handlers
Encounter socket channel advancements, together with multicasting
Who this booklet is for
This publication is for these skilled with Java, past the basics.

Show description

Preview of Java I/O, NIO and NIO.2 PDF

Best Java books

Mastering Lambdas: Java Programming in a Multicore World (Oracle Press)

The Definitive consultant to Lambda Expressions gaining knowledge of Lambdas: Java Programming in a Multicore global describes how the lambda-related positive aspects of Java SE eight will permit Java to fulfill the demanding situations of next-generation parallel architectures. The booklet explains how one can write lambdas, and the way to take advantage of them in streams and in assortment processing, offering code examples all through.

Mastering JavaFX 8 Controls (Oracle Press)

Layout and set up High-Performance JavaFX Controls convey state of the art functions with visually lovely UIs. getting to know JavaFX eight Controls presents transparent directions, unique examples, and ready-to-use code samples. the way to paintings with the newest JavaFX APIs, configure UI parts, immediately generate FXML, construct state of the art controls, and successfully follow CSS styling.

Data Abstraction and Problem Solving with Java: Walls and Mirrors (3rd Edition)

The 3rd version of info Abstraction and challenge fixing with Java: partitions and Mirrors employs the analogies of partitions (data abstraction) and Mirrors (recursion) to coach Java programming layout recommendations, in a manner that starting scholars locate obtainable. The publication has a student-friendly pedagogical method that conscientiously money owed for the strengths and weaknesses of the Java language.

Java Software Solutions: Foundations of Program Design (7th Edition)

Java software program suggestions teaches a origin of programming thoughts to foster well-designed object-oriented software program. Heralded for its integration of small and massive lifelike examples, this world wide best-selling textual content emphasizes construction sturdy problem-solving and layout abilities to put in writing top of the range courses.

Extra resources for Java I/O, NIO and NIO.2

Show sample text content

Open(); ssc. socket(). bind(new InetSocketAddress(9999)); ssc. configureBlocking(false); String msg = "Local tackle: " + ssc. socket(). getLocalSocketAddress(); ByteBuffer buffer = ByteBuffer. wrap(msg. getBytes()); whereas (true) { approach. out. print(". "); SocketChannel sc = ssc. accept(); if (sc ! = null) { method. out. println(); procedure. out. println("Received connection from " + sc. socket(). getRemoteSocketAddress()); buffer. rewind(); sc. write(buffer); sc. close(); } else test { Thread. sleep(100); } 184 bankruptcy 7: Channels seize (InterruptedException ie) { assert fake; // won't ensue } } } } directory 7-7’s main() process first outputs a startup message after which obtains a server socket channel. carrying on with, it accesses the ServerSocket peer item and makes use of this item to bind the socket/channel to port 9999. subsequent, main() configures the server socket channel to be nonblocking and creates a byte buffer in keeping with a message that identifies the server socket channel’s neighborhood socket handle. main() now enters some time loop that again and again prints a unmarried interval personality to illustrate the channel’s nonblocking prestige and exams for an incoming connection. If a connection is detected, its SocketChannel example is used to procure the distant socket deal with, that's output to the traditional output move. The buffer is then rewound and its content material is written to the socket channel, that's then closed. besides the fact that, if a connection isn’t detected, main() sleeps for a fragment of a moment. assemble directory 7-7 as follows: javac ChannelServer. java Execute the next command line to begin the server: java ChannelServer you need to realize a beginning server... message by way of a transforming into series of classes around the display from left to correct. At this element, there’s not anything additional to monitor. Exploring Socket Channels SocketChannel is the main prevalent of the 3 socket channel periods and types a connection-oriented movement protocol (such as TCP/IP). This type comprises the next tools:  static SocketChannel open(): try to open a socket channel. If the channel can't be opened, IOException is thrown. bankruptcy 7: Channels  static SocketChannel open(InetSocketAddress remoteAddr): try and open a socket channel and attach it to remoteAddr. This comfort strategy works as though through invoking the open() strategy, invoking the connect() technique at the ensuing socket channel, passing it remoteAddr, after which returning that channel. this technique throws 5 diversified exceptions. It throws AsynchronousCloseException whilst one other thread closes this channel whereas the attach operation is in growth; ClosedByInterruptException while one other thread interrupts the present thread whereas the attach operation is in development, thereby last the channel and environment the present thread’s interrupt prestige; java. nio. channels. UnresolvedAddressException while the given distant handle isn’t absolutely resolved; java. nio. channels. UnsupportedAddressTypeException whilst the kind of the given distant tackle isn’t supported; and IOException while another I/O mistakes happens.

Download PDF sample

Rated 4.17 of 5 – based on 12 votes