• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Writing objects over nio

 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how to convert a lets say a Person obj to ByteBuffer so one can send over a socketShannel and the reconstruct the Person object, im looking for a ObjectOutputstream/ObjectInputstream over nio ?
:roll:
 
Author
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ByteBuffers and channels deal only with arrays of bytes, they have no conception of things like ObjectStreams.
Sending a serialized object graph over an NIO channel is no different than sending any other chunk of bytes. You just need to obtain the bytes representing your serialized object and write it to the channel. Here are two ways to do so:

or

In the first case, you've got the encoded object graph in a ByteBuffer instance and could do other things with it if you like. The second uses a utility adapter class which will handle the conversion from stream to channel for you.
 
Rikard Qvarforth
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh many thanks i dident get that one could do chaining with nio this was nice because im after the non blockable read/write methods in nio. im doing a little server/client progg.so i thougth that it would be nice with nio thanks !
 
I once met a man from Nantucket. He had a tiny ad
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic