private static Document parseXmlFromBytebuffer(ByteBuffer buffer,ParseOptions options) throws XMPException {
  InputSource source=new InputSource(buffer.getByteStream());
  try {
    return parseInputSource(source);
  }
 catch (  XMPException e) {
    if (e.getErrorCode() == XMPError.BADXML || e.getErrorCode() == XMPError.BADSTREAM) {
      if (options.getAcceptLatin1()) {
        buffer=Latin1Converter.convert(buffer);
      }
      if (options.getFixControlChars()) {
        try {
          String encoding=buffer.getEncoding();
          Reader fixReader=new FixASCIIControlsReader(new InputStreamReader(buffer.getByteStream(),encoding));
          return parseInputSource(new InputSource(fixReader));
        }
 catch (        UnsupportedEncodingException e1) {
          throw new XMPException("Unsupported Encoding",XMPError.INTERNALFAILURE,e);
        }
      }
      source=new InputSource(buffer.getByteStream());
      return parseInputSource(source);
    }
 else {
      throw e;
    }
  }
}

private static Document parseXmlFromBytebuffer ( ByteBuffer buffer , ParseOptions options ) throws XMPException { InputSource source = new InputSource ( buffer . getByteStream ( ) ) ; try { return parseInputSource ( source ) ; } catch ( XMPException e ) { if ( e . getErrorCode ( ) == XMPError . BADXML || e . getErrorCode ( ) == XMPError . BADSTREAM ) { if ( options . getAcceptLatin1 ( ) ) { buffer = Latin1Converter . convert ( buffer ) ; } if ( options . getFixControlChars ( ) ) { try { String encoding = buffer . getEncoding ( ) ; Reader fixReader = new FixASCIIControlsReader ( new InputStreamReader ( buffer . getByteStream ( ) , encoding ) ) ; return parseInputSource ( new InputSource ( fixReader ) ) ; } catch ( UnsupportedEncodingException e1 ) { throw new XMPException ( "Unsupported Encoding" , XMPError . INTERNALFAILURE , e ) ; } } source = new InputSource ( buffer . getByteStream ( ) ) ; return parseInputSource ( source ) ; } else { throw e ; } } }
parses xml from a byte buffer , fixing the encoding ( latin - 1 to utf - 8 ) and illegal control character optionally .
