Ejemplo n.º 1
1
  private int bin_cmp(InputPort f1, InputPort f2) throws CoreException, IOException {
    BufferedInputStream is1 = new BufferedInputStream(f1.asInputStream(getSerializeOpts()));

    BufferedInputStream is2 = null;
    try {
      is2 = new BufferedInputStream(f2.asInputStream(getSerializeOpts()));

      int b = 0;
      int c;
      while ((c = readByte(is1)) >= 0) {
        int c2 = readByte(is2);
        if (c != c2) {
          if (!nopt) printErr("Differs at byte: " + b);

          return 1;
        }
        b++;
      }

      if (is2.read() != -1) {
        if (!nopt) printErr("Differs at byte: " + b);
        return 2;
      }
      return 0;

    } finally {
      is1.close();
      if (is2 != null) is2.close();
    }
  }
Ejemplo n.º 2
0
  private int xml_cmp(InputPort f1, InputPort f2)
      throws InvalidArgumentException, CoreException, XMLStreamException {

    /*
    XMLInputFactory inputFactory=XMLInputFactory.newInstance();


    inputFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.valueOf(true));
    inputFactory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.valueOf(false));
    inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.valueOf(false));
     */

    SerializeOpts opts = getSerializeOpts().clone();
    opts.setSupports_dtd(false);

    XMLEventReader xmlreader1 = f1.asXMLEventReader(opts);

    XMLEventReader xmlreader2 = f2.asXMLEventReader(opts);

    try {

      while (xmlreader1.hasNext() && xmlreader2.hasNext()) {

        XMLEvent e1 = xmlreader1.nextEvent();

        /*
         * DAL: Note: skip START_DOCUMENT tags on either e1 or e2
         * StAX only produdes START_DOCUMENT tags if there is an <?xml?> declaration
         * which doesnt change the logical meaning of the document wrt to comparison
         */
        if (e1.getEventType() == XMLStreamConstants.START_DOCUMENT && xmlreader1.hasNext())
          e1 = xmlreader1.nextEvent();
        XMLEvent e2 = xmlreader2.nextEvent();
        if (e2.getEventType() == XMLStreamConstants.START_DOCUMENT && xmlreader2.hasNext())
          e2 = xmlreader2.nextEvent();

        /*
         * If ignoring blanks then entirely skip any element which is charactors and entirely blank
         */
        if (bopt || copt || popt) {
          while (((bopt
                      && (e1.getEventType() == XMLStreamConstants.CHARACTERS)
                      && isBlank(e1.asCharacters()))
                  || (copt && e1.getEventType() == XMLStreamConstants.COMMENT)
                  || (popt && e1.getEventType() == XMLStreamConstants.PROCESSING_INSTRUCTION))
              && xmlreader1.hasNext()) e1 = xmlreader1.nextEvent();

          while (((bopt
                      && (e2.getEventType() == XMLStreamConstants.CHARACTERS)
                      && isBlank(e2.asCharacters()))
                  || (copt && e2.getEventType() == XMLStreamConstants.COMMENT)
                  || (popt && e2.getEventType() == XMLStreamConstants.PROCESSING_INSTRUCTION))
              && xmlreader2.hasNext()) e2 = xmlreader2.nextEvent();
        }

        if (!isEqual(e1, e2)) {
          Location loc = e1.getLocation();
          if (!nopt) printErr("xml diff at file1: " + loc.toString());

          return 2;
        }
      }
      return ((!xmlreader1.hasNext()) && (!xmlreader2.hasNext())) ? 0 : 1;
    } finally {
      try {
        xmlreader1.close();

      } finally {
      }
      try {
        xmlreader2.close();

      } finally {
      }
    }
  }