idx int64 0 165k | question stringlengths 73 4.15k | target stringlengths 5 918 | len_question int64 21 890 | len_target int64 3 255 |
|---|---|---|---|---|
16,500 | @ Nonnull public static < DATATYPE > SuccessWithValue < DATATYPE > createSuccess ( @ Nullable final DATATYPE aValue ) { return new SuccessWithValue <> ( ESuccess . SUCCESS , aValue ) ; } | Create a new success object with the given value . | 58 | 10 |
16,501 | @ Nonnull public static < DATATYPE > SuccessWithValue < DATATYPE > createFailure ( @ Nullable final DATATYPE aValue ) { return new SuccessWithValue <> ( ESuccess . FAILURE , aValue ) ; } | Create a new failure object with the given value . | 58 | 10 |
16,502 | @ Nonnull public static AuthIdentificationResult validateLoginCredentialsAndCreateToken ( @ Nonnull final IAuthCredentials aCredentials ) { ValueEnforcer . notNull ( aCredentials , "Credentials" ) ; // validate credentials final ICredentialValidationResult aValidationResult = AuthCredentialValidatorManager . validateCredentials ( aCredentials ) ; if ( aValidationResult . isFailure ( ) ) { if ( LOGGER . isWarnEnabled ( ) ) LOGGER . warn ( "Credentials have been rejected: " + aCredentials ) ; return AuthIdentificationResult . createFailure ( aValidationResult ) ; } if ( LOGGER . isDebugEnabled ( ) ) LOGGER . debug ( "Credentials have been accepted: " + aCredentials ) ; // try to get AuthSubject from passed credentials final IAuthSubject aSubject = AuthCredentialToSubjectResolverManager . getSubjectFromCredentials ( aCredentials ) ; if ( aSubject != null ) { if ( LOGGER . isDebugEnabled ( ) ) LOGGER . debug ( "Credentials " + aCredentials + " correspond to subject " + aSubject ) ; } else { if ( LOGGER . isErrorEnabled ( ) ) LOGGER . error ( "Failed to resolve credentials " + aCredentials + " to an auth subject!" ) ; } // Create the identification element final AuthIdentification aIdentification = new AuthIdentification ( aSubject ) ; // create the token (without expiration seconds) final IAuthToken aNewAuthToken = AuthTokenRegistry . createToken ( aIdentification , IAuthToken . EXPIRATION_SECONDS_INFINITE ) ; return AuthIdentificationResult . createSuccess ( aNewAuthToken ) ; } | Validate the login credentials try to resolve the subject and create a token upon success . | 390 | 17 |
16,503 | @ Nonnull public MimeTypeInfoManager read ( @ Nonnull final IReadableResource aRes ) { ValueEnforcer . notNull ( aRes , "Resource" ) ; final IMicroDocument aDoc = MicroReader . readMicroXML ( aRes ) ; if ( aDoc == null ) throw new IllegalArgumentException ( "Failed to read MimeTypeInfo resource " + aRes ) ; aDoc . getDocumentElement ( ) . forAllChildElements ( eItem -> { final MimeTypeInfo aInfo = MicroTypeConverter . convertToNative ( eItem , MimeTypeInfo . class ) ; registerMimeType ( aInfo ) ; } ) ; return this ; } | Read the information from the specified resource . | 151 | 8 |
16,504 | @ Nonnull public EChange clearCache ( ) { return m_aRWLock . writeLocked ( ( ) -> { EChange ret = m_aList . removeAll ( ) ; if ( ! m_aMapExt . isEmpty ( ) ) { m_aMapExt . clear ( ) ; ret = EChange . CHANGED ; } if ( ! m_aMapMimeType . isEmpty ( ) ) { m_aMapMimeType . clear ( ) ; ret = EChange . CHANGED ; } return ret ; } ) ; } | Remove all registered mime types | 121 | 6 |
16,505 | @ Nullable @ ReturnsMutableCopy public ICommonsList < MimeTypeInfo > getAllInfosOfExtension ( @ Nullable final String sExtension ) { // Extension may be empty! if ( sExtension == null ) return null ; return m_aRWLock . readLocked ( ( ) -> { ICommonsList < MimeTypeInfo > ret = m_aMapExt . get ( sExtension ) ; if ( ret == null ) { // Especially on Windows, sometimes file extensions like "JPG" can be // found. Therefore also test for the lowercase version of the // extension. ret = m_aMapExt . get ( sExtension . toLowerCase ( Locale . US ) ) ; } // Create a copy if present return ret == null ? null : ret . getClone ( ) ; } ) ; } | Get all infos associated with the specified filename extension . | 183 | 11 |
16,506 | @ Nullable @ ReturnsMutableCopy public ICommonsList < MimeTypeInfo > getAllInfosOfMimeType ( @ Nullable final IMimeType aMimeType ) { if ( aMimeType == null ) return null ; final ICommonsList < MimeTypeInfo > ret = m_aRWLock . readLocked ( ( ) -> m_aMapMimeType . get ( aMimeType ) ) ; // Create a copy if present return ret == null ? null : ret . getClone ( ) ; } | Get all infos associated with the passed mime type . | 118 | 12 |
16,507 | public boolean containsMimeTypeForFilename ( @ Nonnull @ Nonempty final String sFilename ) { ValueEnforcer . notEmpty ( sFilename , "Filename" ) ; final String sExtension = FilenameHelper . getExtension ( sFilename ) ; return containsMimeTypeForExtension ( sExtension ) ; } | Check if any mime type is registered for the extension of the specified filename . | 69 | 16 |
16,508 | public boolean containsMimeTypeForExtension ( @ Nonnull final String sExtension ) { ValueEnforcer . notNull ( sExtension , "Extension" ) ; final ICommonsList < MimeTypeInfo > aInfos = getAllInfosOfExtension ( sExtension ) ; return CollectionHelper . isNotEmpty ( aInfos ) ; } | Check if any mime type is associated with the passed extension | 79 | 12 |
16,509 | @ Nonnull public final XMLWriterSettings setSerializeVersion ( @ Nonnull final EXMLSerializeVersion eSerializeVersion ) { m_eSerializeVersion = ValueEnforcer . notNull ( eSerializeVersion , "Version" ) ; m_eXMLVersion = eSerializeVersion . getXMLVersionOrDefault ( EXMLVersion . XML_10 ) ; return this ; } | Set the preferred XML version to use . | 84 | 8 |
16,510 | @ Nonnull public final XMLWriterSettings setSerializeXMLDeclaration ( @ Nonnull final EXMLSerializeXMLDeclaration eSerializeXMLDecl ) { m_eSerializeXMLDecl = ValueEnforcer . notNull ( eSerializeXMLDecl , "SerializeXMLDecl" ) ; return this ; } | Set the way how to handle the XML declaration . | 72 | 10 |
16,511 | @ Nonnull public final XMLWriterSettings setSerializeDocType ( @ Nonnull final EXMLSerializeDocType eSerializeDocType ) { m_eSerializeDocType = ValueEnforcer . notNull ( eSerializeDocType , "SerializeDocType" ) ; return this ; } | Set the way how to handle the doc type . | 64 | 10 |
16,512 | @ Nonnull public final XMLWriterSettings setSerializeComments ( @ Nonnull final EXMLSerializeComments eSerializeComments ) { m_eSerializeComments = ValueEnforcer . notNull ( eSerializeComments , "SerializeComments" ) ; return this ; } | Set the way how comments should be handled . | 58 | 9 |
16,513 | @ Nonnull public final XMLWriterSettings setIncorrectCharacterHandling ( @ Nonnull final EXMLIncorrectCharacterHandling eIncorrectCharacterHandling ) { m_eIncorrectCharacterHandling = ValueEnforcer . notNull ( eIncorrectCharacterHandling , "IncorrectCharacterHandling" ) ; return this ; } | Set the way how to handle invalid characters . | 70 | 9 |
16,514 | @ Nonnull public final XMLWriterSettings setCharset ( @ Nonnull final Charset aCharset ) { m_aCharset = ValueEnforcer . notNull ( aCharset , "Charset" ) ; return this ; } | Set the serialization charset . | 56 | 7 |
16,515 | @ Nonnull public final XMLWriterSettings setNamespaceContext ( @ Nullable final INamespaceContext aNamespaceContext ) { // A namespace context must always be present, to resolve default namespaces m_aNamespaceContext = aNamespaceContext != null ? aNamespaceContext : new MapBasedNamespaceContext ( ) ; return this ; } | Set the namespace context to be used . | 73 | 8 |
16,516 | @ Nonnull @ Nonempty private static String _getUnifiedDecimal ( @ Nonnull @ Nonempty final String sStr ) { return StringHelper . replaceAll ( sStr , ' ' , ' ' ) ; } | Get the unified decimal string for parsing by the runtime library . This is done by replacing with . . | 46 | 20 |
16,517 | public static boolean isDouble ( @ Nullable final String sStr ) { return ! Double . isNaN ( parseDouble ( sStr , Double . NaN ) ) ; } | Checks if the given string is a double string that can be converted to a double value . | 37 | 19 |
16,518 | public static boolean isFloat ( @ Nullable final String sStr ) { return ! Float . isNaN ( parseFloat ( sStr , Float . NaN ) ) ; } | Checks if the given string is a float string that can be converted to a double value . | 37 | 19 |
16,519 | public static < T > boolean identityEqual ( @ Nullable final T aObj1 , @ Nullable final T aObj2 ) { return aObj1 == aObj2 ; } | The only place where objects are compared by identity . | 39 | 10 |
16,520 | @ Nonnull public ICommonsList < String > next ( ) { final ICommonsList < String > ret = m_aNextLine ; if ( ret == null ) throw new NoSuchElementException ( ) ; try { m_aNextLine = m_aReader . readNext ( ) ; } catch ( final IOException ex ) { throw new IllegalStateException ( "Failed to read next CSV line" , ex ) ; } return ret ; } | Returns the next element in the iterator . | 97 | 8 |
16,521 | @ Nonnull public static < DATATYPE , ITEMTYPE extends ITreeItemWithID < String , DATATYPE , ITEMTYPE > > IMicroElement getTreeWithStringIDAsXML ( @ Nonnull final IBasicTree < DATATYPE , ITEMTYPE > aTree , @ Nonnull final IConverterTreeItemToMicroNode < ? super DATATYPE > aConverter ) { return getTreeWithIDAsXML ( aTree , IHasID . getComparatorID ( ) , x -> x , aConverter ) ; } | Specialized conversion method for converting a tree with ID to a standardized XML tree . | 130 | 16 |
16,522 | public void forEachResourceError ( @ Nonnull final Consumer < ? super IError > aConsumer ) { ValueEnforcer . notNull ( aConsumer , "Consumer" ) ; m_aRWLock . readLocked ( ( ) -> m_aErrors . forEach ( aConsumer ) ) ; } | Call the provided consumer for all contained resource errors . | 65 | 10 |
16,523 | @ MustBeLocked ( ELockType . WRITE ) private void _addItem ( @ Nonnull final IMPLTYPE aItem , @ Nonnull final EDAOActionType eActionType ) { ValueEnforcer . notNull ( aItem , "Item" ) ; ValueEnforcer . isTrue ( eActionType == EDAOActionType . CREATE || eActionType == EDAOActionType . UPDATE , "Invalid action type provided!" ) ; final String sID = aItem . getID ( ) ; final IMPLTYPE aOldItem = m_aMap . get ( sID ) ; if ( eActionType == EDAOActionType . CREATE ) { if ( aOldItem != null ) throw new IllegalArgumentException ( ClassHelper . getClassLocalName ( getDataTypeClass ( ) ) + " with ID '" + sID + "' is already in use and can therefore not be created again. Old item = " + aOldItem + "; New item = " + aItem ) ; } else { // Update if ( aOldItem == null ) throw new IllegalArgumentException ( ClassHelper . getClassLocalName ( getDataTypeClass ( ) ) + " with ID '" + sID + "' is not yet in use and can therefore not be updated! Updated item = " + aItem ) ; } m_aMap . put ( sID , aItem ) ; } | Add or update an item . Must only be invoked inside a write - lock . | 301 | 16 |
16,524 | @ Nullable @ IsLocked ( ELockType . READ ) protected final IMPLTYPE getOfID ( @ Nullable final String sID ) { if ( StringHelper . hasNoText ( sID ) ) return null ; return m_aRWLock . readLocked ( ( ) -> m_aMap . get ( sID ) ) ; } | Find the element with the provided ID . Locking is done internally . | 75 | 14 |
16,525 | @ Nullable @ IsLocked ( ELockType . READ ) protected final INTERFACETYPE getAtIndex ( @ Nonnegative final int nIndex ) { return m_aRWLock . readLocked ( ( ) -> CollectionHelper . getAtIndex ( m_aMap . values ( ) , nIndex ) ) ; } | Get the item at the specified index . This method only returns defined results if an ordered map is used for data storage . | 71 | 24 |
16,526 | public static int getWeekDays ( @ Nonnull final LocalDate aStartDate , @ Nonnull final LocalDate aEndDate ) { ValueEnforcer . notNull ( aStartDate , "StartDate" ) ; ValueEnforcer . notNull ( aEndDate , "EndDate" ) ; final boolean bFlip = aStartDate . isAfter ( aEndDate ) ; LocalDate aCurDate = bFlip ? aEndDate : aStartDate ; final LocalDate aRealEndDate = bFlip ? aStartDate : aEndDate ; int ret = 0 ; while ( ! aRealEndDate . isBefore ( aCurDate ) ) { if ( ! isWeekend ( aCurDate ) ) ret ++ ; aCurDate = aCurDate . plusDays ( 1 ) ; } return bFlip ? - 1 * ret : ret ; } | Count all non - weekend days in the range . Does not consider holidays! | 183 | 15 |
16,527 | public static int getEndWeekOfMonth ( @ Nonnull final LocalDateTime aDT , @ Nonnull final Locale aLocale ) { return getWeekOfWeekBasedYear ( aDT . plusMonths ( 1 ) . withDayOfMonth ( 1 ) . minusDays ( 1 ) , aLocale ) ; } | Get the end - week number for the passed year and month . | 68 | 13 |
16,528 | public static boolean birthdayEquals ( @ Nullable final LocalDate aDate1 , @ Nullable final LocalDate aDate2 ) { return birthdayCompare ( aDate1 , aDate2 ) == 0 ; } | Check if the two birthdays are equal . Equal birthdays are identified by equal months and equal days . | 44 | 21 |
16,529 | public static boolean isInstancableClass ( @ Nullable final Class < ? > aClass ) { if ( ! isPublicClass ( aClass ) ) return false ; // Check if a default constructor is present try { aClass . getConstructor ( ( Class < ? > [ ] ) null ) ; } catch ( final NoSuchMethodException ex ) { return false ; } return true ; } | Check if the passed class is public instancable and has a no - argument constructor . | 82 | 18 |
16,530 | public static boolean isInterface ( @ Nullable final Class < ? > aClass ) { return aClass != null && Modifier . isInterface ( aClass . getModifiers ( ) ) ; } | Check if the passed class is an interface or not . Please note that annotations are also interfaces! | 41 | 19 |
16,531 | @ Nullable public static Class < ? > getPrimitiveWrapperClass ( @ Nullable final Class < ? > aClass ) { if ( isPrimitiveWrapperType ( aClass ) ) return aClass ; return PRIMITIVE_TO_WRAPPER . get ( aClass ) ; } | Get the primitive wrapper class of the passed primitive class . | 64 | 11 |
16,532 | @ Nullable public static Class < ? > getPrimitiveClass ( @ Nullable final Class < ? > aClass ) { if ( isPrimitiveType ( aClass ) ) return aClass ; return WRAPPER_TO_PRIMITIVE . get ( aClass ) ; } | Get the primitive class of the passed primitive wrapper class . | 60 | 11 |
16,533 | public static boolean areConvertibleClasses ( @ Nonnull final Class < ? > aSrcClass , @ Nonnull final Class < ? > aDstClass ) { ValueEnforcer . notNull ( aSrcClass , "SrcClass" ) ; ValueEnforcer . notNull ( aDstClass , "DstClass" ) ; // Same class? if ( aDstClass . equals ( aSrcClass ) ) return true ; // Default assignable if ( aDstClass . isAssignableFrom ( aSrcClass ) ) return true ; // Special handling for "int.class" == "Integer.class" etc. if ( aDstClass == getPrimitiveWrapperClass ( aSrcClass ) ) return true ; if ( aDstClass == getPrimitiveClass ( aSrcClass ) ) return true ; // Not convertible return false ; } | Check if the passed classes are convertible . Includes conversion checks between primitive types and primitive wrapper types . | 191 | 19 |
16,534 | @ Nullable public static String getClassLocalName ( @ Nullable final Object aObject ) { return aObject == null ? null : getClassLocalName ( aObject . getClass ( ) ) ; } | Get the name of the object s class without the package . | 43 | 12 |
16,535 | @ Nullable public static String getClassPackageName ( @ Nullable final Object aObject ) { return aObject == null ? null : getClassPackageName ( aObject . getClass ( ) ) ; } | Get the name of the package the passed object resides in . | 43 | 12 |
16,536 | @ Nullable public static String getDirectoryFromPackage ( @ Nullable final Package aPackage ) { // No differentiation return aPackage == null ? null : getPathFromClass ( aPackage . getName ( ) ) ; } | Convert a package name to a relative directory name . | 46 | 11 |
16,537 | @ Nonnull @ Nonempty public static String getObjectAddress ( @ Nullable final Object aObject ) { if ( aObject == null ) return "0x00000000" ; return "0x" + StringHelper . getHexStringLeadingZero ( System . identityHashCode ( aObject ) , 8 ) ; } | Get the hex representation of the passed object s address . Note that this method makes no differentiation between 32 and 64 bit architectures . The result is always a hexadecimal value preceded by 0x and followed by exactly 8 characters . | 67 | 46 |
16,538 | public static void visitStatistics ( @ Nonnull final IStatisticsVisitorCallback aCallback ) { ValueEnforcer . notNull ( aCallback , "Callback" ) ; // For all cache handler ICommonsList < String > aHandlers = StatisticsManager . getAllCacheHandler ( ) . getSorted ( Comparator . naturalOrder ( ) ) ; for ( final String sName : aHandlers ) { final IStatisticsHandlerCache aHandler = StatisticsManager . getCacheHandler ( sName ) ; aCallback . onCache ( sName , aHandler ) ; } // For all timer handler aHandlers = StatisticsManager . getAllTimerHandler ( ) . getSorted ( Comparator . naturalOrder ( ) ) ; for ( final String sName : aHandlers ) { final IStatisticsHandlerTimer aHandler = StatisticsManager . getTimerHandler ( sName ) ; aCallback . onTimer ( sName , aHandler ) ; } // For all keyed timer handler aHandlers = StatisticsManager . getAllKeyedTimerHandler ( ) . getSorted ( Comparator . naturalOrder ( ) ) ; for ( final String sName : aHandlers ) { final IStatisticsHandlerKeyedTimer aHandler = StatisticsManager . getKeyedTimerHandler ( sName ) ; aCallback . onKeyedTimer ( sName , aHandler ) ; } // For all size handler aHandlers = StatisticsManager . getAllSizeHandler ( ) . getSorted ( Comparator . naturalOrder ( ) ) ; for ( final String sName : aHandlers ) { final IStatisticsHandlerSize aHandler = StatisticsManager . getSizeHandler ( sName ) ; aCallback . onSize ( sName , aHandler ) ; } // For all keyed size handler aHandlers = StatisticsManager . getAllKeyedSizeHandler ( ) . getSorted ( Comparator . naturalOrder ( ) ) ; for ( final String sName : aHandlers ) { final IStatisticsHandlerKeyedSize aHandler = StatisticsManager . getKeyedSizeHandler ( sName ) ; aCallback . onKeyedSize ( sName , aHandler ) ; } // For all counter handler aHandlers = StatisticsManager . getAllCounterHandler ( ) . getSorted ( Comparator . naturalOrder ( ) ) ; for ( final String sName : aHandlers ) { final IStatisticsHandlerCounter aHandler = StatisticsManager . getCounterHandler ( sName ) ; aCallback . onCounter ( sName , aHandler ) ; } // For all keyed counter handler aHandlers = StatisticsManager . getAllKeyedCounterHandler ( ) . getSorted ( Comparator . naturalOrder ( ) ) ; for ( final String sName : aHandlers ) { final IStatisticsHandlerKeyedCounter aHandler = StatisticsManager . getKeyedCounterHandler ( sName ) ; aCallback . onKeyedCounter ( sName , aHandler ) ; } } | Walk all available statistics elements with the passed statistics visitor . | 611 | 11 |
16,539 | public final void reset ( ) { for ( int i = 0 ; i < m_aIndexResult . length ; i ++ ) m_aIndexResult [ i ] = i ; m_aCombinationsLeft = m_aTotalCombinations ; m_nCombinationsLeft = m_nTotalCombinations ; } | Reset the generator | 67 | 4 |
16,540 | @ Nonnull public static < DATATYPE > ICommonsList < ICommonsList < DATATYPE > > getAllPermutations ( @ Nonnull @ Nonempty final ICommonsList < DATATYPE > aInput , @ Nonnegative final int nSlotCount ) { final ICommonsList < ICommonsList < DATATYPE > > aResultList = new CommonsArrayList <> ( ) ; addAllPermutations ( aInput , nSlotCount , aResultList ) ; return aResultList ; } | Get a list of all permutations of the input elements . | 121 | 12 |
16,541 | public static < DATATYPE > void addAllPermutations ( @ Nonnull @ Nonempty final ICommonsList < DATATYPE > aInput , @ Nonnegative final int nSlotCount , @ Nonnull final Collection < ICommonsList < DATATYPE > > aResultList ) { for ( final ICommonsList < DATATYPE > aPermutation : new CombinationGenerator <> ( aInput , nSlotCount ) ) aResultList . ( aPermutation ) ; } | Fill a list with all permutations of the input elements . | 116 | 12 |
16,542 | @ OverrideOnDemand protected void onInsertBefore ( @ Nonnull final AbstractMicroNode aChildNode , @ Nonnull final IMicroNode aSuccessor ) { throw new MicroException ( "Cannot insert children in class " + getClass ( ) . getName ( ) ) ; } | Callback that is invoked once a child is to be inserted before another child . | 60 | 15 |
16,543 | @ OverrideOnDemand protected void onInsertAfter ( @ Nonnull final AbstractMicroNode aChildNode , @ Nonnull final IMicroNode aPredecessor ) { throw new MicroException ( "Cannot insert children in class " + getClass ( ) . getName ( ) ) ; } | Callback that is invoked once a child is to be inserted after another child . | 61 | 15 |
16,544 | @ OverrideOnDemand protected void onInsertAtIndex ( @ Nonnegative final int nIndex , @ Nonnull final AbstractMicroNode aChildNode ) { throw new MicroException ( "Cannot insert children in class " + getClass ( ) . getName ( ) ) ; } | Callback that is invoked once a child is to be inserted at the specified index . | 58 | 16 |
16,545 | @ Nonnull @ ReturnsMutableCopy public static ByteArrayWrapper create ( @ Nonnull final String sText , @ Nonnull final Charset aCharset ) { return new ByteArrayWrapper ( sText . getBytes ( aCharset ) , false ) ; } | Wrap the content of a String in a certain charset . | 60 | 13 |
16,546 | @ Nullable public static byte [ ] getAllFileBytes ( @ Nullable final File aFile ) { return aFile == null ? null : StreamHelper . getAllBytes ( FileHelper . getInputStream ( aFile ) ) ; } | Get the content of the file as a byte array . | 50 | 11 |
16,547 | @ Nullable public static String stripBidi ( @ Nullable final String sStr ) { if ( sStr == null || sStr . length ( ) <= 1 ) return sStr ; String ret = sStr ; if ( isBidi ( ret . charAt ( 0 ) ) ) ret = ret . substring ( 1 ) ; if ( isBidi ( ret . charAt ( ret . length ( ) - 1 ) ) ) ret = ret . substring ( 0 , ret . length ( ) - 1 ) ; return ret ; } | Removes leading and trailing bidi controls from the string | 113 | 11 |
16,548 | @ Nullable public static String wrapBidi ( @ Nullable final String sStr , final char cChar ) { switch ( cChar ) { case RLE : return _wrap ( sStr , RLE , PDF ) ; case RLO : return _wrap ( sStr , RLO , PDF ) ; case LRE : return _wrap ( sStr , LRE , PDF ) ; case LRO : return _wrap ( sStr , LRO , PDF ) ; case RLM : return _wrap ( sStr , RLM , RLM ) ; case LRM : return _wrap ( sStr , LRM , LRM ) ; default : return sStr ; } } | Wrap the string with the specified bidi control | 142 | 10 |
16,549 | public < T extends OmiseObject > T deserialize ( InputStream input , Class < T > klass ) throws IOException { return objectMapper . readerFor ( klass ) . readValue ( input ) ; } | Deserialize an instance of the given class from the input stream . | 47 | 14 |
16,550 | public < T extends OmiseObject > T deserialize ( InputStream input , TypeReference < T > ref ) throws IOException { return objectMapper . readerFor ( ref ) . readValue ( input ) ; } | Deserialize an instance of the given type reference from the input stream . | 46 | 15 |
16,551 | public < T extends OmiseObject > T deserializeFromMap ( Map < String , Object > map , Class < T > klass ) { return objectMapper . convertValue ( map , klass ) ; } | Deserialize an instance of the given class from the map . | 46 | 13 |
16,552 | public < T extends OmiseObject > T deserializeFromMap ( Map < String , Object > map , TypeReference < T > ref ) { return objectMapper . convertValue ( map , ref ) ; } | Deserialize an instance of the given type reference from the map . | 45 | 14 |
16,553 | public < T extends OmiseObject > void serialize ( OutputStream output , T model ) throws IOException { objectMapper . writerFor ( model . getClass ( ) ) . writeValue ( output , model ) ; } | Serializes the given model to the output stream . | 47 | 10 |
16,554 | public < T extends Params > void serializeParams ( OutputStream output , T param ) throws IOException { // TODO: Add params-specific options. objectMapper . writerFor ( param . getClass ( ) ) . writeValue ( output , param ) ; } | Serializes the given parameter object to the output stream . | 58 | 11 |
16,555 | public < T extends OmiseObject > Map < String , Object > serializeToMap ( T model ) { return objectMapper . convertValue ( model , new TypeReference < Map < String , Object > > ( ) { } ) ; } | Serialize the given model to a map with JSON - like structure . | 51 | 14 |
16,556 | public < T extends Enum < T > > String serializeToQueryParams ( T value ) { return ( String ) objectMapper . convertValue ( value , String . class ) ; } | Serialize the given model to a representation suitable for using as URL query parameters . | 41 | 16 |
16,557 | public static Function < HttpRequest , String > PREFIXED_REQUEST_METHOD_NAME ( final String prefix ) { return ( request ) - > replaceIfNull ( prefix , "" ) + replaceIfNull ( request . getRequestLine ( ) . getMethod ( ) , "unknown" ) ; } | A configurable version of REQUEST_METHOD_NAME | 64 | 11 |
16,558 | public static Function < HttpRequest , String > PREFIXED_REQUEST_TARGET_NAME ( final String prefix ) { return ( request ) - > replaceIfNull ( prefix , "" ) + replaceIfNull ( standardizeUri ( request . getRequestLine ( ) . getUri ( ) ) , "unknown" ) ; } | A configurable version of REQUEST_TARGET_NAME | 72 | 12 |
16,559 | public static Function < HttpRequest , String > PREFIXED_REQUEST_METHOD_TARGET_NAME ( final String prefix ) { return ( request ) - > replaceIfNull ( prefix , "" ) + replaceIfNull ( request . getRequestLine ( ) . getMethod ( ) , "unknown" ) + " " + replaceIfNull ( standardizeUri ( request . getRequestLine ( ) . getUri ( ) ) , "unknown" ) ; } | A configurable version of REQUEST_METHOD_TARGET_NAME | 99 | 14 |
16,560 | private static String standardizeUri ( String uri ) { return ( uri == null ) ? null : regexIDPattern . matcher ( regexTaskIDPattern . matcher ( regexParameterPattern . matcher ( uri ) . replaceFirst ( "" ) ) . replaceAll ( "task_id:\\?" ) ) . replaceAll ( "/\\?$1" ) ; } | Using regexes derived from the Elasticsearch 5 . 6 HTTP API this method removes additional parameters in the request and replaces numerical IDs with ? to reduce granularity . | 81 | 32 |
16,561 | private SpanContext extract ( HttpRequest request ) { SpanContext spanContext = tracer . extract ( Format . Builtin . HTTP_HEADERS , new HttpTextMapExtractAdapter ( request ) ) ; if ( spanContext != null ) { return spanContext ; } Span span = tracer . activeSpan ( ) ; if ( span != null ) { return span . context ( ) ; } return null ; } | Extract context from headers or from active Span | 88 | 9 |
16,562 | public String build ( Class < ? > clazz ) { String packageName = clazz . getPackage ( ) . getName ( ) ; String formattedPackageName = packageName . replace ( "." , "/" ) ; return formattedPackageName + "/" + clazz . getSimpleName ( ) + "-BeanohContext.xml" ; } | Builds a bootstrap name with the same name as the test plus - BeanohContext . xml . | 73 | 21 |
16,563 | @ Override public Object intercept ( Object object , Method method , Object [ ] args , MethodProxy methodProxy ) throws Throwable { Method delegateMethod = delegateClass . getMethod ( method . getName ( ) , method . getParameterTypes ( ) ) ; if ( "registerBeanDefinition" . equals ( method . getName ( ) ) ) { if ( beanDefinitionMap . containsKey ( args [ 0 ] ) ) { List < BeanDefinition > definitions = beanDefinitionMap . get ( args [ 0 ] ) ; definitions . add ( ( BeanDefinition ) args [ 1 ] ) ; } else { List < BeanDefinition > beanDefinitions = new ArrayList < BeanDefinition > ( ) ; beanDefinitions . add ( ( BeanDefinition ) args [ 1 ] ) ; beanDefinitionMap . put ( ( String ) args [ 0 ] , beanDefinitions ) ; } } return delegateMethod . invoke ( delegate , args ) ; } | Intercepts method calls to the proxy and calls the corresponding method on the delegate . | 193 | 17 |
16,564 | public void assertUniqueBeans ( Set < String > ignoredDuplicateBeanNames ) { for ( BeanohBeanFactoryMethodInterceptor callback : callbacks ) { Map < String , List < BeanDefinition > > beanDefinitionMap = callback . getBeanDefinitionMap ( ) ; for ( String key : beanDefinitionMap . keySet ( ) ) { if ( ! ignoredDuplicateBeanNames . contains ( key ) ) { List < BeanDefinition > definitions = beanDefinitionMap . get ( key ) ; List < String > resourceDescriptions = new ArrayList < String > ( ) ; for ( BeanDefinition definition : definitions ) { String resourceDescription = definition . getResourceDescription ( ) ; if ( resourceDescription == null ) { resourceDescriptions . add ( definition . getBeanClassName ( ) ) ; } else if ( ! resourceDescription . endsWith ( "-BeanohContext.xml]" ) ) { if ( ! resourceDescriptions . contains ( resourceDescription ) ) { resourceDescriptions . add ( resourceDescription ) ; } } } if ( resourceDescriptions . size ( ) > 1 ) { throw new DuplicateBeanDefinitionException ( "Bean '" + key + "' was defined " + resourceDescriptions . size ( ) + " times.\n" + "Either remove duplicate bean definitions or ignore them with the 'ignoredDuplicateBeanNames' method.\n" + "Configuration locations:" + messageUtil . list ( resourceDescriptions ) ) ; } } } } } | This will fail if there are duplicate beans in the Spring context . Beans that are configured in the bootstrap context will not be considered duplicate beans . | 326 | 29 |
16,565 | public String list ( List < String > messages ) { List < String > sortedComponents = new ArrayList < String > ( messages ) ; Collections . sort ( sortedComponents ) ; String output = "" ; for ( String component : sortedComponents ) { output += "\n" + component ; } return output ; } | Separates messages on different lines for error messages . | 66 | 11 |
16,566 | public synchronized void stopThrow ( ) throws JMException { if ( connector != null ) { try { connector . stop ( ) ; } catch ( IOException e ) { throw createJmException ( "Could not stop our Jmx connector server" , e ) ; } finally { connector = null ; } } if ( rmiRegistry != null ) { try { UnicastRemoteObject . unexportObject ( rmiRegistry , true ) ; } catch ( NoSuchObjectException e ) { throw createJmException ( "Could not unexport our RMI registry" , e ) ; } finally { rmiRegistry = null ; } } if ( serverHostNamePropertySet ) { System . clearProperty ( RMI_SERVER_HOST_NAME_PROPERTY ) ; serverHostNamePropertySet = false ; } } | Stop the JMX server by closing the connector and unpublishing it from the RMI registry . This throws a JMException on any issues . | 174 | 29 |
16,567 | public synchronized ObjectName register ( PublishAllBeanWrapper wrapper ) throws JMException { ReflectionMbean mbean ; try { mbean = new ReflectionMbean ( wrapper ) ; } catch ( Exception e ) { throw createJmException ( "Could not build mbean object for publish-all bean: " + wrapper . getTarget ( ) , e ) ; } ObjectName objectName = ObjectNameUtil . makeObjectName ( wrapper . getJmxResourceInfo ( ) ) ; doRegister ( objectName , mbean ) ; return objectName ; } | Register the object parameter for exposure with JMX that is wrapped using the PublishAllBeanWrapper . | 119 | 22 |
16,568 | public static Object stringToParam ( String string , String typeString ) throws IllegalArgumentException { if ( typeString . equals ( "boolean" ) || typeString . equals ( "java.lang.Boolean" ) ) { return Boolean . parseBoolean ( string ) ; } else if ( typeString . equals ( "char" ) || typeString . equals ( "java.lang.Character" ) ) { if ( string . length ( ) == 0 ) { // not sure what to do here return ' ' ; } else { return string . toCharArray ( ) [ 0 ] ; } } else if ( typeString . equals ( "byte" ) || typeString . equals ( "java.lang.Byte" ) ) { return Byte . parseByte ( string ) ; } else if ( typeString . equals ( "short" ) || typeString . equals ( "java.lang.Short" ) ) { return Short . parseShort ( string ) ; } else if ( typeString . equals ( "int" ) || typeString . equals ( "java.lang.Integer" ) ) { return Integer . parseInt ( string ) ; } else if ( typeString . equals ( "long" ) || typeString . equals ( "java.lang.Long" ) ) { return Long . parseLong ( string ) ; } else if ( typeString . equals ( "java.lang.String" ) ) { return string ; } else if ( typeString . equals ( "float" ) || typeString . equals ( "java.lang.Float" ) ) { return Float . parseFloat ( string ) ; } else if ( typeString . equals ( "double" ) || typeString . equals ( "java.lang.Double" ) ) { return Double . parseDouble ( string ) ; } else { Constructor < ? > constr = getConstructor ( typeString ) ; try { return constr . newInstance ( new Object [ ] { string } ) ; } catch ( Exception e ) { throw new IllegalArgumentException ( "Could not get new instance using string constructor for type " + typeString ) ; } } } | Convert a string to an object based on the type string . | 447 | 13 |
16,569 | public static String valueToString ( Object value ) { if ( value == null ) { return "null" ; } else if ( ! value . getClass ( ) . isArray ( ) ) { return value . toString ( ) ; } StringBuilder sb = new StringBuilder ( ) ; valueToString ( sb , value ) ; return sb . toString ( ) ; } | Return the string version of value . | 81 | 7 |
16,570 | public static String displayType ( String className , Object value ) { if ( className == null ) { return null ; } boolean array = false ; if ( className . equals ( "[J" ) ) { array = true ; if ( value == null ) { className = "unknown" ; } else if ( value instanceof boolean [ ] ) { className = "boolean" ; } else if ( value instanceof byte [ ] ) { className = "byte" ; } else if ( value instanceof char [ ] ) { className = "char" ; } else if ( value instanceof short [ ] ) { className = "short" ; } else if ( value instanceof int [ ] ) { className = "int" ; } else if ( value instanceof long [ ] ) { className = "long" ; } else if ( value instanceof float [ ] ) { className = "float" ; } else if ( value instanceof double [ ] ) { className = "double" ; } else { className = "unknown" ; } } else if ( className . startsWith ( "[L" ) ) { className = className . substring ( 2 , className . length ( ) - 1 ) ; } if ( className . startsWith ( "java.lang." ) ) { className = className . substring ( 10 ) ; } else if ( className . startsWith ( "javax.management.openmbean." ) ) { className = className . substring ( 27 ) ; } if ( array ) { return "array of " + className ; } else { return className ; } } | Display type string from class name string . | 352 | 8 |
16,571 | public void runCommands ( final String [ ] commands ) throws IOException { doLines ( 0 , new LineReader ( ) { private int commandC = 0 ; @ Override public String getNextLine ( String prompt ) { if ( commandC >= commands . length ) { return null ; } else { return commands [ commandC ++ ] ; } } } , true ) ; } | Run commands from the String array . | 80 | 7 |
16,572 | public void runBatchFile ( File batchFile ) throws IOException { final BufferedReader reader = new BufferedReader ( new FileReader ( batchFile ) ) ; try { doLines ( 0 , new LineReader ( ) { @ Override public String getNextLine ( String prompt ) throws IOException { return reader . readLine ( ) ; } } , true ) ; } finally { reader . close ( ) ; } } | Read in commands from the batch - file and execute them . | 90 | 12 |
16,573 | private void doLines ( int levelC , LineReader lineReader , boolean batch ) throws IOException { if ( levelC > 20 ) { System . out . print ( "Ignoring possible recursion after including 20 times" ) ; return ; } while ( true ) { String line = lineReader . getNextLine ( DEFAULT_PROMPT ) ; if ( line == null ) { break ; } // skip blank lines and comments if ( line . length ( ) == 0 || line . startsWith ( "#" ) || line . startsWith ( "//" ) ) { continue ; } if ( batch ) { // if we are in batch mode, spit out the line we just read System . out . println ( "> " + line ) ; } String [ ] lineParts = line . split ( " " ) ; String command = lineParts [ 0 ] ; if ( command . startsWith ( HELP_COMMAND ) ) { helpOutput ( ) ; } else if ( command . startsWith ( "objects" ) ) { listBeans ( lineParts ) ; } else if ( command . startsWith ( "run" ) ) { if ( lineParts . length == 2 ) { runScript ( lineParts [ 1 ] , levelC ) ; } else { System . out . println ( "Error. Usage: run script" ) ; } } else if ( command . startsWith ( "attrs" ) ) { listAttributes ( lineParts ) ; } else if ( command . startsWith ( "get" ) ) { if ( lineParts . length == 2 ) { getAttributes ( lineParts ) ; } else { getAttribute ( lineParts ) ; } } else if ( command . startsWith ( "set" ) ) { setAttribute ( lineParts ) ; } else if ( command . startsWith ( "opers" ) || command . startsWith ( "ops" ) ) { listOperations ( lineParts ) ; } else if ( command . startsWith ( "dolines" ) ) { invokeOperationLines ( lineReader , lineParts , batch ) ; } else if ( command . startsWith ( "do" ) ) { invokeOperation ( lineParts ) ; } else if ( command . startsWith ( "sleep" ) ) { if ( lineParts . length == 2 ) { try { Thread . sleep ( Long . parseLong ( lineParts [ 1 ] ) ) ; } catch ( NumberFormatException e ) { System . out . println ( "Error. Usage: sleep millis, invalid millis number '" + lineParts [ 1 ] + "'" ) ; } catch ( InterruptedException e ) { Thread . currentThread ( ) . interrupt ( ) ; return ; } } else { System . out . println ( "Error. Usage: sleep millis" ) ; } } else if ( command . startsWith ( "examples" ) ) { exampleOutput ( ) ; } else if ( command . startsWith ( "quit" ) ) { break ; } else { System . out . println ( "Error. Unknown command. Type '" + HELP_COMMAND + "' for help: " + command ) ; } } } | Do the lines from the reader . This might go recursive if we run a script . | 660 | 17 |
16,574 | private void runScript ( String alias , int levelC ) throws IOException { String scriptFile = alias ; InputStream stream ; try { stream = getInputStream ( scriptFile ) ; if ( stream == null ) { System . out . println ( "Error. Script file is not found: " + scriptFile ) ; return ; } } catch ( IOException e ) { System . out . println ( "Error. Could not load script file " + scriptFile + ": " + e . getMessage ( ) ) ; return ; } final BufferedReader reader = new BufferedReader ( new InputStreamReader ( stream ) ) ; try { doLines ( levelC + 1 , new LineReader ( ) { @ Override public String getNextLine ( String prompt ) throws IOException { return reader . readLine ( ) ; } } , true ) ; } finally { reader . close ( ) ; } } | Run a script . This might go recursive if we run from within a script . | 189 | 16 |
16,575 | private MBeanInfo buildMbeanInfo ( JmxAttributeFieldInfo [ ] attributeFieldInfos , JmxAttributeMethodInfo [ ] attributeMethodInfos , JmxOperationInfo [ ] operationInfos , boolean ignoreErrors ) { // NOTE: setup the maps that track previous class configuration Map < String , JmxAttributeFieldInfo > attributeFieldInfoMap = null ; if ( attributeFieldInfos != null ) { attributeFieldInfoMap = new HashMap < String , JmxAttributeFieldInfo > ( ) ; for ( JmxAttributeFieldInfo info : attributeFieldInfos ) { attributeFieldInfoMap . put ( info . getFieldName ( ) , info ) ; } } Map < String , JmxAttributeMethodInfo > attributeMethodInfoMap = null ; if ( attributeMethodInfos != null ) { attributeMethodInfoMap = new HashMap < String , JmxAttributeMethodInfo > ( ) ; for ( JmxAttributeMethodInfo info : attributeMethodInfos ) { attributeMethodInfoMap . put ( info . getMethodName ( ) , info ) ; } } Map < String , JmxOperationInfo > attributeOperationInfoMap = null ; if ( operationInfos != null ) { attributeOperationInfoMap = new HashMap < String , JmxOperationInfo > ( ) ; for ( JmxOperationInfo info : operationInfos ) { attributeOperationInfoMap . put ( info . getMethodName ( ) , info ) ; } } Set < String > attributeNameSet = new HashSet < String > ( ) ; List < MBeanAttributeInfo > attributes = new ArrayList < MBeanAttributeInfo > ( ) ; // NOTE: methods override fields so subclasses can stop exposing of fields discoverAttributeMethods ( attributeMethodInfoMap , attributeNameSet , attributes , ignoreErrors ) ; discoverAttributeFields ( attributeFieldInfoMap , attributeNameSet , attributes ) ; List < MBeanOperationInfo > operations = discoverOperations ( attributeOperationInfoMap ) ; return new MBeanInfo ( target . getClass ( ) . getName ( ) , description , attributes . toArray ( new MBeanAttributeInfo [ attributes . size ( ) ] ) , null , operations . toArray ( new MBeanOperationInfo [ operations . size ( ) ] ) , null ) ; } | Build our JMX information object by using reflection . | 480 | 10 |
16,576 | private List < MBeanOperationInfo > discoverOperations ( Map < String , JmxOperationInfo > attributeOperationInfoMap ) { Set < MethodSignature > methodSignatureSet = new HashSet < MethodSignature > ( ) ; List < MBeanOperationInfo > operations = new ArrayList < MBeanOperationInfo > ( operationMethodMap . size ( ) ) ; for ( Class < ? > clazz = target . getClass ( ) ; clazz != Object . class ; clazz = clazz . getSuperclass ( ) ) { discoverOperations ( attributeOperationInfoMap , methodSignatureSet , operations , clazz ) ; } return operations ; } | Find operation methods from our object that will be exposed via JMX . | 141 | 14 |
16,577 | private MBeanParameterInfo [ ] buildOperationParameterInfo ( Method method , JmxOperationInfo operationInfo ) { Class < ? > [ ] types = method . getParameterTypes ( ) ; MBeanParameterInfo [ ] parameterInfos = new MBeanParameterInfo [ types . length ] ; String [ ] parameterNames = operationInfo . getParameterNames ( ) ; String [ ] parameterDescriptions = operationInfo . getParameterDescriptions ( ) ; for ( int i = 0 ; i < types . length ; i ++ ) { String parameterName ; if ( parameterNames == null || i >= parameterNames . length ) { parameterName = "p" + ( i + 1 ) ; } else { parameterName = parameterNames [ i ] ; } String typeName = types [ i ] . getName ( ) ; String description ; if ( parameterDescriptions == null || i >= parameterDescriptions . length ) { description = "parameter #" + ( i + 1 ) + " of type: " + typeName ; } else { description = parameterDescriptions [ i ] ; } parameterInfos [ i ] = new MBeanParameterInfo ( parameterName , typeName , description ) ; } return parameterInfos ; } | Build our parameter information for an operation . | 262 | 8 |
16,578 | public static ObjectName makeObjectName ( JmxResource jmxResource , JmxSelfNaming selfNamingObj ) { String domainName = selfNamingObj . getJmxDomainName ( ) ; if ( domainName == null ) { if ( jmxResource != null ) { domainName = jmxResource . domainName ( ) ; } if ( isEmpty ( domainName ) ) { throw new IllegalArgumentException ( "Could not create ObjectName because domain name not specified in getJmxDomainName() nor @JmxResource" ) ; } } String beanName = selfNamingObj . getJmxBeanName ( ) ; if ( beanName == null ) { if ( jmxResource != null ) { beanName = getBeanName ( jmxResource ) ; } if ( isEmpty ( beanName ) ) { beanName = selfNamingObj . getClass ( ) . getSimpleName ( ) ; } } String [ ] jmxResourceFolders = null ; if ( jmxResource != null ) { jmxResourceFolders = jmxResource . folderNames ( ) ; } return makeObjectName ( domainName , beanName , selfNamingObj . getJmxFolderNames ( ) , jmxResourceFolders ) ; } | Constructs an object - name from a jmx - resource and a self naming object . | 269 | 18 |
16,579 | public static ObjectName makeObjectName ( JmxSelfNaming selfNamingObj ) { JmxResource jmxResource = selfNamingObj . getClass ( ) . getAnnotation ( JmxResource . class ) ; return makeObjectName ( jmxResource , selfNamingObj ) ; } | Constructs an object - name from a self naming object only . | 63 | 13 |
16,580 | public static ObjectName makeObjectName ( JmxResource jmxResource , Object obj ) { String domainName = jmxResource . domainName ( ) ; if ( isEmpty ( domainName ) ) { throw new IllegalArgumentException ( "Could not create ObjectName because domain name not specified in @JmxResource" ) ; } String beanName = getBeanName ( jmxResource ) ; if ( beanName == null ) { beanName = obj . getClass ( ) . getSimpleName ( ) ; } return makeObjectName ( domainName , beanName , null , jmxResource . folderNames ( ) ) ; } | Constructs an object - name from a jmx - resource and a object which is not self - naming . | 132 | 22 |
16,581 | public static ObjectName makeObjectName ( String domainName , String beanName , String [ ] folderNameStrings ) { return makeObjectName ( domainName , beanName , null , folderNameStrings ) ; } | Constructs an object - name from a domain - name object - name and folder - name strings . | 45 | 20 |
16,582 | void doMain ( String [ ] args , boolean throwOnError ) throws Exception { if ( args . length == 0 ) { usage ( throwOnError , "no arguments specified" ) ; return ; } else if ( args . length > 2 ) { usage ( throwOnError , "improper number of arguments:" + Arrays . toString ( args ) ) ; return ; } // check for --usage or --help if ( args . length == 1 && ( "--usage" . equals ( args [ 0 ] ) || "--help" . equals ( args [ 0 ] ) ) ) { usage ( throwOnError , null ) ; return ; } CommandLineJmxClient jmxClient ; if ( args [ 0 ] . indexOf ( ' ' ) >= 0 ) { jmxClient = new CommandLineJmxClient ( args [ 0 ] ) ; } else { String [ ] parts = args [ 0 ] . split ( ":" ) ; if ( parts . length != 2 ) { usage ( throwOnError , "argument should be in 'hostname:port' format, not: " + args [ 0 ] ) ; return ; } String hostName = parts [ 0 ] ; int port = 0 ; try { port = Integer . parseInt ( parts [ 1 ] ) ; } catch ( NumberFormatException e ) { usage ( throwOnError , "port number not in the right format: " + parts [ 1 ] ) ; return ; } jmxClient = new CommandLineJmxClient ( hostName , port ) ; } if ( args . length == 1 ) { jmxClient . runCommandLine ( ) ; } else if ( args . length == 2 ) { jmxClient . runBatchFile ( new File ( args [ 1 ] ) ) ; } } | This is package for testing purposes . | 372 | 7 |
16,583 | public String [ ] getBeanDomains ( ) throws JMException { checkClientConnected ( ) ; try { return mbeanConn . getDomains ( ) ; } catch ( IOException e ) { throw createJmException ( "Problems getting jmx domains: " + e , e ) ; } } | Return an array of the bean s domain names . | 66 | 10 |
16,584 | public MBeanAttributeInfo getAttributeInfo ( ObjectName name , String attrName ) throws JMException { checkClientConnected ( ) ; return getAttrInfo ( name , attrName ) ; } | Return information for a particular attribute name . | 44 | 8 |
16,585 | public String getAttributeString ( String domain , String beanName , String attributeName ) throws Exception { return getAttributeString ( ObjectNameUtil . makeObjectName ( domain , beanName ) , attributeName ) ; } | Return the value of a JMX attribute as a String . | 45 | 12 |
16,586 | public String getAttributeString ( ObjectName name , String attributeName ) throws Exception { Object bean = getAttribute ( name , attributeName ) ; if ( bean == null ) { return null ; } else { return ClientUtils . valueToString ( bean ) ; } } | Return the value of a JMX attribute as a String or null if attribute has a null value . | 56 | 20 |
16,587 | public void setAttribute ( ObjectName name , String attrName , Object value ) throws Exception { checkClientConnected ( ) ; Attribute attribute = new Attribute ( attrName , value ) ; mbeanConn . setAttribute ( name , attribute ) ; } | Set the JMX attribute to a particular value . | 55 | 10 |
16,588 | public void stop ( ) throws Exception { if ( server != null ) { server . setStopTimeout ( 100 ) ; server . stop ( ) ; server = null ; } } | Stop the internal Jetty web server and associated classes . | 36 | 11 |
16,589 | public static String formatException ( IThrowableProxy error ) { String ex = "" ; ex += formatTopLevelError ( error ) ; ex += formatStackTraceElements ( error . getStackTraceElementProxyArray ( ) ) ; IThrowableProxy cause = error . getCause ( ) ; ex += DELIMITER ; while ( cause != null ) { ex += formatTopLevelError ( cause ) ; StackTraceElementProxy [ ] arr = cause . getStackTraceElementProxyArray ( ) ; ex += formatStackTraceElements ( arr ) ; ex += DELIMITER ; cause = cause . getCause ( ) ; } return ex ; } | Returns a formatted stack trace for an exception . | 141 | 9 |
16,590 | public static Token generate ( final Random random , final Key key , final String plainText ) { return generate ( random , key , plainText . getBytes ( charset ) ) ; } | Convenience method to generate a new Fernet token with a string payload . | 38 | 16 |
16,591 | public static Token generate ( final Random random , final Key key , final byte [ ] payload ) { final IvParameterSpec initializationVector = generateInitializationVector ( random ) ; final byte [ ] cipherText = key . encrypt ( payload , initializationVector ) ; final Instant timestamp = Instant . now ( ) ; final byte [ ] hmac = key . sign ( supportedVersion , timestamp , initializationVector , cipherText ) ; return new Token ( supportedVersion , timestamp , initializationVector , cipherText , hmac ) ; } | Generate a new Fernet token . | 105 | 8 |
16,592 | @ SuppressWarnings ( "PMD.LawOfDemeter" ) public < T > T validateAndDecrypt ( final Key key , final Validator < T > validator ) { return validator . validateAndDecrypt ( key , this ) ; } | Check the validity of this token . | 56 | 7 |
16,593 | @ SuppressWarnings ( "PMD.LawOfDemeter" ) public < T > T validateAndDecrypt ( final Collection < ? extends Key > keys , final Validator < T > validator ) { return validator . validateAndDecrypt ( keys , this ) ; } | Check the validity of this token against a collection of keys . Use this if you have implemented key rotation . | 61 | 21 |
16,594 | @ SuppressWarnings ( "PMD.LawOfDemeter" ) public void writeTo ( final OutputStream outputStream ) throws IOException { try ( DataOutputStream dataStream = new DataOutputStream ( outputStream ) ) { dataStream . writeByte ( getVersion ( ) ) ; dataStream . writeLong ( getTimestamp ( ) . getEpochSecond ( ) ) ; dataStream . write ( getInitializationVector ( ) . getIV ( ) ) ; dataStream . write ( getCipherText ( ) ) ; dataStream . write ( getHmac ( ) ) ; } } | Write the raw bytes of this token to the specified output stream . | 127 | 13 |
16,595 | public boolean isValidSignature ( final Key key ) { final byte [ ] computedHmac = key . sign ( getVersion ( ) , getTimestamp ( ) , getInitializationVector ( ) , getCipherText ( ) ) ; return Arrays . equals ( getHmac ( ) , computedHmac ) ; } | Recompute the HMAC signature of the token with the stored shared secret key . | 68 | 17 |
16,596 | boolean checkValidUUID ( String uuid ) { if ( "" . equals ( uuid ) ) return false ; try { UUID u = UUID . fromString ( uuid ) ; } catch ( IllegalArgumentException e ) { return false ; } return true ; } | Checks that the UUID is valid | 59 | 8 |
16,597 | String getEnvVar ( String key ) { String envVal = System . getenv ( key ) ; return envVal != null ? envVal : "" ; } | Try and retrieve environment variable for given key return empty string if not found | 34 | 14 |
16,598 | boolean checkCredentials ( ) { if ( ! httpPut ) { if ( token . equals ( CONFIG_TOKEN ) || token . equals ( "" ) ) { //Check if set in an environment variable, used with PaaS providers String envToken = getEnvVar ( CONFIG_TOKEN ) ; if ( envToken == "" ) { dbg ( INVALID_TOKEN ) ; return false ; } this . setToken ( envToken ) ; } return checkValidUUID ( this . getToken ( ) ) ; } else { if ( ! checkValidUUID ( this . getKey ( ) ) || this . getLocation ( ) . equals ( "" ) ) return false ; return true ; } } | Checks that key and location are set . | 152 | 9 |
16,599 | void dbg ( String msg ) { if ( debug ) { if ( ! msg . endsWith ( LINE_SEP ) ) { System . err . println ( LE + msg ) ; } else { System . err . print ( LE + msg ) ; } } } | Prints the message given . Used for internal debugging . | 56 | 11 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.