orc::Buffer *HdfsInputStream::read(uint64_t offset, uint64_t length, orc::Buffer *buffer) { if(!configured_) { throw std::runtime_error("Need to configure first"); } if (buffer == NULL) { buffer = new HeapBuffer(length); } else if (buffer->getLength() < length) { delete buffer; buffer = new HeapBuffer(length); } //blockreader::BlockPtr block = hdfsBlockReader_.getBlock(offset, length); hdfsutils::HdfsBlockLocator locator; base::ConfigurationMap conf; conf["filename"] = url_; conf["hdfsConfigurationFile"] = hdfsConfigurationFile_; conf["fileStatCache"] = fileStatCache_; locator.configure(conf); BufferPtr block = locator.getBlock(offset, length); if(block->size() != length) { throw std::runtime_error("size mismatch"); } // TODO get rid of this copy memcpy(buffer->getStart(), block->data(), block->size()); return buffer; }
// Read a file (may be text or binary). inline BufferPtr read_binary(const std::string& filename, const boost::uint64_t max_size = 0, const unsigned int buffer_flags = 0) { std::ifstream ifs(filename.c_str(), std::ios::binary); if (!ifs) OPENVPN_THROW(open_file_error, "cannot open: " << filename); // get length of file ifs.seekg (0, std::ios::end); const std::streamsize length = ifs.tellg(); if (max_size && boost::uint64_t(length) > max_size) OPENVPN_THROW(file_too_large, "file too large [" << length << '/' << max_size << "]: " << filename); ifs.seekg (0, std::ios::beg); // allocate buffer BufferPtr b = new BufferAllocated(size_t(length), buffer_flags | BufferAllocated::ARRAY); // read data ifs.read((char *)b->data(), length); // check for errors if (ifs.gcount() != length) OPENVPN_THROW(open_file_error, "read length inconsistency: " << filename); if (!ifs) OPENVPN_THROW(open_file_error, "cannot read: " << filename); return b; }
void VBOMesh::bufferSubData(GLuint theBufferID, BufferPtr theData, int theOffset, int theNumberOfVertices, int theNumberOfCoords) { // std::cout << "vbo::bufferSubData" << std::endl; // XXX ??? theData.flip(); // Bind The Buffer glBindBuffer(GL_ARRAY_BUFFER, theBufferID); // Load The Data glBufferSubData(GL_ARRAY_BUFFER, theOffset, theNumberOfVertices * theNumberOfCoords * sizeof(float), theData->data()); }