// static PassRefPtrWillBeRawPtr<Entry> DataTransferItemFileSystem::webkitGetAsEntry(ExecutionContext* executionContext, DataTransferItem& item) { if (!item.dataObjectItem()->isFilename()) return nullptr; // For dragged files getAsFile must be pretty lightweight. Blob* file = item.getAsFile().get(); // The clipboard may not be in a readable state. if (!file) return nullptr; ASSERT(file->isFile()); DraggedIsolatedFileSystem* filesystem = DraggedIsolatedFileSystem::from(item.clipboard()->dataObject().get()); DOMFileSystem* domFileSystem = filesystem ? filesystem->getDOMFileSystem(executionContext) : 0; if (!filesystem) { // IsolatedFileSystem may not be enabled. return nullptr; } ASSERT(domFileSystem); // The dropped entries are mapped as top-level entries in the isolated filesystem. String virtualPath = DOMFilePath::append("/", toFile(file)->name()); // FIXME: This involves synchronous file operation. Consider passing file type data when we dispatch drag event. FileMetadata metadata; if (!getFileMetadata(toFile(file)->path(), metadata)) return nullptr; if (metadata.type == FileMetadata::TypeDirectory) return DirectoryEntry::create(domFileSystem, virtualPath); return FileEntry::create(domFileSystem, virtualPath); }
V new_file_scope_env(V file, V env) { V sc = create_scope(); Scope* scope = toScope(sc); scope->is_func_scope = true; scope->is_error_handler = false; scope->parent = add_ref(toFile(file)->global); scope->func = NULL; scope->file = add_ref(file); scope->callname = NULL; scope->pc = toFile(file)->code - 1; scope->env = env; return sc; }
PassRefPtr<Blob> Blob::slice(long long start, long long end, const String& contentType) const { // When we slice a file for the first time, we obtain a snapshot of the file by capturing its current size and modification time. // The modification time will be used to verify if the file has been changed or not, when the underlying data are accessed. long long size; double modificationTime; if (isFile()) { // FIXME: This involves synchronous file operation. We need to figure out how to make it asynchronous. toFile(this)->captureSnapshot(size, modificationTime); } else { ASSERT(m_size != -1); size = m_size; } // Convert the negative value that is used to select from the end. if (start < 0) start = start + size; if (end < 0) end = end + size; // Clamp the range if it exceeds the size limit. if (start < 0) start = 0; if (end < 0) end = 0; if (start >= size) { start = 0; end = 0; } else if (end < start) end = start; else if (end > size) end = size; long long length = end - start; OwnPtr<BlobData> blobData = BlobData::create(); blobData->setContentType(Blob::normalizedContentType(contentType)); if (isFile()) { #if ENABLE(FILE_SYSTEM) if (!toFile(this)->fileSystemURL().isEmpty()) blobData->appendURL(toFile(this)->fileSystemURL(), start, length, modificationTime); else #endif blobData->appendFile(toFile(this)->path(), start, length, modificationTime); } else blobData->appendBlob(m_internalURL, start, length); return Blob::create(blobData.release(), length); }
bool BeaconLoader::sendBeacon(LocalFrame* frame, int allowance, const KURL& beaconURL, PassRefPtrWillBeRawPtr<Blob>& data, int& payloadLength) { ASSERT(data); unsigned long long entitySize = data->size(); if (allowance > 0 && static_cast<unsigned long long>(allowance) < entitySize) return false; ResourceRequest request(beaconURL); prepareRequest(frame, request); RefPtr<FormData> entityBody = FormData::create(); if (data->hasBackingFile()) entityBody->appendFile(toFile(data.get())->path()); else entityBody->appendBlob(data->uuid(), data->blobDataHandle()); request.setHTTPBody(entityBody.release()); AtomicString contentType; const String& blobType = data->type(); if (!blobType.isEmpty() && isValidContentType(blobType)) request.setHTTPContentType(AtomicString(contentType)); issueRequest(frame, request); payloadLength = entitySize; return true; }
void XMLHttpRequest::send(Blob* body, ExceptionCode& ec) { if (!initSend(ec)) return; if (m_method != "GET" && m_method != "HEAD" && m_url.protocolIsInHTTPFamily()) { const String& contentType = getRequestHeader("Content-Type"); if (contentType.isEmpty()) { const String& blobType = body->type(); if (!blobType.isEmpty() && isValidContentType(blobType)) setRequestHeaderInternal("Content-Type", blobType); else { // From FileAPI spec, whenever media type cannot be determined, empty string must be returned. setRequestHeaderInternal("Content-Type", ""); } } // FIXME: add support for uploading bundles. m_requestEntityBody = FormData::create(); if (body->isFile()) m_requestEntityBody->appendFile(toFile(body)->path()); #if ENABLE(BLOB) else m_requestEntityBody->appendBlob(body->url()); #endif } createRequest(ec); }
v8::Handle<v8::Object> wrap(Blob* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) { ASSERT(impl); if (impl->isFile()) return wrap(toFile(impl), creationContext, isolate); return V8Blob::createWrapper(impl, creationContext, isolate); }
/* Event handler for tool 'batch' */ ATerm batch_handler(int conn, ATerm term) { ATerm in, out; /* We need some temporary variables during matching */ int i0; char *s0; ATerm t0; if(ATmatch(term, "rec-eval(fromFile)")) { return fromFile(conn); } if(ATmatch(term, "rec-do(toFile(<str>,<int>))", &s0, &i0)) { toFile(conn, s0, i0); return NULL; } if(ATmatch(term, "rec-terminate(<term>)", &t0)) { rec_terminate(conn, t0); return NULL; } if(ATmatch(term, "rec-do(signature(<term>,<term>))", &in, &out)) { ATerm result = batch_checker(conn, in); if(!ATmatch(result, "[]")) ATfprintf(stderr, "warning: not in input signature:\n\t%\n\tl\n", result); return NULL; } ATerror("tool batch cannot handle term %t", term); return NULL; /* Silence the compiler */ }
void XMLHttpRequest::send(Blob* body, ExceptionState& exceptionState) { WTF_LOG(Network, "XMLHttpRequest %p send() Blob '%s'", this, body->uuid().utf8().data()); if (!initSend(exceptionState)) return; if (areMethodAndURLValidForSend()) { if (getRequestHeader("Content-Type").isEmpty()) { const String& blobType = body->type(); if (!blobType.isEmpty() && isValidContentType(blobType)) setRequestHeaderInternal("Content-Type", AtomicString(blobType)); else { // From FileAPI spec, whenever media type cannot be determined, empty string must be returned. setRequestHeaderInternal("Content-Type", ""); } } // FIXME: add support for uploading bundles. m_requestEntityBody = FormData::create(); if (body->hasBackingFile()) m_requestEntityBody->appendFile(toFile(body)->path()); else m_requestEntityBody->appendBlob(body->uuid(), body->blobDataHandle()); } createRequest(exceptionState); }
/*! * \brief Callback for burst messages * * This method is called automatically when the node receives a burst message. * It creates and publishes a CAT from this burst. * * \param b the received message */ void CatCreator::callback(const burst_calc::burst::ConstPtr& b) { if (is_init_) { // Write burst header to file if (save_to_file_) headerToFile(*b); // Create a new CAT burst_calc::cat cat; cat.header.stamp = b->header.stamp; cat.end = b->end; cat.channels = b->channels; for (unsigned int i = 0; i < b->dishes.size(); i++) { // Update offsets in case a new min voltage is encountered updateOffsets(b->dishes[i]); if (caExists(b->dishes[i])) { // A center of activity exists for this dish state: // Add CA to CAT, publish CA, and write CAT & burst to file burst_calc::ca ca = getCa(b->dishes[i]); cat.cas.push_back(ca); ca_pub_.publish(ca); if (save_to_file_) toFile(i, b->dishes[i], ca); } else { // No center of activity for this dish state: // Just write burst to file if (save_to_file_) toFile(i, b->dishes[i]); } } // Publish CAT cat_pub_.publish(cat); ROS_INFO("CAT of size %d created from burst of size %d", static_cast<int>(cat.cas.size()), static_cast<int>(b->dishes.size())); } else ROS_ERROR("Minimum voltages not initialized, skipping CAT creation"); }
Vector<String> DataObject::filenames() const { Vector<String> results; for (size_t i = 0; i < m_itemList.size(); ++i) { if (m_itemList[i]->isFilename()) results.append(toFile(m_itemList[i]->getAsFile())->path()); } return results; }
void Statistics::write_fault_data_to_file(void) { std::ofstream toFile("fault_data.txt", std::ios::trunc); toFile << "Fault Fraction: " << fault_fraction << "\n"; toFile << "Steps Before Fault: " << steps_before_fault << "\n"; toFile << "On Fault Count: " << on_fault_count << "\n"; toFile << "Off Fault Count: " << off_fault_count << "\n"; }
v8::Handle<v8::Value> toV8(Blob* impl, v8::Isolate* isolate) { if (!impl) return v8::Null(); if (impl->isFile()) return toV8(toFile(impl), isolate); return V8Blob::wrap(impl, isolate); }
void Matrix_To_File(SparseMatrix<double> mat, const char* filename) { ofstream toFile(filename); toFile.precision(10); for (int k=0; k < mat.outerSize(); ++k) { for (SparseMatrix<double>::InnerIterator it(mat,k); it; ++it) { toFile << (it.row()+1) << "\t" << (it.col()+1) << "\t" << it.value() <<"\n"; } } toFile.close(); }
bool ClientConfiguration::toFile(QString const& filename) const { QString backupString; QString backupPassword = generateRandomPassword(20); try { backupString = toBackup(backupPassword); } catch (InternalErrorException& iex) { LOGGER()->critical("Failed to create a Backup from Identity: {}", iex.what()); return false; } return toFile(filename, backupString, backupPassword); }
WebDragData DataObject::toWebDragData() { WebDragData data; data.initialize(); data.setModifierKeyState(m_modifiers); WebVector<WebDragData::Item> itemList(length()); for (size_t i = 0; i < length(); ++i) { DataObjectItem* originalItem = item(i); WebDragData::Item item; if (originalItem->kind() == DataObjectItem::StringKind) { item.storageType = WebDragData::Item::StorageTypeString; item.stringType = originalItem->type(); item.stringData = originalItem->getAsString(); } else if (originalItem->kind() == DataObjectItem::FileKind) { if (originalItem->sharedBuffer()) { item.storageType = WebDragData::Item::StorageTypeBinaryData; item.binaryData = originalItem->sharedBuffer(); } else if (originalItem->isFilename()) { Blob* blob = originalItem->getAsFile(); if (blob->isFile()) { File* file = toFile(blob); if (file->hasBackingFile()) { item.storageType = WebDragData::Item::StorageTypeFilename; item.filenameData = file->path(); item.displayNameData = file->name(); } else if (!file->fileSystemURL().isEmpty()) { item.storageType = WebDragData::Item::StorageTypeFileSystemFile; item.fileSystemURL = file->fileSystemURL(); item.fileSystemFileSize = file->size(); } else { // FIXME: support dragging constructed Files across renderers, see // http://crbug.com/394955 item.storageType = WebDragData::Item::StorageTypeString; item.stringType = "text/plain"; item.stringData = file->name(); } } else { ASSERT_NOT_REACHED(); } } else { ASSERT_NOT_REACHED(); } } else { ASSERT_NOT_REACHED(); } item.title = originalItem->title(); item.baseURL = originalItem->baseURL(); itemList[i] = item; } data.swapItems(itemList); return data; }
WSLUA_METAMETHOD File__tostring(lua_State* L) { /* Generates a string of debug info for the File object */ File f = toFile(L,1); if (!f) { lua_pushstring(L,"File pointer is NULL!"); } else { lua_pushfstring(L,"File expired=%s, handle=%s, is %s", f->expired? "true":"false", f->file? "<ptr>":"<NULL>", f->wdh? "writer":"reader"); } WSLUA_RETURN(1); /* String of debug information. */ }
/*! * \brief Constructeur de la classe Solution * * Cette fonction appelle l'heuristique de construction, et recopie * la solution dans un fichier "res.txt". * * \param instance : instance sur laquelle on travaille. */ Solution::Solution(Instance *instance) { _distParcourue = 0; _dateFin = 0; srand(time(0)); HeurisSaving(instance); computeDateDist(instance); toFile("../res.txt", instance); }
void MainWindow::ssave() { if(fileName.isEmpty()) { fileName = QFileDialog::getSaveFileName(this,"Save file"); lFileName->setText("FileName: " + fileName.section('/',-1)); } QFile file(fileName); if (file.open(QIODevice::WriteOnly)) { QTextStream toFile(&file); toFile << QString::number(lastResult) << "\n" << textEdit->toPlainText(); lFileName->setText("File Name: " + fileName.section('/',-1)); file.close(); } }
FileList* DataTransfer::files() const { FileList* files = FileList::create(); if (!canReadData()) return files; for (size_t i = 0; i < m_dataObject->length(); ++i) { if (m_dataObject->item(i)->kind() == DataObjectItem::FileKind) { Blob* blob = m_dataObject->item(i)->getAsFile(); if (blob && blob->isFile()) files->append(toFile(blob)); } } return files; }
void copyFileFromResources(QString from, QString to) { // copy a file from resources to the config dir if it does not exist there QFileInfo toFile(to); if(!toFile.exists()) { QFile newToFile(toFile.absoluteFilePath()); QResource res(from); if (newToFile.open(QIODevice::WriteOnly)) { newToFile.write( reinterpret_cast<const char*>(res.data()) ); newToFile.close(); } else { qFatal("failed to copy default config from resources"); } } }
PassRefPtrWillBeRawPtr<FileList> Clipboard::files() const { RefPtrWillBeRawPtr<FileList> files = FileList::create(); if (!canReadData()) return files.release(); for (size_t i = 0; i < m_dataObject->length(); ++i) { if (m_dataObject->item(i)->kind() == DataObjectItem::FileKind) { RefPtrWillBeRawPtr<Blob> blob = m_dataObject->item(i)->getAsFile(); if (blob && blob->isFile()) files->append(toFile(blob.get())); } } return files.release(); }
void Statistics::write_mass_l_distribution_to_file(void) { std::ofstream toFile("mass_l_distribution.txt", std::ios::trunc); toFile << mass_l_distribution.size() << "\n"; toFile << "Example Mass_l Distribution\n"; std::map<long int, long int>::iterator chem_level; for(chem_level = mass_l_distribution.begin(); chem_level != mass_l_distribution.end(); chem_level++) { toFile << chem_level->first << "\t" << chem_level->second << "\n"; } }
void Statistics::write_mass_r_distribution_to_file(void) { std::ofstream toFile("mass_r_distribution.txt", std::ios::trunc); toFile << mass_r_distribution.size() << "\n"; toFile << "Example Mass_r Distribution\n"; std::map<long int, long int>::iterator radius; for(radius = mass_r_distribution.begin(); radius != mass_r_distribution.end(); radius++) { toFile << radius->first << "\t" << radius->second << "\n"; } }
void Statistics::write_burst_distribution_to_file(void) { std::ofstream toFile("burst_distribution.txt", std::ios::trunc); toFile << burst_distribution.size() << "\n"; toFile << "Example Burst Distribution p_c = " << p_c << "\n"; std::map<long int, long int>::iterator size; for(size = burst_distribution.begin(); size != burst_distribution.end(); size++) { toFile << size->first << "\t" << size->second << "\n"; } }
int main(int argc, char **argv) { if(argc==2) { srand(time(NULL)); room maze[COLS][ROWS]; room (*ptr)[ROWS] = maze; init(ptr); dw(ptr, 0,0); toFile(ptr, argv[1]); return 0; } else { puts("NEED FILE PATH"); return 1; } }
void XMLHttpRequest::send(Blob* body, ExceptionCode& ec) { if (!initSend(ec)) return; if (m_method != "GET" && m_method != "HEAD" && m_url.protocolIsInHTTPFamily()) { // FIXME: Should we set a Content-Type if one is not set. // FIXME: add support for uploading bundles. m_requestEntityBody = FormData::create(); if (body->isFile()) m_requestEntityBody->appendFile(toFile(body)->path()); #if ENABLE(BLOB) else m_requestEntityBody->appendBlob(body->url()); #endif } createRequest(ec); }
bool LaunchPoint::updateIconPath(std::string newIconPath) { // strip off local file url if (newIconPath.compare(0, 7, localFileURI) == 0) { newIconPath.erase(0, 7); } QImage newIcon(qFromUtf8Stl(newIconPath)); if (newIcon.isNull()) { return false; } m_iconPath = newIconPath; // attempt to persist change toFile(); return true; }
JSValue* JSXMLHttpRequest::send(ExecState* exec, const ArgList& args) { ExceptionCode ec = 0; if (args.isEmpty()) impl()->send(ec); else { JSValue* val = args.at(exec, 0); if (val->isUndefinedOrNull()) impl()->send(ec); else if (val->isObject(&JSDocument::s_info)) impl()->send(toDocument(val), ec); else if (val->isObject(&JSFile::s_info)) impl()->send(toFile(val), ec); else impl()->send(val->toString(exec), ec); } setDOMException(exec, ec); return jsUndefined(); }
File* FormData::Entry::file() const { ASSERT(blob()); // The spec uses the passed filename when inserting entries into the list. // Here, we apply the filename (if present) as an override when extracting // entries. // FIXME: Consider applying the name during insertion. if (blob()->isFile()) { File* file = toFile(blob()); if (filename().isNull()) return file; return file->clone(filename()); } String filename = m_filename; if (filename.isNull()) filename = "blob"; return File::create(filename, currentTimeMS(), blob()->blobDataHandle()); }
bool Queue::save(const ssi_char_t *filepath, FILE *fp, void(*toFile) (const ssi_char_t *filepath, FILE *fp, void *x)) { fwrite(&_n, sizeof(int), 1, fp); fwrite(&_first, sizeof(int), 1, fp); fwrite(&_last, sizeof(int), 1, fp); fwrite(&_count, sizeof(int), 1, fp); STATE::List empty = STATE::EMPTY; STATE::List filled = STATE::FILLED; for (int i = 0; i < _n; i++) { if (_q[i]) { fwrite(&filled, sizeof(STATE::List), 1, fp); toFile(filepath, fp, _q[i]); } else { fwrite(&empty, sizeof(STATE::List), 1, fp); } } return true; }