void windowManager::openNewImage() { const bool warnToSave = !originalImage_.isNull(); const QString file = ::getNewImageFileName(activeWindow(), warnToSave); if (!file.isEmpty()) { const QImage newImage(file); if (newImage.isNull()) { const QList<QByteArray> formats = QImageWriter::supportedImageFormats(); QString supportedTypes; for (QList<QByteArray>::const_iterator it = formats.begin(), end = formats.end(); it != end; ++it) { supportedTypes += (*it).data() + QString(", "); } supportedTypes.chop(2); const QString errorString = "Unable to load " + file + ";\nplease make sure " + "your image is one of the supported types:\n" + supportedTypes; QMessageBox::warning(NULL, "Image load failed", errorString); return; } QFile fileDevice(file); fileDevice.open(QIODevice::ReadOnly); QByteArray byteArray(fileDevice.readAll()); const QString imageName = QFileInfo(file).fileName(); reset(newImage, byteArray, imageName); setProjectVersion(programVersion_); ::showAndRaise(colorChooser_.window()); colorChooser_.window()->setNewImage(newImage); colorChooser_.window()->setWindowTitle(getWindowTitle()); startOriginalImageColorCount(); } }
/* * Class: org_mahu_proto_jnitest_nativewrapper_HelloJNI * Method: processDataClass * Signature: (Lorg/mahu/proto/jnitest/nativewrapper/DataClass;)V */ JNIEXPORT void JNICALL Java_org_mahu_proto_jnitest_nativewrapper_HelloJNI_processDataClass (JNIEnv *env, jobject obj, jobject dataClassObj) { printf("### Java_org_mahu_proto_jnitest_nativewrapper_HelloJNI_processDataClass\n"); JavaObject javaObjectDataClass(env,"org/mahu/proto/jnitest/nativewrapper/DataClass", dataClassObj); jboolean boolValue = javaObjectDataClass.getBoolean("getBooleanValue"); javaObjectDataClass.setBoolean("setBooleanValue",true); jint val = javaObjectDataClass.getInt("getIntValue"); if (boolValue) { printf("Method getIntValue() return: %i\n", val); } javaObjectDataClass.setInt("setIntValue",val*2); JavaStringIn str(env,javaObjectDataClass.getString("getStringValue")); std::ostringstream os; os << str.getString() << "-jni" << "\0"; javaObjectDataClass.setString("setStringValue", os.str()); jfloat f = javaObjectDataClass.getFloat("getFloatValue"); javaObjectDataClass.setFloat("setFloatValue",f * 3); jdouble d = javaObjectDataClass.getDouble("getDoubleValue"); javaObjectDataClass.setDouble("setDoubleValue",d/2); JByteArrayPtrIn byteArray(env, javaObjectDataClass.getBytes("getByteArrayValue")); if (byteArray.getNumberOfBytes()>0) { int nrOfBytes = byteArray.getNumberOfBytes()*2; jbyte buf[nrOfBytes]; javaObjectDataClass.setBytes("setByteArrayValue", buf, nrOfBytes); } }
JNIEXPORT void JNICALL Java_org_mahu_proto_jnitest_nativewrapper_HelloJNI_processDataClass1_a (JNIEnv *env, jobject obj, jobject dataClass1Obj) { printf("### Java_org_mahu_proto_jnitest_nativewrapper_HelloJNI_processDataClass1\n"); JavaObject javaObjectDataClass(env,"org/mahu/proto/jnitest/nativewrapper/DataClass1", dataClass1Obj); jboolean boolValue = javaObjectDataClass.getBooleanField("booleanValue"); javaObjectDataClass.setBooleanField("booleanValue",true); jint intValue = javaObjectDataClass.getIntField("intValue"); javaObjectDataClass.setIntField("intValue",intValue*2); JavaStringIn str(env,javaObjectDataClass.getStringField("stringValue")); std::ostringstream os; os << str.getString() << "-jni" << "\0"; javaObjectDataClass.setStringField("stringValue", os.str()); jfloat f = javaObjectDataClass.getFloatField("floatValue"); javaObjectDataClass.setFloatField("floatValue",f * 3); jdouble d = javaObjectDataClass.getDoubleField("doubleValue"); javaObjectDataClass.setDoubleField("doubleValue",d/2); JByteArrayPtrIn byteArray(env, javaObjectDataClass.getBytesField("byteArrayValue")); if (byteArray.getNumberOfBytes()>0) { int nrOfBytes = byteArray.getNumberOfBytes()*2; jbyte buf[nrOfBytes]; javaObjectDataClass.setBytesField("byteArrayValue", buf, nrOfBytes); } }
JNIEXPORT void JNICALL Java_org_mahu_proto_jnitest_nativewrapper_HelloJNI_processDataClass1_b (JNIEnv *env, jobject obj, jobject dataClass1Obj) { printf("### Java_org_mahu_proto_jnitest_nativewrapper_HelloJNI_processDataClass1\n"); MyDataClass1 dc1(env, *myMyDataClass1, dataClass1Obj); jboolean boolValue = dc1.booleanField.get(); dc1.booleanField.set(true); jint intValue = dc1.intField.get(); dc1.intField.set(intValue*2); // JavaStringIn str(env,javaObjectDataClass.getStringField("stringValue")); // std::ostringstream os; // os << str.getString() << "-jni" << "\0"; // javaObjectDataClass.setStringField("stringValue", os.str()); // jfloat f = javaObjectDataClass.getFloatField("floatValue"); // javaObjectDataClass.setFloatField("floatValue",f * 3); jdouble d = dc1.doubleField.get(); dc1.doubleField.set(d/2); JByteArrayPtrIn byteArray(env, dc1.byteArrayField.get()); if (byteArray.getNumberOfBytes()>0) { int nrOfBytes = byteArray.getNumberOfBytes()*2; jbyte buf[nrOfBytes]; dc1.byteArrayField.set(buf, nrOfBytes); } }
const byteArray X509Certificate::getFingerprint(const DigestAlgorithm algo) const { gnutls_digest_algorithm galgo; switch (algo) { case DIGEST_MD5: galgo = GNUTLS_DIG_MD5; break; default: case DIGEST_SHA1: galgo = GNUTLS_DIG_SHA; break; } size_t bufferSize = 0; gnutls_x509_crt_get_fingerprint (m_data->cert, galgo, NULL, &bufferSize); std::vector <byte_t> buffer(bufferSize); if (gnutls_x509_crt_get_fingerprint (m_data->cert, galgo, &buffer[0], &bufferSize) == 0) { byteArray res; res.insert(res.end(), &buffer[0], &buffer[0] + bufferSize); return res; } return byteArray(); }
SingleApplication::SingleApplication(int &argc, char *argv[], const QString uniqueKey) : QApplication(argc, argv) { sharedMemory.setKey(uniqueKey); if (sharedMemory.attach()) _isRunning = true; else { _isRunning = false; // attach data to shared memory. QByteArray byteArray("0"); // default value to note that no message is available. if (!sharedMemory.create(byteArray.size())) { qDebug("Unable to create single instance."); return; } sharedMemory.lock(); char *to = (char*)sharedMemory.data(); const char *from = byteArray.data(); memcpy(to, from, qMin(sharedMemory.size(), byteArray.size())); sharedMemory.unlock(); // start checking for messages of other instances. QTimer *timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(checkForMessage())); timer->start(1000); } }
vCardProperty vCardProperty::createAvatar(const std::vector<char>& iconData) { QByteArray byteArray(iconData.data(), iconData.size()); QString iconBase64 = QString::fromLatin1(byteArray.toBase64().data()); QString propertuName = VC_PHOTO + QString(";PNG")/*icon format*/ + ";ENCODING=BASE64"; return vCardProperty(propertuName, iconBase64); }
void CDevicePCR2500::write(QString &data) { QByteArray byteArray(data.toLocal8Bit()); log_t.dataSent += byteArray.size(); byteArray.append("\n"); tty.sendData(byteArray); }
void KHTMLPageCache::sendData() { if (d->delivery.isEmpty()) { d->deliveryActive = false; return; } KHTMLPageCacheDelivery *delivery = d->delivery.takeFirst(); assert(delivery); QByteArray byteArray(delivery->file->read(64 * 1024)); delivery->emitData(byteArray); //put back in queue if (delivery->file->atEnd()) { // done. delivery->file->close(); delivery->emitData(QByteArray()); // Empty array delete delivery; } else { d->delivery.append(delivery); } QTimer::singleShot(0, this, SLOT(sendData())); }
void SchannelContext::forwardDataToApplication(const void* pData, size_t dataSize) { SafeByteArray byteArray(dataSize); memcpy(&byteArray[0], pData, dataSize); onDataForApplication(byteArray); }
void KalSocket::sendPoints(int x, int y, int color) { QString data("draw\n" + QString::number(x) + " " + QString::number(y) + " " + QString::number(color) + "\n"); QByteArray byteArray(data.toAscii()); this->write(byteArray); }
jobject sockaddrToInetAddress(JNIEnv* env, const sockaddr_storage* ss, jint* port) { // Convert IPv4-mapped IPv6 addresses to IPv4 addresses. // The RI states "Java will never return an IPv4-mapped address". sockaddr_storage tmp; memset(&tmp, 0, sizeof(tmp)); const sockaddr_in6* sin6 = reinterpret_cast<const sockaddr_in6*>(ss); if (ss->ss_family == AF_INET6 && IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) { // Copy the IPv6 address into the temporary sockaddr_storage. memcpy(&tmp, ss, sizeof(tmp)); // Unmap it into an IPv4 address. sockaddr_in* sin = reinterpret_cast<sockaddr_in*>(&tmp); sin->sin_family = AF_INET; sin->sin_port = sin6->sin6_port; memcpy(&sin->sin_addr.s_addr, &sin6->sin6_addr.s6_addr[12], 4); // Fall through into the regular conversion using the unmapped address. ss = &tmp; } const void* rawAddress; size_t addressLength; int sin_port; int scope_id = 0; if (ss->ss_family == AF_INET) { const sockaddr_in* sin = reinterpret_cast<const sockaddr_in*>(ss); rawAddress = &sin->sin_addr.s_addr; addressLength = 4; sin_port = ntohs(sin->sin_port); } else if (ss->ss_family == AF_INET6) { const sockaddr_in6* sin6 = reinterpret_cast<const sockaddr_in6*>(ss); rawAddress = &sin6->sin6_addr.s6_addr; addressLength = 16; sin_port = ntohs(sin6->sin6_port); scope_id = sin6->sin6_scope_id; } else { // We can't throw SocketException. We aren't meant to see bad addresses, so seeing one // really does imply an internal error. jniThrowExceptionFmt(env, "java/lang/IllegalArgumentException", "sockaddrToInetAddress bad ss_family: %i", ss->ss_family); return NULL; } if (port != NULL) { *port = sin_port; } ScopedLocalRef<jbyteArray> byteArray(env, env->NewByteArray(addressLength)); if (byteArray.get() == NULL) { return NULL; } env->SetByteArrayRegion(byteArray.get(), 0, addressLength, reinterpret_cast<const jbyte*>(rawAddress)); static jmethodID getByAddressMethod = env->GetStaticMethodID(JniConstants::inetAddressClass, "getByAddress", "(Ljava/lang/String;[BI)Ljava/net/InetAddress;"); if (getByAddressMethod == NULL) { return NULL; } return env->CallStaticObjectMethod(JniConstants::inetAddressClass, getByAddressMethod, NULL, byteArray.get(), scope_id); }
StringCell* BytevectorCell::utf8ToString(World &world, SliceIndexType start, SliceIndexType end) { if (!adjustSlice(start, end, length())) { return nullptr; } if ((start == 0) && (end == length())) { // We can share our byte array return StringCell::withUtf8ByteArray(world, byteArray(), length()); } else { return StringCell::fromUtf8Data(world, &byteArray()->data()[start], end - start); } }
QString CMisc::getFileTemporary(const QString& strFile) { QString strMD5 = ""; QByteArray byteArray(strFile.toStdString().c_str()); QByteArray md5Data = QCryptographicHash::hash(byteArray, QCryptographicHash::Md5); strMD5.append(md5Data.toHex()); return strMD5; }
const byteArray X509Certificate::getSerialNumber() const { char serial[64]; size_t serialSize = sizeof(serial); gnutls_x509_crt_get_serial(m_data->cert, serial, &serialSize); return byteArray(serial, serial + serialSize); }
ByteArray TcpClient::read(std::size_t length) { ByteArray byteArray(length); std::size_t read = receive(&byteArray[0], byteArray.getCapacity()); byteArray.resize(read); return byteArray; }
void SchannelContext::sendDataOnNetwork(const void* pData, size_t dataSize) { if (dataSize > 0 && pData) { SafeByteArray byteArray(dataSize); memcpy(&byteArray[0], pData, dataSize); onDataForNetwork(byteArray); } }
/////////////////////////////////////////////////////////////////////////////// // Writes the code for this current node, that represents a symbol // // writes: [symbol] [nb bits] [count: # of symbol on stream] [ byte array ] // not that the byte array is padded. For example, // if the symbol contains 11 bits, 2 bytes will be written. bool HuffmanCode::writeCode(Stream& out)const { bool bOk = true; out.writeSymbol(symbol()); // Write the 1 byte symbol. out.writeByte(nbBits()); // Write the 1 byte code bit length. out.write((uint32_t)leaf()->count()); // Write the count of this bit if(bOk) bOk &= out.write(byteArray(), (size_t)nbByte()); return bOk; }
static void ExpatParser_appendBytes(JNIEnv* env, jobject object, jlong pointer, jbyteArray xml, jint byteOffset, jint byteCount) { ScopedByteArrayRO byteArray(env, xml); if (byteArray.get() == NULL) { return; } const char* bytes = reinterpret_cast<const char*>(byteArray.get()); append(env, object, pointer, bytes, byteOffset, byteCount, XML_FALSE); }
BytevectorCell* BytevectorCell::copy(World &world, SliceIndexType start, SliceIndexType end) const { if (!adjustSlice(start, end, length())) { return nullptr; } if ((start == 0) && (end == length())) { // We can do a copy-on-write here return BytevectorCell::withByteArray(world, byteArray()->ref(), length()); } const LengthType newLength = end - start; SharedByteArray *newByteArray = SharedByteArray::createInstance(newLength); memcpy(newByteArray->data(), &byteArray()->data()[start], newLength); return BytevectorCell::withByteArray(world, newByteArray, newLength); }
static void bytearray_ptr_ctor_snippet() { //! [3] QByteArray byteArray("abc"); QBuffer buffer(&byteArray); buffer.open(QIODevice::WriteOnly); buffer.seek(3); buffer.write("def", 3); buffer.close(); // byteArray == "abcdef" //! [3] }
QMimeData *BlockTreeWidget::mimeData(const QList<QTreeWidgetItem *> items) const { for (auto item : items) { auto b = dynamic_cast<BlockTreeWidgetItem *>(item); if (b == nullptr) continue; auto mimeData = new QMimeData(); std::ostringstream oss; b->getBlockDesc()->stringify(oss); QByteArray byteArray(oss.str().c_str(), oss.str().size()); mimeData->setData("text/json/pothos_block", byteArray); return mimeData; } return QTreeWidget::mimeData(items); }
void JsonReader::dumpToFile(std::vector<cvf::Vec3d>& points, QString filePath) { QFile file; file.setFileName(filePath); file.open(QIODevice::WriteOnly); for (size_t idx = 0; idx < points.size(); idx++) { cvf::Vec3d point = points[idx]; QString string; string.sprintf("(%0.10e, %0.10e, %0.10e)\n", point.x(), point.y(), point.z()); QByteArray byteArray(string.toAscii()); file.write(byteArray); } file.close(); }
bool SingleApplication::sendMessage(const QString &message) { if (!_isRunning) return false; QByteArray byteArray("1"); byteArray.append(message.toUtf8()); byteArray.append('\0'); // < should be as char here, not a string! sharedMemory.lock(); char *to = (char*)sharedMemory.data(); const char *from = byteArray.data(); memcpy(to, from, qMin(sharedMemory.size(), byteArray.size())); sharedMemory.unlock(); return true; }
void BlockTreeWidget::mouseMoveEvent(QMouseEvent *event) { if(!(event->buttons() & Qt::LeftButton)) { QTreeWidget::mouseMoveEvent(event); return; } if((event->pos() - _dragStartPos).manhattanLength() < QApplication::startDragDistance()) { QTreeWidget::mouseMoveEvent(event); return; } //get the block data auto blockItem = dynamic_cast<BlockTreeWidgetItem *>(itemAt(_dragStartPos)); if (not blockItem->getBlockDesc()) return; //create a block object to render the image auto draw = dynamic_cast<GraphEditorTabs *>(getObjectMap()["editorTabs"])->getCurrentGraphEditor()->getCurrentGraphDraw(); std::shared_ptr<GraphBlock> renderBlock(new GraphBlock(draw)); renderBlock->setBlockDesc(blockItem->getBlockDesc()); renderBlock->prerender(); //precalculate so we can get bounds const auto bounds = renderBlock->boundingRect(); //draw the block's preview onto a mini pixmap QPixmap pixmap(bounds.size().toSize()+QSize(2,2)); pixmap.fill(Qt::transparent); QPainter painter(&pixmap); painter.translate(-bounds.topLeft()+QPoint(1,1)); //painter.scale(zoomScale, zoomScale); //TODO get zoomscale from draw painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::HighQualityAntialiasing); painter.setRenderHint(QPainter::SmoothPixmapTransform); renderBlock->render(painter); renderBlock.reset(); painter.end(); //create the drag object auto mimeData = new QMimeData(); std::ostringstream oss; blockItem->getBlockDesc()->stringify(oss); QByteArray byteArray(oss.str().c_str(), oss.str().size()); mimeData->setData("text/json/pothos_block", byteArray); auto drag = new QDrag(this); drag->setMimeData(mimeData); drag->setPixmap(pixmap); drag->setHotSpot(-bounds.topLeft().toPoint()); drag->exec(Qt::CopyAction | Qt::MoveAction); }
void ArrayTest::testByteArray() { valarray<uint8_t> byteArray(2); shared_ptr<Array<double> > array = Array<double>::newArray(byteArray, 1.0, 0.0); CPPUNIT_ASSERT(array->size() == 2); CPPUNIT_ASSERT(array->get(0) == 0.0); CPPUNIT_ASSERT(array->get(1) == 0.0); CPPUNIT_ASSERT(array->getScaleFactor() == 1.0); CPPUNIT_ASSERT(array->getAddOffset() == 0.0); array->set(0, 1.0); array->set(1, 7.0); CPPUNIT_ASSERT(array->get(0) == 1.0); CPPUNIT_ASSERT(array->get(1) == 7.0); }
void SerialPortLink::writeBytes(const char* data,qint64 size) { m_serialPort.open(QIODevice::ReadWrite); //[#strange]: need this statement to open everytime. /* [#Explanation]:write data to serial port [#Ref]: from QGroundControl */ QByteArray byteArray(data, size); //append data into serialBuffer m_serialBuffer.append(byteArray); int numWritten = m_serialPort.write(m_serialBuffer); //once all data is written, flush the buffer m_serialBuffer = m_serialBuffer.remove(0, numWritten); }
byteArray getTileHolderDatabaseMaster(const blub::vector3int32& id) const { soci::indicator indicator = soci::i_null; std::string selectData; m_databaseConnection << "select data from voxel_tiles where x = :x and y = :y and z = :z" , soci::into(selectData, indicator), blub::database::use(id.x), blub::database::use(id.y), blub::database::use(id.z); if (indicator == soci::i_ok) { byteArray decompressed(base64::decode(selectData)); if (m_funcDecompress) { decompressed = m_funcDecompress(decompressed); } return decompressed; } return byteArray(); }
/* * Writes the L3 (IP) packet to the raw socket supplied in the * FileDescriptor instance. * * Assumes that the caller has validated the offset & byteCount values. */ static int RawSocket_sendPacket(JNIEnv* env, jclass, jobject fileDescriptor, jstring interfaceName, jshort protocolType, jbyteArray destMac, jbyteArray packet, jint offset, jint byteCount) { NetFd fd(env, fileDescriptor); if (fd.isClosed()) { return 0; } ScopedUtfChars ifname(env, interfaceName); if (ifname.c_str() == NULL) { return 0; } ScopedByteArrayRO byteArray(env, packet); if (byteArray.get() == NULL) { return 0; } ScopedByteArrayRO mac(env, destMac); if (mac.get() == NULL) { return 0; } sockunion su; memset(&su, 0, sizeof(su)); su.sll.sll_hatype = htons(1); // ARPHRD_ETHER su.sll.sll_halen = mac.size(); memcpy(&su.sll.sll_addr, mac.get(), mac.size()); su.sll.sll_family = AF_PACKET; su.sll.sll_protocol = htons(protocolType); su.sll.sll_ifindex = if_nametoindex(ifname.c_str()); int err; { int intFd = fd.get(); AsynchronousSocketCloseMonitor monitor(intFd); err = NET_FAILURE_RETRY(fd, sendto(intFd, byteArray.get() + offset, byteCount, 0, &su.sa, sizeof(su))); } return err; }
TInt CDatabaseManagerServerSession::RegisterServiceL(const RMessage2& aMessage) { QString securityToken; TVendorId vendorId = aMessage.VendorId(); if (vendorId != 0) { securityToken = QString::number(vendorId); } else { securityToken = QString::number(aMessage.SecureId().iId); } TInt ret; HBufC8* serviceMetaDataBuf8 = HBufC8::New(aMessage.GetDesLength(0)); if (!serviceMetaDataBuf8) return KErrNoMemory; TPtr8 ptrToBuf(serviceMetaDataBuf8->Des()); TRAP(ret, aMessage.ReadL(0, ptrToBuf)); if (ret != KErrNone) { iDb->lastError().setError(DBError::UnknownError); aMessage.Write(1, LastErrorCode()); delete serviceMetaDataBuf8; return ret; } QByteArray byteArray((const char*)ptrToBuf.Ptr(), ptrToBuf.Length()); QDataStream out(byteArray); ServiceMetaDataResults results; out >> results; iDb->registerService(results, securityToken); aMessage.Write(1, LastErrorCode()); delete serviceMetaDataBuf8; return ret; }