import
java.nio.*;
import
java.util.*;
import
java.io.IOException;
public
class
GFG {
public
static
void
main(String[] args)
{
try
{
char
[] cb1 = {
'x'
,
'y'
,
'z'
};
char
[] cb2 = {
'a'
,
'b'
,
'c'
,
'd'
,
'e'
};
CharBuffer charBuffer1
= CharBuffer.wrap(cb1);
CharBuffer charBuffer2
= CharBuffer.wrap(cb2);
System.out.println(
"CharBuffer Before operation is: "
+ Arrays.toString(
charBuffer1.array())
+
"\nTarget Charbuffer: "
+ Arrays.toString(
charBuffer2.array()));
CharBuffer readonlybuff
= charBuffer2.asReadOnlyBuffer();
int
value = charBuffer1.read(readonlybuff);
System.out.println(
"\nCharBuffer After operation is: "
+ Arrays.toString(
charBuffer1.array())
+
"\nTarget Charbuffer: "
+ Arrays.toString(
charBuffer2.array())
+
"\nno of value changed: "
+ value);
}
catch
(IOException e) {
System.out.println(
"\nan I/O error occurs"
);
System.out.println(
"Exception throws: "
+ e);
}
catch
(NullPointerException e) {
System.out.println(
"\ntarget charbuffer is null"
);
System.out.println(
"Exception throws: "
+ e);
}
catch
(ReadOnlyBufferException e) {
System.out.println(
"\ntarget is a read only buffer"
);
System.out.println(
"Exception throws: "
+ e);
}
}
}