void ActionPerformer::cancelAction() { if(action_current == nullptr) { throw IllegalStateException("action is not being performed"); } else if(action_current->cancelling) { throw IllegalStateException("action is already cancelling"); } action_current->cancel(); }
const QString& Action::nextInteraction() { if (!this->hasInteraction()) { throw IllegalStateException("!this->hasInteraction()"); } ++m_index; return m_interactions.at(m_index - 1); }
AVPacket* LibavSingleton::readNextPacket(AVFormatContext *formatContext) const { if (NULL == formatContext) { throw IllegalArgumentException( "Cannot read a packet from a NULL AVFormatContext"); } if (0 >= formatContext->nb_streams) { throw IllegalStateException( "There are no streams within the AVFormatContext to read a packet from."); } AVPacket *packet = new AVPacket(); av_init_packet(packet); int error = av_read_frame(formatContext, packet); // If error equals 0 then we have a valid packet so return it. if (0 == error) return packet; // If we have reached the end of the file return NULL; if (AVERROR_EOF == error) return NULL; // Double check to see if we have reached the end of the file. // Because the AVERROR_EOF error code isn't always returned. AVIOContext *ioContext = formatContext->pb; if (NULL != ioContext && ioContext->eof_reached) return NULL; // Otherwise throw an exception with the error message. throw PacketReadException(errorMessage(error)); }
ParserModel::ParserModel(const std::string &languageCode, AbstractModel *buildModel, AbstractModel *checkModel, AbstractModel *attachModel, POSModel *parserTagger, ChunkerModel *chunkerTagger, opennlp::tools::parser::lang::en::HeadRules *headRules, ParserType modelType, Map<std::string, std::string> *manifestInfoEntries) : opennlp.tools.util.model.BaseModel(COMPONENT_NAME, languageCode, manifestInfoEntries) { setManifestProperty(PARSER_TYPE, modelType::name()); artifactMap->put(BUILD_MODEL_ENTRY_NAME, buildModel); artifactMap->put(CHECK_MODEL_ENTRY_NAME, checkModel); if (CHUNKING::equals(modelType)) { if (attachModel != 0) throw IllegalArgumentException("attachModel must be null for chunking parser!"); } else if (TREEINSERT::equals(modelType)) { if (attachModel == 0) throw IllegalArgumentException("attachModel must not be null!"); artifactMap->put(ATTACH_MODEL_ENTRY_NAME, attachModel); } else { throw IllegalStateException("Unkown ParserType!"); } artifactMap->put(PARSER_TAGGER_MODEL_ENTRY_NAME, parserTagger); artifactMap->put(CHUNKER_TAGGER_MODEL_ENTRY_NAME, chunkerTagger); artifactMap->put(HEAD_RULES_MODEL_ENTRY_NAME, headRules); checkArtifactMap(); }
AVMediaType LibavSingleton::findPacketType(const AVFormatContext *formatContext, const AVPacket *packet) const { if (NULL == formatContext) { throw IllegalArgumentException( "The supplied format context for findPacketType(AVFormatContext*,AVPacket*) cannot be null."); } if (NULL == packet) { throw IllegalArgumentException( "The supplied packet for findPacketType(AVFormatContext*,AVPacket*) cannot be null."); } int packetIndex = packet->stream_index; int streamNumber = formatContext->nb_streams; // Check to make sure the packet index isn't out of bounds. if (0 <= packetIndex && streamNumber < packetIndex) { stringstream errorMessage; errorMessage << "Packet index greater than stream number. Packet index: " << packetIndex << " Stream number: " << streamNumber << " File name: " << formatContext->filename << endl; throw IllegalStateException(errorMessage.str()); } return findStreamType(formatContext->streams[packetIndex]); }
void FeedHandler::tlsPrune(SerialNum oldest_to_keep) { if (!_tlsWriter.erase(oldest_to_keep)) { throw IllegalStateException(make_string("Failed to prune TLS to token %" PRIu64 ".", oldest_to_keep)); } _prunedSerialNum = oldest_to_keep; }
void LibavSingleton::closeFormatContext(AVFormatContext **formatContext) const { if (NULL == (*formatContext)) { throw IllegalArgumentException("Cannot close a NULL AVFormatContext"); } if (0 >= (*formatContext)->nb_streams) { throw IllegalStateException( "The AVFormatContext does not contain any valid streams"); } AVStream *stream = NULL; // Close all the codec contexts within the format context to make sure they // are cleaned up. for (int i = 0; i < (*formatContext)->nb_streams; i++) { stream = (*formatContext)->streams[i]; if (NULL != stream) avcodec_close(stream->codec); } avformat_close_input(formatContext); }
void HTTPClientSession::setProxyHost(const std::string& host) { if (!connected()) _proxyHost = host; else throw IllegalStateException("Cannot set the proxy host for an already connected session"); }
TPElement* OpenSSLRSAPermutation::invert(TPElement * tpEl) { if (!isKeySet()) throw IllegalStateException("keys aren't set"); // If only the public key was set and not the private key - can't do the invert, throw exception. if (privKey == NULL && pubKey != NULL) throw InvalidKeyException("in order to decrypt a message, this object must be initialized with private key"); RSAElement * rsaEl = dynamic_cast<RSAElement *>(tpEl); if (!rsaEl) throw invalid_argument("trapdoor element type doesn't match the trapdoor permutation type"); // gets the pointer for the native object. biginteger elementP = rsaEl->getElement(); // Allocate a new byte array to hold the output. int size = RSA_size(rsa); std::shared_ptr<byte> ret(new byte[size], std::default_delete<byte[]>()); size_t encodedSize = bytesCount(elementP); std::shared_ptr<byte> encodedBi(new byte[encodedSize], std::default_delete<byte[]>()); encodeBigInteger(elementP, encodedBi.get(), encodedSize); string st(encodedBi.get(), encodedBi.get()+encodedSize); // invert the RSA permutation on the given bytes. int sucess = RSA_private_decrypt(encodedSize, encodedBi.get(), ret.get(), rsa, RSA_NO_PADDING); biginteger resValue = decodeBigInteger(ret.get(), size); // creates and initialize a RSAElement with the result. RSAElement * returnEl = new RSAElement(modulus, resValue, false); return returnEl; // return the result TPElement. }
AVMediaType LibavSingleton::findCodecType( const AVCodecContext *codecContext) const { if (NULL == codecContext) { throw IllegalArgumentException( "The supplied codec context for findCodecType(AVCodecContext*) cannot be null."); } AVMediaType type = codecContext->codec_type; // If the type value is within the bounds of the // AVMediaType enum then return it. // This check is unfortunately tightly coupled to // libav version, but I think the benefit of the check // out ways the burden of keeping the values in sync // with the compiled libav version. if (-1 <= type && 5 >= type) return type; stringstream errorMessage; errorMessage << "Invalid AVMediaType value: " << type << endl; throw IllegalStateException(errorMessage.str()); }
Poco::UInt32 ODBCStatementImpl::next() { std::size_t count = 0; if (nextRowReady()) { Extractions& extracts = extractions(); Extractions::iterator it = extracts.begin(); Extractions::iterator itEnd = extracts.end(); std::size_t prevCount = 0; for (std::size_t pos = 0; it != itEnd; ++it) { count = (*it)->extract(pos); if (prevCount && count != prevCount) throw IllegalStateException("Different extraction counts"); prevCount = count; pos += (*it)->numOfColumnsHandled(); } _stepCalled = false; } else { throw StatementException(_stmt, std::string("Iterator Error: trying to access the next value")); } return static_cast<Poco::UInt32>(count); return 0; }
/* * vislib::sys::ThreadPool::queueUserWorkItem */ void vislib::sys::ThreadPool::queueUserWorkItem(WorkItem& workItem, const bool createDefaultThreads) { /* Sanity checks. */ if ((workItem.runnable == NULL) && (workItem.runnableFunction == NULL)) { throw vislib::IllegalParamException("workItem", __FILE__, __LINE__); } if ((workItem.runnable != NULL) && (workItem.runnableFunction != NULL)) { throw vislib::IllegalParamException("workItem", __FILE__, __LINE__); } /* Add work item to queue. */ this->lockQueue.Lock(); if (this->isQueueOpen) { this->queue.Append(workItem); this->evtAllCompleted.Reset(); // Signal unfinished work. this->semBlockWorker.Unlock(); // Wake workers. this->lockQueue.Unlock(); #ifndef _WIN32 // Linux has the most crap scheduler I have ever seen ... sched_yield(); #endif /* _WIN32 */ } else { this->lockQueue.Unlock(); throw IllegalStateException("The user work item queue has been closed, " "because the thread pool is being terminated.", __FILE__, __LINE__); } /* Create threads if requested. */ this->lockThreadCounters.Lock(); if (createDefaultThreads && (this->cntTotalThreads < 1)) { this->SetThreadCount(SystemInformation::ProcessorCount()); } this->lockThreadCounters.Unlock(); }
FieldComparatorPtr SortField::getComparator(int32_t numHits, int32_t sortPos) { if (locale) return newLucene<StringComparatorLocale>(numHits, field, *locale); switch (type) { case SCORE: return newLucene<RelevanceComparator>(numHits); case DOC: return newLucene<DocComparator>(numHits); case SHORT: case INT: return newLucene<IntComparator>(numHits, field, parser); case FLOAT: case DOUBLE: return newLucene<DoubleComparator>(numHits, field, parser); case LONG: return newLucene<LongComparator>(numHits, field, parser); case BYTE: return newLucene<ByteComparator>(numHits, field, parser); case CUSTOM: BOOST_ASSERT(comparatorSource); return comparatorSource->newComparator(field, numHits, sortPos, reverse); case STRING: return newLucene<StringOrdValComparator>(numHits, field, sortPos, reverse); case STRING_VAL: return newLucene<StringValComparator>(numHits, field); default: boost::throw_exception(IllegalStateException(L"Illegal sort type: " + StringUtils::toString(type))); return FieldComparatorPtr(); } }
byte* TrapdoorPermutationAbs::hardCoreFunction(TPElement * tpEl) { if (!isKeySet()) throw IllegalStateException("keys aren't set"); /* * We use this implementation both in RSA permutation and in Rabin permutation. * Thus, We implement it in TrapdoorPermutationAbs and let derived classes override it if needed. */ // gets the element value as byte array biginteger elementValue = tpEl->getElement(); byte* bytesValue=NULL; int bytesSize = allocateAndEncodeBigInteger(elementValue, bytesValue); // the number of bytes to get the log (N) least significant bits double logBits = NumberOfBits(modulus) / 2.0; //log N bits int logBytes = (int)ceil(logBits / 8); //log N bites in bytes // if the element length is less than log(N), the return byte[] should be all the element bytes int size = min(logBytes, bytesSize); byte* leastSignificantBytes = new byte[size]; // copies the bytes to the output array for (int i = 0; i < size; i++) leastSignificantBytes[i] = bytesValue[bytesSize - size + i]; return leastSignificantBytes; }
void HTTPClientSession::setProxyPort(Poco::UInt16 port) { if (!connected()) _proxyPort = port; else throw IllegalStateException("Cannot set the proxy port number for an already connected session"); }
void SegmentInfos::prepareCommit(DirectoryPtr dir) { TestScope testScope(L"SegmentInfos", L"prepareCommit"); if (pendingSegnOutput) boost::throw_exception(IllegalStateException(L"prepareCommit was already called")); write(dir); }
void connect() { if(redisContext_) { throw IllegalStateException("Error redisContext already created"); } state_ = REDISREQUEST_CONNECTING; ScopedMutexLock(lockRedis_); redisContext_ = redisAsyncConnect(host_.c_str(), port_); if (redisContext_->err) { _LOG_DEBUG("REDIS CONNECT FAILED (CREATE ERROR): %s:%d, err = %x, this = %p" , host_.c_str(), port_, redisContext_->err, this); state_ = REDISREQUEST_CONNECTFAILED; //fire_onRedisRequest_Error(redisContext_->err, "connect error", NULL); // disconnectCallback() is called later soon.. // error process will be executed by that function. } redisContext_->data = this; redisLibeventAttach(redisContext_, (struct event_base *)ioService_->coreHandle()); redisAsyncSetConnectCallback(redisContext_, connectCallback); redisAsyncSetDisconnectCallback(redisContext_, disconnectCallback); timerObj_->setTimer(TIMER_ID_CONNECTION_TIMEOUT, DEFAULT_CONNECT_TIMEOUT, false); _LOG_DEBUG("redis connect start : %s:%d, flag = 0x%x, fd = %d, context = %p, this = %p" , host_.c_str(), port_, redisContext_->c.flags, redisContext_->c.fd, redisContext_, this); }
void InternalJob::SetUser(bool value) { //TODO Error Exception Problem IllegalStateException if (GetState() != Job::NONE) throw IllegalStateException(); flags = value ? flags | M_USER : flags & ~M_USER; }
/*MaxValue MaxValue::getMaxValue(BitDepth bitDepth) { switch (bitDepth) { case Unknow: return DoubleUnlimited; case Bit6: return Int6Bit; case Bit8: return Int8Bit; case Bit10: return Int10Bit; case Bit12: return Int12Bit; } }; */ const MaxValue & MaxValue::getByBit(int bit) { foreach(const MaxValue & m, *MaxValueVector) { if (m.bit == bit) { return m; } } throw IllegalStateException(""); };
void HTTPClientSession::setProxy(const std::string& host, uint16_t port) { if (!connected()) { _proxyHost = host; _proxyPort = port; } else throw IllegalStateException("Cannot set the proxy host and port for an already connected session"); }
void LubyRackoffPrpFromPrfVarying::computeBlock(const vector<byte> & inBytes, int inOff, int inLen, vector<byte>& outBytes, int outOff) { if (!isKeySet()) throw IllegalStateException("secret key isn't set"); if ((inOff > inBytes.size()) || (inOff + inLen > inBytes.size())) throw out_of_range("wrong offset for the given input buffer"); if ((outOff > outBytes.size()) || (outOff + inLen > outBytes.size())) throw out_of_range("wrong offset for the given output buffer"); if (inLen % 2 != 0) // checks that the input is of even length. throw invalid_argument("Length of input must be even"); int sideSize = inLen / 2; // L in the pseudo code vector<byte> * tmpReference = NULL; vector<byte> * leftNext = new vector<byte>(sideSize); vector<byte> * rightNext = new vector<byte>(sideSize+1);//keeps space for the index. Size of L+1. // Let left_current be the first half bits of the input vector<byte> * leftCurrent = new vector<byte>(inBytes.begin()+inOff, inBytes.begin() + inOff + sideSize); //Let right_current be the last half bits of the input vector<byte> * rightCurrent = new vector<byte>(inBytes.begin() + inOff + sideSize, inBytes.begin() + inOff + 2 * sideSize); for (int i = 1; i <= 4; i++) { // Li = Ri-1 leftNext->insert(rightCurrent->begin(), leftNext->begin(), rightCurrent->begin() + sideSize); // put the index in the last position of Ri-1 rightCurrent->push_back((byte)i); // does PRF_VARY_INOUT(k,(Ri-1,i),L) of the pseudocode // puts the result in the rightNext array. Later we will XOr it with leftCurrent. Note that the result size is not the entire // rightNext array. It is one byte less. The remaining byte will contain the index for the next iteration. prfVaryingIOLength->computeBlock(*rightCurrent, 0, rightCurrent->size(), *rightNext, 0, sideSize); // does Ri = Li-1 ^ PRF_VARY_INOUT(k,(Ri-1,i),L) // XOR rightNext (which is the resulting PRF computation by now) with leftCurrent. for (int j = 0; j<sideSize; j++) (*rightNext)[j] = (byte)((*rightNext)[j] ^ (*leftCurrent)[j]); //switches between the current and the next for the next round. //Note that it is much more readable and straightforward to copy the next arrays into the current arrays. //However why copy if we can switch between them and avoid the performance increase by copying. We can not just use assignment //Since both current and next will point to the same memory block and thus changing one will change the other. tmpReference = leftCurrent; leftCurrent = leftNext; leftNext = tmpReference; tmpReference = rightCurrent; rightCurrent = rightNext; rightNext = tmpReference; } // copies the result to the out array. outBytes.insert(outBytes.begin() + outOff, leftCurrent->begin(), leftCurrent->begin() + (inLen / 2)); outBytes.insert(outBytes.begin() + outOff+inLen/2, rightCurrent->begin(), rightCurrent->begin() + (inLen / 2)); delete leftCurrent, leftNext, rightCurrent, rightNext; // no need to delete tmpRefernece points to rightNext }
/* * vislib::net::IPAgnosticAddress::operator vislib::net::IPAddress6 * */ vislib::net::IPAgnosticAddress::operator vislib::net::IPAddress6 *(void) { VLSTACKTRACE("IPAgnosticAddress::operator IPAddress6 *", __FILE__, __LINE__); if (this->IsV6()) { return this->v6; } else { throw IllegalStateException("The IPAgnosticAddress does not represent " "an IPv6 address.", __FILE__, __LINE__); } }
void NetworkTable::AddConnectionListener(IRemoteConnectionListener* listener, bool immediateNotify) { map<IRemoteConnectionListener*, NetworkTableConnectionListenerAdapter*>::iterator itr = connectionListenerMap.find(listener); if(itr != connectionListenerMap.end()){ throw IllegalStateException("Cannot add the same listener twice"); } else{ NetworkTableConnectionListenerAdapter* adapter = new NetworkTableConnectionListenerAdapter(this, listener); connectionListenerMap[listener] = adapter; node.AddConnectionListener(adapter, immediateNotify); } }
void System::setupPresentation() { if( _state != SystemState_Integrated ) throw IllegalStateException( "the system's state is not SystemState_Integrated" ); _state = SystemState_IntegratingPresentation; _modules->updateModules( ModuleState_PresentationIntegrated ); _state = SystemState_Running; }
/* * vislib::net::IPAgnosticAddress::operator const vislib::net::IPAddress * */ vislib::net::IPAgnosticAddress::operator const vislib::net::IPAddress *( void) const { VLSTACKTRACE("IPAgnosticAddress::operator const IPAddress *", __FILE__, __LINE__); if (this->IsV4()) { return this->v4; } else { throw IllegalStateException("The IPAgnosticAddress does not represent " "an IPv4 address.", __FILE__, __LINE__); } }
/* * vislib::net::IPAgnosticAddress::operator [] */ BYTE vislib::net::IPAgnosticAddress::operator [](const int i) const { VLSTACKTRACE("IPAgnosticAddress::operator []", __FILE__, __LINE__); if (this->IsV4()) { return this->v4->operator [](i); } else if (this->IsV6()) { return this->v6->operator [](i); } else { throw IllegalStateException("The IPAgnosticAddress has no data to " "be accessed.", __FILE__, __LINE__); } }
/* * vislib::net::IPAgnosticAddress::operator vislib::net::IPAddress */ vislib::net::IPAgnosticAddress::operator vislib::net::IPAddress(void) const { VLSTACKTRACE("IPAgnosticAddress::operator IPAddress", __FILE__, __LINE__); if (this->IsV4()) { return *(this->v4); } else if (this->IsV6()) { return static_cast<IPAddress>(*(this->v6)); } else { throw IllegalStateException("The IPAgnosticAddress cannot be converted " "to an IPv4 address.", __FILE__, __LINE__); } }
void PrpFromPrfFixed::computeBlock(const vector<byte> & inBytes, int inOff, int inLen, vector<byte>& outBytes, int outOff, int outLen) { if (!isKeySet()) throw IllegalStateException("secret key isn't set"); if ((inOff > inBytes.size()) || (inOff + inLen > inBytes.size())) throw out_of_range("wrong offset for the given input buffer"); if ((outOff > outBytes.size()) || (outOff + outLen > outBytes.size())) throw out_of_range("wrong offset for the given output buffer"); // if the input and output length are equal to the blockSize, call the computeBlock that doesn't take length arguments. if (inLen == outLen && inLen == getBlockSize()) computeBlock(inBytes, inOff, outBytes, outOff); else throw out_of_range("input and output lengths should be equal to Block size"); }
void PrpFromPrfFixed::invertBlock(const vector<byte> & inBytes, int inOff, vector<byte>& outBytes, int outOff, int len) { if (!isKeySet()) throw IllegalStateException("secret key isn't set"); if ((inOff > inBytes.size()) || (inOff + len > inBytes.size())) throw out_of_range("wrong offset for the given input buffer"); if ((outOff > outBytes.size()) || (outOff + len > outBytes.size())) throw out_of_range("wrong offset for the given output buffer"); // checks that the offset and length are correct if (len == getBlockSize())//the length is correct //call the derived class implementation of invertBlock ignoring len invertBlock(inBytes, inOff, outBytes, outOff); else throw out_of_range("the length should be the same as block size"); }
void RowFilter::doCompare(Poco::Dynamic::Var& ret, Poco::Dynamic::Var& val, CompT comp, const ComparisonEntry& ce) { if (ret.isEmpty()) ret = comp(val, ce.get<0>()); else { if (ce.get<2>() == OP_OR) ret = ret || comp(val, ce.get<0>()); else if (ce.get<2>() == OP_AND) ret = ret && comp(val, ce.get<0>()); else throw IllegalStateException("Unknown logical operation."); } }