Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 0.59 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Java NIO advantages if there is a single client and complete object read is required
  2. // Reading from socket
  3. private SomeObject readObject() throws IOException, ClassNotFoundException {
  4.     Object object = oiStream.readObject();
  5.     if (object != null && object instanceof SomeObject) {
  6.         SomeObject someObject = (SomeObject) object;
  7.         return someObject;
  8.     }
  9.     return null;
  10. }
  11.  
  12.     // Writing to socket
  13.     public void writeToSocket(SomeObject someObject) throws IOException {
  14.     if (isSocketOpen()) {
  15.         ooStream.writeObject(someObject);
  16.         ooStream.flush();
  17.     }
  18. }