Encode and Decode in Java NIOUsing Java NIO API encode and decode operation can be perform from one Charset to another Charset. The two classes' CharsetEncoder and CharsetDecoder play an important role in encoding and decoding between the ByteBuffer and CharBuffer. The reactor keeps the track of arrived events and dispatches only when the handler is available. Let's see the architecture of encoding and decoding operation performed in reactor: CharsetEncoder in Java NIO CharsetEncoder is used for encoding the Unicode characters into the sequence of bytes. It also returns the CoderResult that provides the information of any error.CharsetDecoder in Java NIO CharsetDecoder is used for decoding the sequence of arrays or bytes into the Unicode characters. During decoding from ByteBuffer to CharBuffer, the CoderResult is obtained. The CoderResultCharset.newEncoder() in Java NIO In CharsetEncoder, Charset.newEncoder() is used for the creation of an object of Charset and then by the newEncoder() method, we can get an object of CharsetEncoder.Charset.newDecoder() in Java NIO In CharsetDecoder, Charset.newDecoder() is used for the creation of an object of Charset and then by the newDecoder() method, we can get an object of CharsetDecoderBasic Encode and Decode ExampleOutput: Next TopicFileLock in Java NIO Channels |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India