Skip to content

Java NIO

February 2, 2011
tags:

——————————————————–
Java NIO : JSR 51 : JDK 1.4
——————————————————–
Packages:
java.nio.channels
java.nio
java.nio.charset
——————————————————–

1. limit is not the delta part but is the state variable that is equivalent to the capacity of the buffer at the start of the buffer creation.
2. when we do flip – the limit is set equal to current position and position is reset to 0. this is generally done after writing into buffer – i.e reading of data completion.
3. when we do clear – all data cleared from buffer and position set to 0 and the capacity is set to the limit.
4. After every get() operation the position value is incremented to show the next byte to read except for the op named – get(index) – this method does not change the position and bypasses the buffer accounting state variable changes. Similarly the put(index,byte) does not change the state of buffer accounting variables. All other put ops do change.

Buffer Types
Read only, direct buffer,memory mapped buffer.
– You can convert an existing buffer to read only buffer stating asReadOnlyBuffer. But You cannot convert a read-only buffer to a writable buffer.
– Direct buffer is for directly writing for native buffers for speed – check details?
– Memory mapped is mapping directly to the memory – using underlying os to map file or parts of file to the memory.


Slicing creates sub buffers that share the same underlying array – useful for abstraction operations to a sub set .You can use an existing byte array to be wrapped by a ByteBuffer class but then you would be also having directing access to data.

Question:
1. When something is read from channel into buffer – how much is actually read at one time – that is what is the definition of the “block”?
2/ When we are using the file input stream to get the channel – is not that actually using streams inherently to use channels? – Why this design of getting channels from stream – does block data actually use stream inside?

——————————————————–
Java NIO2: JSR 203
——————————————————–
Packages: java.nio.file, java.nio.file.spi
Permissions,metadata,copying, deletion , file change notification support provided
Directory/File filters , File system – walk the tree – recursive operations to be performed,
symbolic link manipulations, file comparisons, alert if file modified,
FileAttributes = basic, system specific implementations (chmod, chown etc..)
Classes :Path (file.toPath()), FileSystem, WatcherService
——————————————————-

Advertisements
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: