void MultipleAvroFileWriter::commit() {
  RMF_TRACE("Writing frame " << frame_.index);
  for (unsigned int i = 0; i < categories_.size(); ++i) {
    if (categories_[i].dirty) {
      if (!categories_[i].writer) {
        std::string name = get_category_dynamic_file_path(Category(i));
        try {
          categories_[i].writer.reset(
              new internal_avro::DataFileWriter<RMF_avro_backend::Data>(
                  name.c_str(), internal_avro::compileJsonSchemaFromString(
                                    data_deprecated_avro::data_json)));
        }
        catch (const std::exception& e) {
          RMF_THROW(Message(e.what()) << Component(name), IOException);
        }
      }
      // show(categories_[i].data);
      RMF_INTERNAL_CHECK(categories_[i].data.frame == frame_.index,
                         "Trying to write category that is at wrong frame.");
      categories_[i].writer->write(categories_[i].data);
      categories_[i].writer->flush();
    }
    categories_[i].data = RMF_avro_backend::Data();
    // go to the about to be added frame
    categories_[i].data.frame = frame_.index + 1;
  }
  for (unsigned int i = 0; i < static_categories_.size(); ++i) {
    if (static_categories_dirty_[i]) {
      std::string name = get_category_static_file_path(Category(i));
      try {
        internal_avro::DataFileWriter<RMF_avro_backend::Data> writer(
            name.c_str(), internal_avro::compileJsonSchemaFromString(
                              data_deprecated_avro::data_json));
        writer.write(static_categories_[i]);
        writer.flush();
      }
      catch (const std::exception& e) {
        RMF_THROW(Message(e.what()) << Component(name), IOException);
      }
      // std::cout << "Writing data for " << get_category_name(Category(i)) <<
      // std::endl;
      // show(static_categories_[i]);
      static_categories_dirty_[i] = false;
    }
  }
  RMF_COMMIT(File, file);
  RMF_COMMIT(Nodes, nodes);
  if (frames_dirty_) {
    if (!frame_writer_) {
      frame_writer_.reset(
          new internal_avro::DataFileWriter<RMF_avro_backend::Frame>(
              get_frames_file_path().c_str(),
              internal_avro::compileJsonSchemaFromString(
                  data_deprecated_avro::frame_json)));
    }
    frame_writer_->write(frame_);
    frames_dirty_ = false;
  }
}
Beispiel #2
0
BufferConstHandle read_buffer(std::string file_name) {
  std::ifstream szstr(file_name.c_str(),
                      std::ios::in | std::ios::binary | std::ios::ate);
  unsigned int size = szstr.tellg();
  std::ifstream in(file_name.c_str(), std::ios::in | std::ios::binary);
  boost::shared_ptr<std::vector<char> > data =
      boost::make_shared<std::vector<char> >(size);
  RMF_TRACE("Found buffer of size " << data->size());
  in.read(&(*data)[0], data->size());
  return BufferConstHandle(data);
}
FrameID MultipleAvroFileWriter::add_frame(std::string name, FrameType t) {
  unsigned int index = get_number_of_frames();
  RMF_TRACE("Adding frame " << index << " under " << get_loaded_frame());
  set_loaded_frame(FrameID(index));
  frame_.name = name;
  frame_.type = boost::lexical_cast<std::string>(FrameType(t));
  if (get_loaded_frame() != FrameID()) {
    unsigned int findex = get_loaded_frame().get_index();
    frame_.parents.push_back(findex);
  }
  frames_dirty_ = true;
  frame_.index = index;
  return FrameID(index);
}
Beispiel #4
0
void write_buffer(BufferConstHandle buffer, std::string file_name) {
  std::ofstream out(file_name.c_str(), std::ios::out | std::ios::binary);
  RMF_TRACE("Writing buffer of size " << buffer.get_buffer().size());
  const std::vector<char> &buf = buffer.get_buffer();
  out.write(&buf[0], buffer.get_buffer().size());
}