Forums Register Login

B&S: ByteBuffer, IntBuffer, putInt(), optional operation

+Pie Number of slices to send: Send
Hi all

Yes... I know yet another thread started by me.

I'm trying to put an int into a ByteBuffer instance. However, the putInt() methods in the ByteBuffer API are specified as "optional operation"s. In my google searches I've discovered this means they throw an UnsupportedOperationException at runtime if they are not supported.

I've enountered them somewhere else, but I can't remember where. Maybe something to do with Charsets. Anyway, I remember wherever I did see them, they came with an "isSupported()" method or some such thing.

I have two questions:

Is there any way to determine at runtime if any of the putInt() methods are supported without just trying it to see if it throws an exceptioni?

Under what conditions will these methods throw and not throw the UnsupportedOperationException?

I thought that you might only be definitely able to use putInt methods in an IntBuffer instance... but no! They are "optional operation"s there as well.

Any thoughts anyone?

Michal
[ September 04, 2004: Message edited by: Michal Charemza ]
+Pie Number of slices to send: Send
Ah!

I think i've found it. ReadOnlyBufferException is a subclass of UnsupportedOperationException, and so these will be thrown if the buffer is read only - and there is a method "isReadOnly()" to test this.

Maybe I could have spent just a little bit longer looking at the API before posting... oh well.

Michal
If you are using a rototiller, you are doing it wrong. Even on this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 627 times.
Similar Threads
Http Reader.read(CharBuffer) for Binary?
question about API info on Sun's website
ByteBuffer optional methods
Threads And Synchronization
FileChannel and thread safety
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 11:13:09.