Exemplo n.º 1
0
  /**
   * Writes the SignedDoc to an output file and automatically calculates DataFile sizes and digests
   *
   * @param outputFile output file name
   * @throws SignedDocException for all errors
   */
  public void writeToStream(OutputStream os) throws SignedDocException {
    // TODO read DataFile elements from old file

    try {
      os.write(xmlHeader().getBytes());
      for (int i = 0; i < countDataFiles(); i++) {
        DataFile df = getDataFile(i);
        df.writeToFile(os);
        os.write("\n".getBytes());
      }
      for (int i = 0; i < countSignatures(); i++) {
        Signature sig = getSignature(i);
        os.write(sig.toXML());
        os.write("\n".getBytes());
      }
      os.write(xmlTrailer().getBytes());
    } catch (SignedDocException ex) {
      throw ex; // already handled
    } catch (Exception ex) {
      SignedDocException.handleException(ex, SignedDocException.ERR_WRITE_FILE);
    }
  }