Saturday, June 28, 2008

Can't extend ByteBuffer

java.nio.ByteBuffer is not extensible and this really sucks badly. I didn't realize that till today when I thought to write a custom ByteBuffer implementation and then realized that all the constructors had only package visibility.

The thing is that there are many good reasons why you would want a custom implementation of ByteBuffer . Maybe you want to proxy over another ByteBuffer for example; have an optimized view over a larger ByteBuffer to reduce data copying.

It seems that I was not the only one to feel this way. Check out http://forum.java.sun.com/thread.jspa?threadID=693259&messageID=4028590

It appears that not just a few people, but also whole frameworks like Apache MINA have gone ahead and constructed their own ByteBuffer replacements. Check out http://mina.apache.org/report/1.1/apidocs/org/apache/mina/common/ByteBuffer.html which is extensible.

1 comment:

Anonymous said...

Hi Tarun,

I am Rajesh from SiliconIndia. I am also an avid blogger for a while now and participating actively in Indian blogosphere. I read your blog posting and found them very interesting and informative. We would love to see a copy of your blogs posted here, whenever you are posting it on blogger.com. Here are some of the benefits of posting your blogs here:

We have a strong community of 500,000 Indian professionals
Best blogs of 2008 to be published in a book "SiliconIndia bLoG PrinT"
Best blog to be printed in SliconIndia & SmartTechie magazines each month
Chance to be featured on homepage everyday


We appreciate your community initiative here and in helping build a more powerful India! Also, if you have any ideas or want to volunteer to help for SiliconIndia, we would be more than excited to get your help. Pls mail me back at rajesh@siliconindia.com with your suggestions and feedback.

Rajesh
Blog Editor- SiliconIndia
9886734775