title: StAX parsing from Java NIO channel
body: <p>I am attempting to receive a stream of XML events over a Java NIO channel. I am new to both NIO and StAX parsing, so I could very easily be overlooking something :)</p>
  
  <p>My search has led me to several SAX and StAX implementations, but they all seem to operate on InputStreams and InputSources--not NIO channels. The two closest attempts I have made have been to get the InputStream from the channel and create a PipedInputStream:</p>
  
  <pre><code>// method 1
  PipedOutputStream out = new PipedOutputStream();
  InputStream in = new PipedInputStream(out);
  PrintWriter writer = new PrintWriter(out);
  
  //method 2
  InputStream in = channel.socket().getInputStream()
  //method 3
  IputStream in = Channels.newInputStream(channel);
  </code></pre>
  
  <p>followed by:</p>
  
  <pre><code>XMLStreamReader xmlStreamReader = XMLInputFactory.newInstance()
          .createXMLStreamReader(in);
  //...
  </code></pre>
  
  <p>When the above code is used with method 1, it blocks on the createXMLStreamReader line. When methods 2/3 are used, they immediately throw IllegalBlockingModeException (I do understand why). Maybe a new approach is needed?</p>
  
  <p>My goal is to have a non-blocking server select => accept character data from a client => parse it to XML events using a specific encoding => forward that event object to another thread for processing => and return to the selecting.</p>
  
  <p>So am I overlooking something, or is there a better approach that can be used? If so what?</p>
  
  <p>Thanks!</p>