idx
int64
0
165k
question
stringlengths
73
5.81k
target
stringlengths
5
918
122,300
private void parse ( String propKey , String propValue ) { if ( ARG_TAG . equals ( propValue ) ) { String value = System . getProperty ( propKey ) ; if ( StringUtils . isNotBlank ( value ) && value . startsWith ( CRYPTEX_TAG ) ) { value = decrypt ( value ) ; } if ( StringUtils . isNotBlank ( value ) ) { this . props . ...
Parses a given property key and value and checks if the value comes from a system property and maybe decrypts the value
122,301
private String decrypt ( String value ) { Crypto crypto = new Crypto ( this ) ; String keyFile = System . getProperty ( Key . APPLICATION_PRIVATEKEY . toString ( ) ) ; if ( StringUtils . isNotBlank ( keyFile ) ) { try ( Stream < String > lines = Files . lines ( Paths . get ( keyFile ) ) ) { String key = lines . findFir...
Decrypts a given property key and rewrites it to props
122,302
public static void header ( Header header , String value ) { Objects . requireNonNull ( header , Required . HEADER . toString ( ) ) ; Map < Header , String > newHeaders = new EnumMap < > ( headers ) ; newHeaders . put ( header , value ) ; headers = newHeaders ; }
Sets a custom header that is used globally on server responses
122,303
public Mail withBuilder ( Email email ) { Objects . requireNonNull ( email , Required . EMAIL . toString ( ) ) ; this . email = email ; return this ; }
Sets the org . Jodd . Email instance that the email is based on
122,304
public Mail templateMessage ( String template , Map < String , Object > content ) throws MangooTemplateEngineException { Objects . requireNonNull ( template , Required . TEMPLATE . toString ( ) ) ; Objects . requireNonNull ( content , Required . CONTENT . toString ( ) ) ; if ( template . charAt ( 0 ) == '/' || template...
Sets a template to be rendered for the email . Using a template will make it a HTML Email by default .
122,305
public static Date localDateTimeToDate ( LocalDateTime localDateTime ) { Objects . requireNonNull ( localDateTime , Required . LOCAL_DATE_TIME . toString ( ) ) ; Instant instant = localDateTime . atZone ( ZoneId . systemDefault ( ) ) . toInstant ( ) ; return Date . from ( instant ) ; }
Converts a LocalDateTime to Date
122,306
public static Date localDateToDate ( LocalDate localDate ) { Objects . requireNonNull ( localDate , Required . LOCAL_DATE . toString ( ) ) ; Instant instant = localDate . atStartOfDay ( ) . atZone ( ZoneId . systemDefault ( ) ) . toInstant ( ) ; return Date . from ( instant ) ; }
Converts a localDate to Date
122,307
protected Request getRequest ( HttpServerExchange exchange ) { final String authenticity = Optional . ofNullable ( this . attachment . getRequestParameter ( ) . get ( Default . AUTHENTICITY . toString ( ) ) ) . orElse ( this . attachment . getForm ( ) . get ( Default . AUTHENTICITY . toString ( ) ) ) ; return new Reque...
Creates a new request object containing the current request data
122,308
protected Response invokeController ( HttpServerExchange exchange , Response response ) throws IllegalAccessException , InvocationTargetException , MangooTemplateEngineException , IOException { Response invokedResponse ; if ( this . attachment . getMethodParameters ( ) . isEmpty ( ) ) { invokedResponse = ( Response ) t...
Invokes the controller methods and retrieves the response which is later send to the client
122,309
protected String getTemplatePath ( Response response ) { return StringUtils . isBlank ( response . getTemplate ( ) ) ? ( this . attachment . getControllerClassName ( ) + "/" + this . attachment . getTemplateEngine ( ) . getTemplateName ( this . attachment . getControllerMethodName ( ) ) ) : response . getTemplate ( ) ;...
Returns the complete path to the template based on the controller and method name
122,310
protected Response executeFilter ( List < Annotation > annotations , Response response ) throws NoSuchMethodException , IllegalAccessException , InvocationTargetException { for ( final Annotation annotation : annotations ) { final FilterWith filterWith = ( FilterWith ) annotation ; for ( final Class < ? > clazz : filte...
Executes all filters on controller and method level
122,311
protected String getRequestBody ( HttpServerExchange exchange ) throws IOException { String body = "" ; if ( RequestUtils . isPostPutPatch ( exchange ) ) { exchange . startBlocking ( ) ; body = IOUtils . toString ( exchange . getInputStream ( ) , Default . ENCODING . toString ( ) ) ; } return body ; }
Retrieves the complete request body from the request
122,312
public boolean isStarted ( ) throws MangooSchedulerException { boolean started ; try { started = this . quartzScheduler != null && this . quartzScheduler . isStarted ( ) ; } catch ( SchedulerException e ) { throw new MangooSchedulerException ( e ) ; } return started ; }
Checks if the scheduler is initialized and started
122,313
public void schedule ( JobDetail jobDetail , Trigger trigger ) throws MangooSchedulerException { Objects . requireNonNull ( jobDetail , Required . JOB_DETAIL . toString ( ) ) ; Objects . requireNonNull ( trigger , Required . TRIGGER . toString ( ) ) ; Objects . requireNonNull ( this . quartzScheduler , Required . SCHED...
Adds a new job with a given JobDetail and Trigger to the scheduler
122,314
@ SuppressWarnings ( "unchecked" ) public List < io . mangoo . models . Job > getAllJobs ( ) throws MangooSchedulerException { Objects . requireNonNull ( this . quartzScheduler , Required . SCHEDULER . toString ( ) ) ; List < io . mangoo . models . Job > jobs = new ArrayList < > ( ) ; try { for ( JobKey jobKey : getAll...
Retrieves a list of all jobs and their current status
122,315
public JobKey getJobKey ( String name ) throws MangooSchedulerException { Objects . requireNonNull ( name , Required . NAME . toString ( ) ) ; return getAllJobKeys ( ) . stream ( ) . filter ( jobKey -> jobKey . getName ( ) . equalsIgnoreCase ( name ) ) . findFirst ( ) . orElse ( null ) ; }
Retrieves a JobKey by it given name
122,316
public void executeJob ( String jobName ) throws MangooSchedulerException { Objects . requireNonNull ( this . quartzScheduler , Required . SCHEDULER . toString ( ) ) ; Objects . requireNonNull ( jobName , Required . JOB_NAME . toString ( ) ) ; try { for ( JobKey jobKey : getAllJobKeys ( ) ) { if ( jobKey . getName ( ) ...
Executes a single Quartz Scheduler job right away only once
122,317
public List < JobKey > getAllJobKeys ( ) throws MangooSchedulerException { Objects . requireNonNull ( this . quartzScheduler , Required . SCHEDULER . toString ( ) ) ; List < JobKey > jobKeys = new ArrayList < > ( ) ; try { for ( String groupName : this . quartzScheduler . getJobGroupNames ( ) ) { jobKeys . addAll ( thi...
Retrieves a list of all JobKeys from the Quartz Scheduler
122,318
public void changeState ( String jobName ) throws MangooSchedulerException { Objects . requireNonNull ( this . quartzScheduler , Required . SCHEDULER . toString ( ) ) ; try { for ( JobKey jobKey : getAllJobKeys ( ) ) { if ( jobKey . getName ( ) . equalsIgnoreCase ( jobName ) ) { TriggerState triggerState = getTriggerSt...
Changes the state of a normally running job from pause to resume or resume to pause
122,319
private void endRequest ( HttpServerExchange exchange , String redirect ) { exchange . setStatusCode ( StatusCodes . FOUND ) ; Server . headers ( ) . entrySet ( ) . stream ( ) . filter ( entry -> StringUtils . isNotBlank ( entry . getValue ( ) ) ) . forEach ( entry -> exchange . getResponseHeaders ( ) . add ( entry . g...
Ends the current request by sending a HTTP 302 status code and a direct to the given URL
122,320
private void endRequest ( HttpServerExchange exchange ) { exchange . setStatusCode ( StatusCodes . FORBIDDEN ) ; Server . headers ( ) . entrySet ( ) . stream ( ) . filter ( entry -> StringUtils . isNotBlank ( entry . getValue ( ) ) ) . forEach ( entry -> exchange . getResponseHeaders ( ) . add ( entry . getKey ( ) . to...
Ends the current request by sending a HTTP 403 status code and the default forbidden template
122,321
public static Map < String , String > getRequestParameters ( HttpServerExchange exchange ) { Objects . requireNonNull ( exchange , Required . HTTP_SERVER_EXCHANGE . toString ( ) ) ; final Map < String , String > requestParamater = new HashMap < > ( ) ; final Map < String , Deque < String > > queryParameters = exchange ...
Converts request and query parameter into a single map
122,322
public static boolean isPostPutPatch ( HttpServerExchange exchange ) { Objects . requireNonNull ( exchange , Required . HTTP_SERVER_EXCHANGE . toString ( ) ) ; return ( Methods . POST ) . equals ( exchange . getRequestMethod ( ) ) || ( Methods . PUT ) . equals ( exchange . getRequestMethod ( ) ) || ( Methods . PATCH ) ...
Checks if the request is a POST PUT or PATCH request
122,323
public static boolean hasValidAuthentication ( String cookie ) { boolean valid = false ; if ( StringUtils . isNotBlank ( cookie ) ) { Config config = Application . getInstance ( Config . class ) ; String value = null ; String [ ] contents = cookie . split ( ";" ) ; for ( String content : contents ) { if ( StringUtils ....
Checks if the given header contains a valid authentication
122,324
public static HttpHandler wrapBasicAuthentication ( HttpHandler httpHandler , String username , String password ) { Objects . requireNonNull ( httpHandler , Required . HTTP_HANDLER . toString ( ) ) ; Objects . requireNonNull ( username , Required . USERNAME . toString ( ) ) ; Objects . requireNonNull ( password , Requi...
Adds a Wrapper to the handler when the request requires authentication
122,325
public static String getOperation ( HttpString method ) { String operation = "" ; if ( Methods . POST . equals ( method ) ) { operation = WRITE ; } else if ( Methods . PUT . equals ( method ) ) { operation = WRITE ; } else if ( Methods . DELETE . equals ( method ) ) { operation = WRITE ; } else if ( Methods . GET . equ...
Return if a given HTTP method results in a read or write request to a resource
122,326
public String decrypt ( String encrytedText , String key ) { Objects . requireNonNull ( encrytedText , Required . ENCRYPTED_TEXT . toString ( ) ) ; Objects . requireNonNull ( key , Required . KEY . toString ( ) ) ; CipherParameters cipherParameters = new ParametersWithRandom ( new KeyParameter ( getSizedSecret ( key ) ...
Decrypts an given encrypted text using the given key
122,327
public String encrypt ( final String plainText , final String key ) { Objects . requireNonNull ( plainText , Required . PLAIN_TEXT . toString ( ) ) ; Objects . requireNonNull ( key , Required . KEY . toString ( ) ) ; CipherParameters cipherParameters = new ParametersWithRandom ( new KeyParameter ( getSizedSecret ( key ...
Encrypts a given plain text using the given key
122,328
private byte [ ] cipherData ( final byte [ ] data ) { byte [ ] result = null ; try { final byte [ ] buffer = new byte [ this . paddedBufferedBlockCipher . getOutputSize ( data . length ) ] ; final int processedBytes = this . paddedBufferedBlockCipher . processBytes ( data , 0 , data . length , buffer , 0 ) ; final int ...
Encrypts or decrypts a given byte array of data
122,329
public KeyPair generateKeyPair ( ) { KeyPair keyPair = null ; try { KeyPairGenerator keyPairGenerator = KeyPairGenerator . getInstance ( ALGORITHM ) ; keyPairGenerator . initialize ( KEYLENGTH ) ; keyPair = keyPairGenerator . generateKeyPair ( ) ; } catch ( NoSuchAlgorithmException e ) { LOG . error ( "Failed to create...
Generate key which contains a pair of private and public key using 4096 bytes
122,330
public byte [ ] encrypt ( byte [ ] text , PublicKey key ) throws MangooEncryptionException { Objects . requireNonNull ( text , Required . PLAIN_TEXT . toString ( ) ) ; Objects . requireNonNull ( text , Required . PUBLIC_KEY . toString ( ) ) ; byte [ ] encrypt = null ; try { Cipher cipher = Cipher . getInstance ( ENCRYP...
Encrypt a text using public key
122,331
public String encrypt ( String text , PublicKey key ) throws MangooEncryptionException { Objects . requireNonNull ( text , Required . PLAIN_TEXT . toString ( ) ) ; Objects . requireNonNull ( text , Required . PUBLIC_KEY . toString ( ) ) ; String encrypt = null ; try { byte [ ] cipherText = encrypt ( text . getBytes ( S...
Encrypt a text using public key . The result is encoded to Base64 .
122,332
public byte [ ] decrypt ( byte [ ] text , PrivateKey key ) throws MangooEncryptionException { Objects . requireNonNull ( text , Required . ENCRYPTED_TEXT . toString ( ) ) ; Objects . requireNonNull ( text , Required . PRIVATE_KEY . toString ( ) ) ; byte [ ] decrypt = null ; try { Cipher cipher = Cipher . getInstance ( ...
Decrypt text using private key
122,333
public String decrypt ( String text , PrivateKey key ) throws MangooEncryptionException { Objects . requireNonNull ( text , Required . ENCRYPTED_TEXT . toString ( ) ) ; Objects . requireNonNull ( text , Required . PRIVATE_KEY . toString ( ) ) ; String decrypt = null ; try { byte [ ] dectyptedText = decrypt ( decodeBase...
Decrypt Base64 encoded text using private key
122,334
public String getKeyAsString ( Key key ) { Objects . requireNonNull ( key , Required . KEY . toString ( ) ) ; return encodeBase64 ( key . getEncoded ( ) ) ; }
Convert a Key to string encoded as Base64
122,335
public PrivateKey getPrivateKeyFromString ( String key ) throws MangooEncryptionException { Objects . requireNonNull ( key , Required . KEY . toString ( ) ) ; try { return KeyFactory . getInstance ( ALGORITHM ) . generatePrivate ( new PKCS8EncodedKeySpec ( decodeBase64 ( key ) ) ) ; } catch ( InvalidKeySpecException | ...
Generates Private Key from Base64 encoded string
122,336
public PublicKey getPublicKeyFromString ( String key ) throws MangooEncryptionException { Objects . requireNonNull ( key , Required . KEY . toString ( ) ) ; try { return KeyFactory . getInstance ( ALGORITHM ) . generatePublic ( new X509EncodedKeySpec ( decodeBase64 ( key ) ) ) ; } catch ( InvalidKeySpecException | NoSu...
Generates Public Key from Base64 encoded string
122,337
private String encodeBase64 ( byte [ ] bytes ) { Objects . requireNonNull ( bytes , Required . BYTES . toString ( ) ) ; return org . apache . commons . codec . binary . Base64 . encodeBase64String ( bytes ) ; }
Encode bytes array to Base64 string
122,338
private byte [ ] decodeBase64 ( String text ) { Objects . requireNonNull ( text , Required . PLAIN_TEXT . toString ( ) ) ; return org . apache . commons . codec . binary . Base64 . decodeBase64 ( text ) ; }
Decode Base64 encoded string to bytes array
122,339
public static String hexJBcrypt ( String data ) { Objects . requireNonNull ( data , Required . DATA . toString ( ) ) ; return BCrypt . hashpw ( data , BCrypt . gensalt ( Default . JBCRYPT_ROUNDS . toInt ( ) ) ) ; }
Hashes a given cleartext data with JBCrypt
122,340
public static String hexSHA512 ( String data ) { Objects . requireNonNull ( data , Required . DATA . toString ( ) ) ; return DigestUtils . sha512Hex ( data ) ; }
Hashes a given cleartext data with SHA512
122,341
public static String hexSHA512 ( String data , String salt ) { Objects . requireNonNull ( data , Required . DATA . toString ( ) ) ; Objects . requireNonNull ( salt , Required . SALT . toString ( ) ) ; return DigestUtils . sha512Hex ( data + salt ) ; }
Hashes a given cleartext data with SHA512 and an appended salt
122,342
public static boolean checkJBCrypt ( String data , String hash ) { Objects . requireNonNull ( data , Required . DATA . toString ( ) ) ; Objects . requireNonNull ( hash , Required . HASH . toString ( ) ) ; return BCrypt . checkpw ( data , hash ) ; }
Checks a given data against a JBCrypted hash
122,343
public static String serializeToBase64 ( Serializable object ) { Objects . requireNonNull ( object , Required . OBJECT . toString ( ) ) ; byte [ ] serialize = SerializationUtils . serialize ( object ) ; return base64Encoder . encodeToString ( serialize ) ; }
Serializes an object into an Base64 encoded data string
122,344
public static < T > T deserializeFromBase64 ( String data ) { Objects . requireNonNull ( data , Required . DATA . toString ( ) ) ; byte [ ] bytes = base64Decoder . decode ( data ) ; return SerializationUtils . deserialize ( bytes ) ; }
Deserialize a given Base64 encoded data string into an object
122,345
public Optional < String > getString ( String key ) { Objects . requireNonNull ( key , Required . KEY . toString ( ) ) ; String value = this . values . get ( key ) ; if ( StringUtils . isNotBlank ( value ) ) { return Optional . of ( value ) ; } return Optional . empty ( ) ; }
Retrieves an optional string value corresponding to the name of the form element
122,346
public Optional < Boolean > getBoolean ( String key ) { Objects . requireNonNull ( key , Required . KEY . toString ( ) ) ; String value = this . values . get ( key ) ; if ( StringUtils . isNotBlank ( value ) ) { if ( ( "1" ) . equals ( value ) ) { return Optional . of ( Boolean . TRUE ) ; } else if ( ( "true" ) . equal...
Retrieves an optional boolean value corresponding to the name of the form element
122,347
public Optional < Integer > getInteger ( String key ) { Objects . requireNonNull ( key , Required . KEY . toString ( ) ) ; String value = this . values . get ( key ) ; if ( StringUtils . isNotBlank ( value ) && NumberUtils . isCreatable ( value ) ) { return Optional . of ( Integer . valueOf ( value ) ) ; } return Optio...
Retrieves an optional integer value corresponding to the name of the form element
122,348
public Optional < InputStream > getFile ( ) { if ( ! this . files . isEmpty ( ) ) { return Optional . of ( this . files . get ( 0 ) ) ; } return Optional . empty ( ) ; }
Retrieves a single file of the form . If the the form has multiple files the first will be returned
122,349
public void addValueList ( String key , String value ) { Objects . requireNonNull ( key , Required . KEY . toString ( ) ) ; if ( ! valueMap . containsKey ( key ) ) { List < String > values = new ArrayList < > ( ) ; values . add ( value ) ; valueMap . put ( key , values ) ; } else { List < String > values = valueMap . g...
Adds an additional item to the value list
122,350
public List < String > getValueList ( String key ) { Objects . requireNonNull ( key , Required . KEY . toString ( ) ) ; return this . valueMap . get ( key ) ; }
Retrieves the value list for a given key
122,351
public void register ( Object eventListener ) { Objects . requireNonNull ( eventListener , Required . EVENT_LISTENER . toString ( ) ) ; this . eventBus . register ( eventListener ) ; this . listeners . getAndIncrement ( ) ; }
Registers an event listener to the event bus
122,352
public void unregister ( Object eventListener ) throws MangooEventBusException { Objects . requireNonNull ( eventListener , Required . EVENT_LISTENER . toString ( ) ) ; try { this . eventBus . unregister ( eventListener ) ; } catch ( IllegalArgumentException e ) { throw new MangooEventBusException ( e ) ; } if ( this ....
Unregisters an event listener to the event bus
122,353
public void publish ( Object event ) { Objects . requireNonNull ( event , Required . EVENT . toString ( ) ) ; this . eventBus . post ( event ) ; this . events . getAndIncrement ( ) ; }
Publishes an event to the event bus
122,354
@ SuppressWarnings ( "rawtypes" ) protected Form getForm ( HttpServerExchange exchange ) throws IOException { final Form form = Application . getInstance ( Form . class ) ; if ( RequestUtils . isPostPutPatch ( exchange ) ) { final Builder builder = FormParserFactory . builder ( ) ; builder . setDefaultCharset ( Standar...
Retrieves the form parameter from a request
122,355
public void put ( String key , String value ) { if ( INVALID_CHRACTERTS . contains ( key ) || INVALID_CHRACTERTS . contains ( value ) ) { LOG . error ( "Session key or value can not contain the following characters: spaces, |, & or :" ) ; } else { this . changed = true ; this . values . put ( key , value ) ; } }
Adds a value to the session overwriting an existing value
122,356
private Map < String , Class < ? > > getMethodParameters ( ) { final Map < String , Class < ? > > parameters = new LinkedHashMap < > ( ) ; for ( final Method declaredMethod : this . controllerClass . getDeclaredMethods ( ) ) { if ( declaredMethod . getName ( ) . equals ( this . controllerMethodName ) && declaredMethod ...
Converts the method parameter of a mapped controller method to a map
122,357
public WebSocketRoute onController ( Class < ? > clazz ) { Objects . requireNonNull ( clazz , Required . URL . toString ( ) ) ; this . controllerClass = clazz ; return this ; }
Sets the controller class for this WebSocket route
122,358
public static String toJson ( Object object ) { Objects . requireNonNull ( object , Required . OBJECT . toString ( ) ) ; String json = null ; try { json = mapper . writeValueAsString ( object ) ; } catch ( JsonProcessingException e ) { LOG . error ( "Failed to convert object to json" , e ) ; } return json ; }
Converts a given object to a Json string
122,359
public static ReadContext fromJson ( String json ) { Objects . requireNonNull ( json , Required . JSON . toString ( ) ) ; return JsonPath . parse ( json ) ; }
Converts a given Json string to an JSONPath ReadContext
122,360
public static < T > T fromJson ( String json , Class < T > clazz ) { Objects . requireNonNull ( json , Required . JSON . toString ( ) ) ; Objects . requireNonNull ( clazz , Required . CLASS . toString ( ) ) ; T object = null ; try { object = mapper . readValue ( json , clazz ) ; } catch ( IOException e ) { LOG . error ...
Converts a given Json string to given Class
122,361
public String get ( String key ) { Objects . requireNonNull ( key , Required . KEY . toString ( ) ) ; return this . values . get ( key ) ; }
Retrieves a form value corresponding to the name of the form element
122,362
protected void setSessionCookie ( HttpServerExchange exchange ) { Session session = this . attachment . getSession ( ) ; if ( session . isInvalid ( ) ) { Cookie cookie = new CookieImpl ( this . config . getSessionCookieName ( ) ) . setSecure ( this . config . isSessionCookieSecure ( ) ) . setHttpOnly ( true ) . setPath...
Sets the session cookie to the current HttpServerExchange
122,363
protected void setAuthenticationCookie ( HttpServerExchange exchange ) { Authentication authentication = this . attachment . getAuthentication ( ) ; if ( authentication . isInvalid ( ) || authentication . isLogout ( ) ) { Cookie cookie = new CookieImpl ( this . config . getAuthenticationCookieName ( ) ) . setSecure ( t...
Sets the authentication cookie to the current HttpServerExchange
122,364
protected void setFlashCookie ( HttpServerExchange exchange ) { Flash flash = this . attachment . getFlash ( ) ; Form form = this . attachment . getForm ( ) ; if ( flash . isDiscard ( ) || flash . isInvalid ( ) ) { final Cookie cookie = new CookieImpl ( this . config . getFlashCookieName ( ) ) . setHttpOnly ( true ) . ...
Sets the flash cookie to current HttpServerExchange
122,365
protected void handleBinaryResponse ( HttpServerExchange exchange , Response response ) { exchange . dispatch ( exchange . getDispatchExecutor ( ) , Application . getInstance ( BinaryHandler . class ) . withResponse ( response ) ) ; }
Handles a binary response to the client by sending the binary content from the response to the undertow output stream
122,366
protected void handleRedirectResponse ( HttpServerExchange exchange , Response response ) { exchange . setStatusCode ( StatusCodes . FOUND ) ; Server . headers ( ) . entrySet ( ) . stream ( ) . filter ( entry -> StringUtils . isNotBlank ( entry . getValue ( ) ) ) . forEach ( entry -> exchange . getResponseHeaders ( ) ....
Handles a redirect response to the client by sending a 403 status code to the client
122,367
protected void handleRenderedResponse ( HttpServerExchange exchange , Response response ) { exchange . setStatusCode ( response . getStatusCode ( ) ) ; Server . headers ( ) . entrySet ( ) . stream ( ) . filter ( entry -> StringUtils . isNotBlank ( entry . getValue ( ) ) ) . forEach ( entry -> exchange . getResponseHead...
Handles a rendered response to the client by sending the rendered body from the response object
122,368
private static void prepareMode ( Mode providedMode ) { final String applicationMode = System . getProperty ( Key . APPLICATION_MODE . toString ( ) ) ; if ( StringUtils . isNotBlank ( applicationMode ) ) { switch ( applicationMode . toLowerCase ( Locale . ENGLISH ) ) { case "dev" : mode = Mode . DEV ; break ; case "tes...
Sets the mode the application is running in
122,369
private static void prepareConfig ( ) { Config config = getInstance ( Config . class ) ; int bitLength = getBitLength ( config . getApplicationSecret ( ) ) ; if ( bitLength < KEY_MIN_BIT_LENGTH ) { LOG . error ( "Application requires a 512 bit application secret. The current property for application.secret has currentl...
Checks for config failures that prevent the application from starting
122,370
private static void prepareRoutes ( ) { injector . getInstance ( MangooBootstrap . class ) . initializeRoutes ( ) ; Router . getRequestRoutes ( ) . forEach ( ( RequestRoute requestRoute ) -> { if ( ! methodExists ( requestRoute . getControllerMethod ( ) , requestRoute . getControllerClass ( ) ) ) { LOG . error ( "Could...
Validate if the routes that are defined in the router are valid
122,371
private static void createRoutes ( ) { pathHandler = new PathHandler ( getRoutingHandler ( ) ) ; Router . getWebSocketRoutes ( ) . forEach ( ( WebSocketRoute webSocketRoute ) -> pathHandler . addExactPath ( webSocketRoute . getUrl ( ) , Handlers . websocket ( getInstance ( WebSocketHandler . class ) . withControllerCla...
Create routes for WebSockets ServerSentEvent and Resource files
122,372
public static String getLogo ( ) { String logo = "" ; try ( InputStream inputStream = Resources . getResource ( Default . LOGO_FILE . toString ( ) ) . openStream ( ) ) { logo = IOUtils . toString ( inputStream , Default . ENCODING . toString ( ) ) ; } catch ( final IOException e ) { LOG . error ( "Failed to get applica...
Retrieves the logo from the logo file and returns the string
122,373
public boolean validLogin ( String identifier , String password , String hash ) { Objects . requireNonNull ( identifier , Required . USERNAME . toString ( ) ) ; Objects . requireNonNull ( password , Required . PASSWORD . toString ( ) ) ; Objects . requireNonNull ( hash , Required . HASH . toString ( ) ) ; Cache cache =...
Creates a hashed value of a given clear text password and checks if the value matches a given already hashed password
122,374
public boolean userHasLock ( String username ) { Objects . requireNonNull ( username , Required . USERNAME . toString ( ) ) ; boolean lock = false ; Config config = Application . getInstance ( Config . class ) ; Cache cache = Application . getInstance ( CacheProvider . class ) . getCache ( CacheName . AUTH ) ; AtomicIn...
Checks if a username is locked because of to many failed login attempts
122,375
public boolean validSecondFactor ( String secret , String number ) { Objects . requireNonNull ( secret , Required . SECRET . toString ( ) ) ; Objects . requireNonNull ( number , Required . TOTP . toString ( ) ) ; return TotpUtils . verifiedTotp ( secret , number ) ; }
Checks if a given number for 2FA is valid for the given secret
122,376
public void withRoutes ( MangooRoute ... routes ) { Objects . requireNonNull ( routes , Required . ROUTE . toString ( ) ) ; for ( MangooRoute route : routes ) { RequestRoute requestRoute = ( RequestRoute ) route ; requestRoute . withControllerClass ( this . controllerClass ) ; if ( hasBasicAuthentication ( ) ) { reques...
Sets the given routes to the defined controller class
122,377
public static int bitLength ( byte [ ] bytes ) { Objects . requireNonNull ( bytes , Required . BYTES . toString ( ) ) ; int byteLength = bytes . length ; int length = 0 ; if ( byteLength <= MAX_BYTE_LENGTH && byteLength > 0 ) { length = byteLength * BYTES ; } return length ; }
Calculates the bit length of a given byte array
122,378
public static int bitLength ( String string ) { Objects . requireNonNull ( string , Required . STRING . toString ( ) ) ; int byteLength = string . getBytes ( StandardCharsets . UTF_8 ) . length ; int length = 0 ; if ( byteLength <= MAX_BYTE_LENGTH && byteLength > 0 ) { length = byteLength * BYTES ; } return length ; }
Calculates the bit length of a given string
122,379
private boolean isNotBlank ( String subject , String resource , String operation ) { return StringUtils . isNotBlank ( subject ) && StringUtils . isNotBlank ( resource ) && StringUtils . isNotBlank ( operation ) ; }
Checks if any of the given strings is blank
122,380
private void endRequest ( HttpServerExchange exchange ) { exchange . setStatusCode ( StatusCodes . UNAUTHORIZED ) ; Server . headers ( ) . entrySet ( ) . stream ( ) . filter ( entry -> StringUtils . isNotBlank ( entry . getValue ( ) ) ) . forEach ( entry -> exchange . getResponseHeaders ( ) . add ( entry . getKey ( ) ....
Ends the current request by sending a HTTP 401 status code and the default unauthorized template
122,381
public < T > ServiceGraphModule register ( Class < ? extends T > type , ServiceAdapter < T > factory ) { registeredServiceAdapters . put ( type , factory ) ; return this ; }
Puts an instance of class and its factory to the factoryMap
122,382
public < T > ServiceGraphModule registerForSpecificKey ( Key < T > key , ServiceAdapter < T > factory ) { keys . put ( key , factory ) ; return this ; }
Puts the key and its factory to the keys
122,383
public ServiceGraphModule addDependency ( Key < ? > key , Key < ? > keyDependency ) { addedDependencies . computeIfAbsent ( key , key1 -> new HashSet < > ( ) ) . add ( keyDependency ) ; return this ; }
Adds the dependency for key
122,384
public ServiceGraphModule removeDependency ( Key < ? > key , Key < ? > keyDependency ) { removedDependencies . computeIfAbsent ( key , key1 -> new HashSet < > ( ) ) . add ( keyDependency ) ; return this ; }
Removes the dependency
122,385
public ChannelInput < ByteBuf > getInput ( ) { return input -> { this . input = sanitize ( input ) ; if ( this . input != null && this . output != null ) startProcess ( ) ; return getProcessCompletion ( ) ; } ; }
check input for clarity
122,386
public < T > T getCurrentInstance ( Class < T > type ) { return getCurrentInstance ( Key . get ( type ) ) ; }
region getCurrentInstance overloads
122,387
public < T > Provider < T > getCurrentInstanceProvider ( Class < T > type ) { return getCurrentInstanceProvider ( Key . get ( type ) ) ; }
region getCurrentInstanceProvider overloads
122,388
public < T > List < T > getInstances ( Class < T > type ) { return getInstances ( Key . get ( type ) ) ; }
region getInstances overloads
122,389
public static AsyncFile open ( Executor executor , Path path , Set < OpenOption > openOptions ) throws IOException { FileChannel channel = doOpenChannel ( path , openOptions ) ; return new AsyncFile ( executor , channel , path , null ) ; }
Opens file synchronously .
122,390
public static Promise < Void > delete ( Executor executor , Path path ) { return ofBlockingRunnable ( executor , ( ) -> { try { Files . delete ( path ) ; } catch ( IOException e ) { throw new UncheckedException ( e ) ; } } ) ; }
Deletes the file concurrently .
122,391
public static Promise < Void > move ( Executor executor , Path source , Path target , CopyOption ... options ) { return ofBlockingRunnable ( executor , ( ) -> { try { Files . move ( source , target , options ) ; } catch ( IOException e ) { throw new UncheckedException ( e ) ; } } ) ; }
Moves or renames a file to a target file .
122,392
public static Promise < Void > createDirectories ( Executor executor , Path dir , FileAttribute ... attrs ) { return ofBlockingRunnable ( executor , ( ) -> { try { Files . createDirectories ( dir , attrs ) ; } catch ( IOException e ) { throw new UncheckedException ( e ) ; } } ) ; }
Creates a directory by creating all nonexistent parent directories first .
122,393
public Promise < Void > write ( ByteBuf buf ) { return sanitize ( ofBlockingRunnable ( executor , ( ) -> { synchronized ( mutexLock ) { try { int writtenBytes ; do { ByteBuffer byteBuffer = buf . toReadByteBuffer ( ) ; writtenBytes = channel . write ( byteBuffer ) ; buf . ofReadByteBuffer ( byteBuffer ) ; } while ( wri...
Writes all bytes of the buffer into this file at its internal position asynchronously .
122,394
public Promise < Void > forceAndClose ( boolean forceMetadata ) { if ( ! isOpen ( ) ) return Promise . ofException ( FILE_CLOSED ) ; return ofBlockingRunnable ( executor , ( ) -> { try { channel . force ( forceMetadata ) ; channel . close ( ) ; } catch ( IOException e ) { throw new UncheckedException ( e ) ; } } ) ; }
Forces physical write and then closes the channel if the file is opened .
122,395
public static < T > StreamSorterStorageImpl < T > create ( Executor executor , BinarySerializer < T > serializer , Path path ) { checkArgument ( ! path . getFileName ( ) . toString ( ) . contains ( "%d" ) , "Filename should not contain '%d'" ) ; try { Files . createDirectories ( path ) ; } catch ( IOException e ) { thr...
Creates a new storage
122,396
public Promise < StreamSupplier < T > > read ( int partition ) { Path path = partitionPath ( partition ) ; return AsyncFile . openAsync ( executor , path , set ( READ ) ) . map ( file -> ChannelFileReader . readFile ( file ) . withBufferSize ( readBlockSize ) . transformWith ( ChannelLZ4Decompressor . create ( ) ) . tr...
Returns supplier for reading data from this storage . It read it from external memory decompresses and deserializes it
122,397
public Promise < Void > cleanup ( List < Integer > partitionsToDelete ) { return Promise . ofBlockingCallable ( executor , ( ) -> { for ( Integer partitionToDelete : partitionsToDelete ) { Path path1 = partitionPath ( partitionToDelete ) ; try { Files . delete ( path1 ) ; } catch ( IOException e ) { logger . warn ( "Co...
Method which removes all creating files
122,398
public void resetStats ( ) { smoothedSum = 0.0 ; smoothedSqr = 0.0 ; smoothedCount = 0.0 ; smoothedMin = 0.0 ; smoothedMax = 0.0 ; lastMaxInteger = Integer . MIN_VALUE ; lastMinInteger = Integer . MAX_VALUE ; lastSumInteger = 0 ; lastSqrInteger = 0 ; lastCountInteger = 0 ; lastValueInteger = 0 ; lastMaxDouble = - Doubl...
Resets stats and sets new parameters
122,399
@ JmxAttribute ( optional = true ) public double getSmoothedStandardDeviation ( ) { if ( totalCount == 0 ) { return 0.0 ; } double avg = smoothedSum / smoothedCount ; double variance = smoothedSqr / smoothedCount - avg * avg ; if ( variance < 0.0 ) variance = 0.0 ; return sqrt ( variance ) ; }
Returns smoothed standard deviation