Java Reference
In-Depth Information
System.out.printf("position = %2d Limit = %4d length =
%4d%n",
charBuf.position(),charBuf.limit(),charBuf.length());
buf.limit(2*charBuf.length());
// Set byte buffer
limit
System.out.println("Byte buffer after limit update:");
System.out.printf("position = %2d Limit = %4d length =
%4d%n",
buf.position(),buf.limit(),
buf.remaining());
channel.write(buf);
// Write buffer to the
channel
System.out.println("Buffer contents written to file.");
buf.clear();
charBuf.clear();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
UsingAFormatter.java
With this example I got the following output after the path for the file:
Char view buffer:
position = 0 Limit = 512 capacity = 512
View buffer after loading:
position = 41 Limit = 512 capacity = 512
View buffer after flip:
position = 0 Limit = 41 length = 41
Byte buffer after limit update:
position = 0 Limit = 82 length = 82
Buffer contents written to file.
View buffer after loading:
position = 58 Limit = 512 capacity = 512
View buffer after flip:
position = 0 Limit = 58 length = 58
Byte buffer after limit update:
position = 0 Limit = 116 length = 116
Buffer contents written to file.
View buffer after loading:
position = 66 Limit = 512 capacity = 512
View buffer after flip:
position = 0 Limit = 66 length = 66
Search WWH ::




Custom Search