Пример #1
0
  /**
   * Constructor StAXBuilder. This constructor is used if the parser is at the beginning
   * (START_DOCUMENT).
   *
   * @param ombuilderFactory
   * @param parser
   */
  protected StAXBuilder(OMFactory ombuilderFactory, XMLStreamReader parser) {
    omfactory = ombuilderFactory;

    // The getEncoding information is only available at the START_DOCUMENT event.
    charEncoding = parser.getEncoding();

    initParser(parser);
  }
Пример #2
0
  private Reader binaryInputStreamStreamToReader(ByteArrayOutputStream out) {

    try {
      // There's got to be an easier way to do this, but
      // I don't feel like coding up Appendix F of the XML Spec
      // myself, when there's a reusable way to do it, and we
      // can warn folks away from BINARY xml streams that have
      // to be parsed to determine the character encoding :P

      String encoding = "UTF-8";

      try {
        ByteArrayInputStream bIn = new ByteArrayInputStream(out.toByteArray());
        XMLStreamReader reader = this.inputFactory.createXMLStreamReader(bIn);

        int eventType = 0;

        while ((eventType = reader.next()) != XMLStreamReader.END_DOCUMENT) {
          if (eventType == XMLStreamReader.START_DOCUMENT) {
            String possibleEncoding = reader.getEncoding();

            if (possibleEncoding != null) {
              encoding = possibleEncoding;
            }

            break;
          }
        }
      } catch (Throwable t) {
        // ignore, dealt with later when the string can't be parsed
        // into valid XML
      }

      return new StringReader(new String(out.toByteArray(), encoding));
    } catch (UnsupportedEncodingException badEnc) {
      throw new RuntimeException(badEnc);
    }
  }
 public String getEncoding() {
   return streamReader.getEncoding();
 }
Пример #4
0
 public String getEncoding() {
   return reader.getEncoding();
 }