Class ByteBufferXMLReader

java.lang.Object
org.postgresql.pljava.internal.SyntheticXMLReader
org.postgresql.pljava.internal.ByteBufferXMLReader
All Implemented Interfaces:
XMLReader
Direct Known Subclasses:
VarlenaXMLRenderer

public abstract class ByteBufferXMLReader extends SyntheticXMLReader
Wrap a readable ByteBuffer as a SyntheticXMLReader.

An implementing class must provide a buffer() method that returns the ByteBuffer, and the method is responsible for knowing when the memory region windowed by the ByteBuffer is no longer to be accessed, and throwing an exception in that case (unless the class also overrides pin() and performs the check there instead).

The underlying buffer's position may be used to maintain the XML reader's position.

  • Constructor Details

    • ByteBufferXMLReader

      public ByteBufferXMLReader()
  • Method Details

    • pin

      protected abstract void pin() throws SQLException
      Pin resources as needed during a reading operation.

      The implementation is also responsible for tracking whether this instance has been closed, and throwing an exception if so.

      Throws:
      SQLException
    • unpin

      protected abstract void unpin()
      Unpin resources after a reading operation.
    • buffer

      protected abstract ByteBuffer buffer() throws SQLException
      Return the ByteBuffer being wrapped.

      All uses of the buffer in this class are preceded by pin() and followed by unpin().

      Throws:
      SQLException
    • next

      protected abstract SyntheticXMLReader.EventCarrier next(ByteBuffer buf)
      Return null if no more events available, or an EventCarrier that carries one or more.

      Start- and end-document events are supplied by the caller, and so should not be supplied here.

      The pin on the underlying state is held.

      Parameters:
      buf - The buffer to read from. Its position may be used to maintain input position.
      Returns:
      An SyntheticXMLReader.EventCarrier representing some XML parse events, null if none remain.
    • next

      This implementation invokes next(ByteBuffer) to get some more events.

      Specified by:
      next in class SyntheticXMLReader
      Returns:
      an SyntheticXMLReader.EventCarrier, or null if no more.
    • parse

      public void parse(InputSource input) throws IOException, SAXException
      Description copied from class: SyntheticXMLReader
      The only parse variant that the implementing class needs to supply.

      An implementation could do as little as ignoring its InputSource argument and calling the zero-argument super.parse().

      Specified by:
      parse in interface XMLReader
      Specified by:
      parse in class SyntheticXMLReader
      Throws:
      IOException
      SAXException