nio : Java Glossary

go to home page N words local find full screen, hide local find menu Google search web for more information on this topic jump to foot of page translate this page with Babelfish 2008-02-22 by Roedy Green ©1996-2009 Canadian Mind Products
index page for letter ⇒ punctuation 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z (all)
nio
Introduced in Java 1.4, the java.nio (new i/ o) package allows I/O more like that available in other lower level languages like C. You can memory map files. You can read and write blocks of data direct from disk, rather than byte by byte. It deals with the endian problem when you fish the data out of the buffer, not during the read. You can do non-blocking asynchronous I/O. You can lock files or parts of files. Regular I/O is based on stacking the methods you need in a rather verbose and highly assymetric way, in InputStream, Reader, BufferedReader. The nio design is cleaner, simpler and more efficient. You could do all your I/O with nio if you chose. Unfortunately, at this point the File I/O Amanuensis will not generate nio examples, however there some examples in the ByteBuffer entry.

Memory mapped files chew up huge amounts of virtual RAM and real RAM as well for the lookup tables and cached data, so they are not for routine use. They will mainly help random access especially when you have several threads accessing the same file. Don’t just assume they will improve performance. Further, they are limited by the address space. In a 32-bit JVM, you will be lucky if you can even handle a 1GB file window. Test both ways.

Direct buffers help primarily for bulk file operations, slewing through files doing little processing of the data or bulk copying. They are only for when you can allocate a mighty buffer at the start of the program and keep it till completion. Normal GC does not recover the unused direct buffers. Again, test both ways. Also be aware performance ratios will differ on different platforms.

Read and writing individual bytes goes through a lot of indirection, even though what you are trying to achieve is very simple. For Sun’s HotSpot you need to make sure that the method with your inner loop is very small. If it isn’t then the access code won’t be inlined and it will run very slowly.

Books

book cover recommend book⇒Java NIO
 paperback
ISBN13:978-0-596-00288-6impressioncounter
ISBN10:0-596-00288-2impressioncounter
publisher:O’Reilly recommended
published:2002-08-15
by:Ron Hitchens
Covers NIO (new I/O) that arrived with JDK 1.4.
UK flag abe books.co.uk abe books.ca Canadian flag
UK flag amazon.co.uk. amazon.ca. Canadian flag
German flag abe books.de chapters.indigo.ca. Canadian flag
German flag amazon.de. abe books.com American flag
French flag abe books.fr amazon.com. American flag
French flag amazon.fr. barnes and noble.com American flag
Italian flag abe books.it powells.com American flag
Spanish flag iberlibro.com download o’reilly safari American flag
abe books anz Australian flag

Learning More

Sun’s Javadoc on the nio overview class : available:
Sun’s JDK Technote Guide on nio examples : available:
Sun’s Javadoc on the CharSet class : available:
Sun’s Javadoc on the CharSetDecoder class : available:
Sun’s Javadoc on the ByteBuffer class : available:
Sun’s Javadoc on the MappedByteBuffer class : available:
Sun’s Javadoc on the CharBuffer class : available:
Sun’s Javadoc on the FileChannel class : available:
Sun’s Javadoc on the SocketChannel class : available:
Sun’s Javadoc on the Pipe class : available:

CMP homejump to top
CMP logo
feedback Please email your feedback for publication, errors, omissions, broken/redirected link reports
and suggestions to improve this page to Roedy Green : feedback email
made with CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[65.110.21.43]
Your face IP:[38.103.63.58]
You are visitor number 13,865.
You can get a fresh copy of this page from: or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror)
http://mindprod.com/jgloss/nio.html J:\mindprod\jgloss\nio.html