Пример #1
0
  public void entityFree(Entity entity) throws CommunicationException {
    String xmlEntity;
    this.checkConnection();

    try {
      xmlEntity = entitySerializer.serializeEntity(entity);
    } catch (TransformationException e) {
      throw new CommunicationException(e.getMessage());
    }
    this.jniEntityFree(xmlEntity);
    this.checkConnection();
  }
Пример #2
0
  @Override
  public synchronized int export(File file) throws CommonException {
    Topic top;
    TopicQoS qos;
    QoSSerializer ser;
    OutputStreamWriter fw = null;
    String xmlQos;
    Sample sample;
    SampleSerializer sampleSer;
    int i = 0;

    if (!file.exists()) {
      try {
        file.createNewFile();
      } catch (IOException e1) {
        throw new CommonException("Cannot create file.");
      }
    }
    if ((!file.canRead()) || !(file.canWrite())) {
      throw new CommonException("Cannot open file (insufficient rights).");
    }

    try {
      ser = DataTransformerFactory.getQoSSerializer(DataTransformerFactory.XML);
      sampleSer = DataTransformerFactory.getSampleSerializer(DataTransformerFactory.XML);

      fw = new OutputStreamWriter(new FileOutputStream(file, false), "UTF-8");
      top = this.getTopic();

      qos = (TopicQoS) top.getQoS();
      xmlQos = ser.serializeQoS(qos);

      fw.write("<splice_data><partitions>");
      String parts = this.getPartitions(reader);

      if (parts != null) {
        fw.write(parts);
      }
      fw.write("</partitions><topic><name>");
      fw.write(top.getName());
      fw.write("</name><typeName>");
      fw.write(top.getTypeName());
      fw.write("</typeName><keyList>");

      if (top.getKeyList() != null) {
        fw.write(top.getKeyList());
      }
      fw.write("</keyList><qos>");
      fw.write(xmlQos);
      fw.write("</qos><metadata>");
      fw.write(this.userDataModel.getUserDataType().toXML());
      fw.write("</metadata></topic><data>");

      do {
        sample = userDataModel.getDataAt(i);

        if (sample != null) {
          fw.write(sampleSer.serializeSample(sample));
        }
        i++;
      } while (sample != null);

      fw.write("</data></splice_data>");
      fw.flush();
      fw.close();
    } catch (FileNotFoundException e) {
      throw new CommonException(e.getMessage());
    } catch (IOException ie) {
      throw new CommonException(ie.getMessage());
    } catch (CMException ce) {
      throw new CommonException(ce.getMessage());
    } catch (TransformationException te) {
      throw new CommonException(te.getMessage());
    } finally {
      if (fw != null) {
        try {
          fw.close();
        } catch (IOException ie) {
          throw new CommonException(ie.getMessage());
        }
      }
    }
    return i - 1;
  }