Package net.sf.robocode.serialization

Examples of net.sf.robocode.serialization.XmlWriter


    FileOutputStream fos = null;
    BufferedOutputStream bos = null;
    ZipOutputStream zos = null;
    ObjectOutputStream oos = null;
    OutputStreamWriter osw = null;
    XmlWriter xwr = null;

    FileInputStream fis = null;
    BufferedInputStream bis = null;
    ObjectInputStream ois = null;

    final boolean isbin = format == BattleRecordFormat.BINARY || format == BattleRecordFormat.BINARY_ZIP;
    final boolean isxml = format == BattleRecordFormat.XML || format == BattleRecordFormat.XML_ZIP;
    Calendar calendar = Calendar.getInstance();

    try {
      fos = new FileOutputStream(recordFilename);
      bos = new BufferedOutputStream(fos, 1024 * 1024);

      if (format == BattleRecordFormat.BINARY) {
        oos = new ObjectOutputStream(bos);
      } else if (format == BattleRecordFormat.BINARY_ZIP) {
        zos = new ZipOutputStream(bos);
        zos.putNextEntry(new ZipEntry(dateFormat.format(calendar.getTime()) + "-robocode.br"));
        oos = new ObjectOutputStream(zos);
      } else if (format == BattleRecordFormat.XML) {
        final Charset utf8 = Charset.forName("UTF-8");

        osw = new OutputStreamWriter(bos, utf8);
        xwr = new XmlWriter(osw, true);
      } else if (format == BattleRecordFormat.XML_ZIP) {
        final Charset utf8 = Charset.forName("UTF-8");

        zos = new ZipOutputStream(bos);
        zos.putNextEntry(new ZipEntry(dateFormat.format(calendar.getTime()) + "-robocode.xml"));

        osw = new OutputStreamWriter(zos, utf8);
        xwr = new XmlWriter(osw, false);
      }

      if (isbin) {
        oos.writeObject(recordInfo);
      } else if (isxml) {
        xwr.startDocument();
        xwr.startElement("record");
        xwr.writeAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
        if (options.shortAttributes) {
          xwr.writeAttribute("xsi:noNamespaceSchemaLocation", "battleRecordS.xsd");
        } else {
          xwr.writeAttribute("xsi:noNamespaceSchemaLocation", "battleRecord.xsd");
        }
        recordInfo.writeXml(xwr, options);
        xwr.startElement("turns");
      }

      if (recordInfo.turnsInRounds != null) {
        fis = new FileInputStream(tempFile);
        bis = new BufferedInputStream(fis, 1024 * 1024);
        ois = new ObjectInputStream(bis);

        for (int i = 0; i < recordInfo.turnsInRounds.length; i++) {
          if (recordInfo.turnsInRounds[i] > 0) {
            for (int j = 0; j <= recordInfo.turnsInRounds[i] - 1; j++) {
              try {
                TurnSnapshot turn = (TurnSnapshot) ois.readObject();

                if (j != turn.getTurn()) {
                  throw new Error("Something rotten");
                }

                if (isbin) {
                  turn.stripDetails(options);
                  oos.writeObject(turn);
                } else if (isxml) {
                  turn.writeXml(xwr, options);
                }
              } catch (ClassNotFoundException e) {
                logError(e);
              }
            }
            if (isbin) {
              oos.flush();
            } else if (isxml) {
              osw.flush();
            }
            bos.flush();
            fos.flush();
          }
        }
        if (isxml) {
          xwr.endElement(); // turns
          xwr.endElement(); // record
          osw.flush();
        }
      }

    } catch (IOException e) {
View Full Code Here


    if (paintSnapshot) {
      String text = null;

      if (lastSnapshot != null) {
        final StringWriter writer = new StringWriter();
        final XmlWriter xmlWriter = new XmlWriter(writer, true);

        try {
          ((IXmlSerializable) lastSnapshot).writeXml(xmlWriter, new SerializableOptions(false));
          writer.close();
        } catch (IOException e) {
View Full Code Here

TOP

Related Classes of net.sf.robocode.serialization.XmlWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.