• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Michal Charemza
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Michal Charemza
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic