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 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) ©1996-2009 2008-02-22 Roedy Green, Canadian Mind Products
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
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 sony e-books American flag
Australian flag abe books anz download o’reilly safari American flag

Learning More

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

CMP homejump to top You can get the freshest 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
CMP logofeedback Please email your feedback for publication, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email
mindprod.com IP:[65.110.21.43]
view BlogYour face IP:[38.107.191.107]
You are visitor number 14,657.