idx int64 0 41.2k | question stringlengths 73 5.81k | target stringlengths 5 918 |
|---|---|---|
31,600 | public < S extends Model , R > AnimaQuery < T > where ( TypeFunction < S , R > function , Object value ) { String columnName = AnimaUtils . getLambdaColumnName ( function ) ; conditionSQL . append ( " AND " ) . append ( columnName ) . append ( " = ?" ) ; paramValues . add ( value ) ; return this ; } | Set the column name using lambda at the same time setting the value the SQL generated is column = ? |
31,601 | public AnimaQuery < T > where ( T model ) { Field [ ] declaredFields = model . getClass ( ) . getDeclaredFields ( ) ; for ( Field declaredField : declaredFields ) { Object value = AnimaUtils . invokeMethod ( model , getGetterName ( declaredField . getName ( ) ) , AnimaUtils . EMPTY_ARG ) ; if ( null == value ) { continue ; } if ( declaredField . getType ( ) . equals ( String . class ) && AnimaUtils . isEmpty ( value . toString ( ) ) ) { continue ; } String columnName = AnimaCache . getColumnName ( declaredField ) ; this . where ( columnName , value ) ; } return this ; } | Set the where parameter according to model and generate sql like where where age = ? and name = ? |
31,602 | public AnimaQuery < T > and ( String statement , Object value ) { return this . where ( statement , value ) ; } | generate AND statement simultaneous setting value |
31,603 | public < R > AnimaQuery < T > and ( TypeFunction < T , R > function ) { return this . where ( function ) ; } | generate AND statement with lambda |
31,604 | public < R > AnimaQuery < T > and ( TypeFunction < T , R > function , Object value ) { return this . where ( function , value ) ; } | generate AND statement with lambda simultaneous setting value |
31,605 | public AnimaQuery < T > or ( String statement , Object value ) { conditionSQL . append ( " OR (" ) . append ( statement ) ; if ( ! statement . contains ( "?" ) ) { conditionSQL . append ( " = ?" ) ; } conditionSQL . append ( ')' ) ; paramValues . add ( value ) ; return this ; } | generate OR statement simultaneous setting value |
31,606 | public AnimaQuery < T > notEmpty ( String columnName ) { conditionSQL . append ( " AND " ) . append ( columnName ) . append ( " != ''" ) ; return this ; } | generate ! = statement |
31,607 | public < R > AnimaQuery < T > notEmpty ( TypeFunction < T , R > function ) { String columnName = AnimaUtils . getLambdaColumnName ( function ) ; return this . notEmpty ( columnName ) ; } | generate ! = statement with lambda |
31,608 | public AnimaQuery < T > notNull ( String columnName ) { conditionSQL . append ( " AND " ) . append ( columnName ) . append ( " IS NOT NULL" ) ; return this ; } | generate IS NOT NULL statement |
31,609 | public AnimaQuery < T > like ( String columnName , Object value ) { conditionSQL . append ( " AND " ) . append ( columnName ) . append ( " LIKE ?" ) ; paramValues . add ( value ) ; return this ; } | generate like statement simultaneous setting value |
31,610 | public < R > AnimaQuery < T > like ( TypeFunction < T , R > function , Object value ) { String columnName = AnimaUtils . getLambdaColumnName ( function ) ; return this . like ( columnName , value ) ; } | generate like statement with lambda simultaneous setting value |
31,611 | public AnimaQuery < T > between ( String columnName , Object a , Object b ) { conditionSQL . append ( " AND " ) . append ( columnName ) . append ( " BETWEEN ? and ?" ) ; paramValues . add ( a ) ; paramValues . add ( b ) ; return this ; } | generate between statement simultaneous setting value |
31,612 | public < R > AnimaQuery < T > between ( TypeFunction < T , R > function , Object a , Object b ) { String columnName = AnimaUtils . getLambdaColumnName ( function ) ; return this . between ( columnName , a , b ) ; } | generate between statement with lambda simultaneous setting value |
31,613 | public < S extends Model , R > AnimaQuery < T > gte ( TypeFunction < S , R > function , Object value ) { String columnName = AnimaUtils . getLambdaColumnName ( function ) ; return this . gte ( columnName , value ) ; } | generate > = statement with lambda simultaneous setting value |
31,614 | public AnimaQuery < T > lt ( String column , Object value ) { conditionSQL . append ( " AND " ) . append ( column ) . append ( " < ?" ) ; paramValues . add ( value ) ; return this ; } | generate < statement simultaneous setting value |
31,615 | public < S > AnimaQuery < T > in ( List < S > list ) { return this . in ( list . toArray ( ) ) ; } | Set in params |
31,616 | public < R > AnimaQuery < T > order ( TypeFunction < T , R > function , OrderBy orderBy ) { String columnName = AnimaUtils . getLambdaColumnName ( function ) ; return order ( columnName , orderBy ) ; } | generate order by statement with lambda |
31,617 | public T byId ( Object id ) { this . beforeCheck ( ) ; this . where ( primaryKeyColumn , id ) ; String sql = this . buildSelectSQL ( false ) ; T model = this . queryOne ( modelClass , sql , paramValues ) ; ifNotNullThen ( model , ( ) -> this . setJoin ( Collections . singletonList ( model ) ) ) ; return model ; } | query model by primary key |
31,618 | public T one ( ) { this . beforeCheck ( ) ; String sql = this . buildSelectSQL ( true ) ; T model = this . queryOne ( modelClass , sql , paramValues ) ; ifThen ( null != model && null != joinParams , ( ) -> this . setJoin ( Collections . singletonList ( model ) ) ) ; return model ; } | query and find one model |
31,619 | public List < T > all ( ) { this . beforeCheck ( ) ; String sql = this . buildSelectSQL ( true ) ; List < T > models = this . queryList ( modelClass , sql , paramValues ) ; this . setJoin ( models ) ; return models ; } | query and find all model |
31,620 | public < R > Stream < R > map ( Function < T , R > function ) { return stream ( ) . map ( function ) ; } | Transform the results of the model . |
31,621 | public List < T > limit ( int limit ) { return ifReturn ( Anima . of ( ) . isUseSQLLimit ( ) , ( ) -> { isSQLLimit = true ; paramValues . add ( limit ) ; return all ( ) ; } , ( ) -> { List < T > all = all ( ) ; return ifReturn ( all . size ( ) > limit , all . stream ( ) . limit ( limit ) . collect ( toList ( ) ) , all ) ; } ) ; } | Take the data of the fixed number from the result . |
31,622 | public Page < T > page ( PageRow pageRow ) { String sql = this . buildSelectSQL ( false ) ; return this . page ( sql , pageRow ) ; } | Paging query results |
31,623 | public AnimaQuery < T > set ( String column , Object value ) { updateColumns . put ( column , value ) ; return this ; } | Update columns set value |
31,624 | public < S extends Model , R > AnimaQuery < T > set ( TypeFunction < S , R > function , Object value ) { return this . set ( AnimaUtils . getLambdaColumnName ( function ) , value ) ; } | Update the model sets column . |
31,625 | public AnimaQuery < T > join ( JoinParam joinParam ) { ifNullThrow ( joinParam , new AnimaException ( "Join param not null" ) ) ; ifNullThrow ( joinParam . getJoinModel ( ) , new AnimaException ( "Join param [model] not null" ) ) ; ifNullThrow ( AnimaUtils . isEmpty ( joinParam . getFieldName ( ) ) , new AnimaException ( "Join param [as] not empty" ) ) ; ifNullThrow ( AnimaUtils . isEmpty ( joinParam . getOnLeft ( ) ) , new AnimaException ( "Join param [onLeft] not empty" ) ) ; ifNullThrow ( AnimaUtils . isEmpty ( joinParam . getOnRight ( ) ) , new AnimaException ( "Join param [onRight] not empty" ) ) ; this . joinParams . add ( joinParam ) ; return this ; } | Add a cascading query . |
31,626 | public < S extends Model > ResultKey save ( S model ) { List < Object > columnValues = AnimaUtils . toColumnValues ( model , true ) ; String sql = this . buildInsertSQL ( model , columnValues ) ; Connection conn = getConn ( ) ; try { List < Object > params = columnValues . stream ( ) . filter ( Objects :: nonNull ) . collect ( toList ( ) ) ; return new ResultKey ( conn . createQuery ( sql ) . withParams ( params ) . executeUpdate ( ) . getKey ( ) ) ; } finally { this . closeConn ( conn ) ; this . clean ( conn ) ; } } | Save a model |
31,627 | public < S extends Model > int updateById ( S model , Serializable id ) { this . where ( primaryKeyColumn , id ) ; String sql = this . buildUpdateSQL ( model , null ) ; List < Object > columnValueList = AnimaUtils . toColumnValues ( model , false ) ; columnValueList . add ( id ) ; return this . execute ( sql , columnValueList ) ; } | Update model by primary key |
31,628 | public < S extends Model > int updateByModel ( S model ) { this . beforeCheck ( ) ; Object primaryKey = AnimaUtils . getAndRemovePrimaryKey ( model ) ; StringBuilder sql = new StringBuilder ( this . buildUpdateSQL ( model , null ) ) ; List < Object > columnValueList = AnimaUtils . toColumnValues ( model , false ) ; ifNotNullThen ( primaryKey , ( ) -> { sql . append ( " WHERE " ) . append ( this . primaryKeyColumn ) . append ( " = ?" ) ; columnValueList . add ( primaryKey ) ; } ) ; return this . execute ( sql . toString ( ) , columnValueList ) ; } | Update a model |
31,629 | private String buildSelectSQL ( boolean addOrderBy ) { SQLParams sqlParams = SQLParams . builder ( ) . modelClass ( this . modelClass ) . selectColumns ( this . selectColumns ) . tableName ( this . tableName ) . pkName ( this . primaryKeyColumn ) . conditionSQL ( this . conditionSQL ) . excludedColumns ( this . excludedColumns ) . isSQLLimit ( isSQLLimit ) . build ( ) ; ifThen ( addOrderBy , ( ) -> sqlParams . setOrderBy ( this . orderBySQL . toString ( ) ) ) ; return Anima . of ( ) . dialect ( ) . select ( sqlParams ) ; } | Build a select statement . |
31,630 | private String buildCountSQL ( ) { SQLParams sqlParams = SQLParams . builder ( ) . modelClass ( this . modelClass ) . tableName ( this . tableName ) . pkName ( this . primaryKeyColumn ) . conditionSQL ( this . conditionSQL ) . build ( ) ; return Anima . of ( ) . dialect ( ) . count ( sqlParams ) ; } | Build a count statement . |
31,631 | private String buildPageSQL ( String sql , PageRow pageRow ) { SQLParams sqlParams = SQLParams . builder ( ) . modelClass ( this . modelClass ) . selectColumns ( this . selectColumns ) . tableName ( this . tableName ) . pkName ( this . primaryKeyColumn ) . conditionSQL ( this . conditionSQL ) . excludedColumns ( this . excludedColumns ) . customSQL ( sql ) . orderBy ( this . orderBySQL . toString ( ) ) . pageRow ( pageRow ) . build ( ) ; return Anima . of ( ) . dialect ( ) . paginate ( sqlParams ) ; } | Build a paging statement |
31,632 | private < S extends Model > String buildInsertSQL ( S model , List < Object > columnValues ) { SQLParams sqlParams = SQLParams . builder ( ) . model ( model ) . columnValues ( columnValues ) . modelClass ( this . modelClass ) . tableName ( this . tableName ) . pkName ( this . primaryKeyColumn ) . build ( ) ; return Anima . of ( ) . dialect ( ) . insert ( sqlParams ) ; } | Build a insert statement . |
31,633 | private < S extends Model > String buildUpdateSQL ( S model , Map < String , Object > updateColumns ) { SQLParams sqlParams = SQLParams . builder ( ) . model ( model ) . modelClass ( this . modelClass ) . tableName ( this . tableName ) . pkName ( this . primaryKeyColumn ) . updateColumns ( updateColumns ) . conditionSQL ( this . conditionSQL ) . build ( ) ; return Anima . of ( ) . dialect ( ) . update ( sqlParams ) ; } | Build a update statement . |
31,634 | private < S extends Model > String buildDeleteSQL ( S model ) { SQLParams sqlParams = SQLParams . builder ( ) . model ( model ) . modelClass ( this . modelClass ) . tableName ( this . tableName ) . pkName ( this . primaryKeyColumn ) . conditionSQL ( this . conditionSQL ) . build ( ) ; return Anima . of ( ) . dialect ( ) . delete ( sqlParams ) ; } | Build a delete statement . |
31,635 | private Connection getConn ( ) { Connection connection = localConnection . get ( ) ; return ifNotNullReturn ( connection , connection , this . getSql2o ( ) . open ( ) ) ; } | Get a database connection . |
31,636 | public static void beginTransaction ( ) { ifNullThen ( localConnection . get ( ) , ( ) -> { Connection connection = getSql2o ( ) . beginTransaction ( ) ; localConnection . set ( connection ) ; } ) ; } | Begin a transaction . |
31,637 | public static void endTransaction ( ) { ifNotNullThen ( localConnection . get ( ) , ( ) -> { Connection connection = localConnection . get ( ) ; ifThen ( connection . isRollbackOnClose ( ) , connection :: close ) ; localConnection . remove ( ) ; } ) ; } | End a transaction . |
31,638 | private void setJoin ( List < T > models ) { if ( null == models || models . isEmpty ( ) || joinParams . size ( ) == 0 ) { return ; } models . stream ( ) . filter ( Objects :: nonNull ) . forEach ( this :: setJoin ) ; } | Set models join fields |
31,639 | private void setJoin ( T model ) { for ( JoinParam joinParam : joinParams ) { try { Object leftValue = AnimaUtils . invokeMethod ( model , getGetterName ( joinParam . getOnLeft ( ) ) , AnimaUtils . EMPTY_ARG ) ; String sql = "SELECT * FROM " + AnimaCache . getTableName ( joinParam . getJoinModel ( ) ) + " WHERE " + joinParam . getOnRight ( ) + " = ?" ; Field field = model . getClass ( ) . getDeclaredField ( joinParam . getFieldName ( ) ) ; if ( field . getType ( ) . equals ( List . class ) ) { if ( AnimaUtils . isNotEmpty ( joinParam . getOrderBy ( ) ) ) { sql += " ORDER BY " + joinParam . getOrderBy ( ) ; } List < ? extends Model > list = this . queryList ( joinParam . getJoinModel ( ) , sql , new Object [ ] { leftValue } ) ; AnimaUtils . invokeMethod ( model , getSetterName ( joinParam . getFieldName ( ) ) , new Object [ ] { list } ) ; } if ( field . getType ( ) . equals ( joinParam . getJoinModel ( ) ) ) { Object joinObject = this . queryOne ( joinParam . getJoinModel ( ) , sql , new Object [ ] { leftValue } ) ; AnimaUtils . invokeMethod ( model , getSetterName ( joinParam . getFieldName ( ) ) , new Object [ ] { joinObject } ) ; } } catch ( NoSuchFieldException e ) { log . error ( "Set join error" , e ) ; } } } | Set model join fields |
31,640 | private void clean ( Connection conn ) { this . selectColumns = null ; this . isSQLLimit = false ; this . orderBySQL = new StringBuilder ( ) ; this . conditionSQL = new StringBuilder ( ) ; this . paramValues . clear ( ) ; this . excludedColumns . clear ( ) ; this . updateColumns . clear ( ) ; ifThen ( localConnection . get ( ) == null && conn != null , ( ) -> conn . close ( ) ) ; } | Clear the battlefield after a database operation . |
31,641 | public static < S extends Model > Object getAndRemovePrimaryKey ( S model ) { String fieldName = getPKField ( model . getClass ( ) ) ; Object value = invokeMethod ( model , getGetterName ( fieldName ) , EMPTY_ARG ) ; if ( null != value ) { invokeMethod ( model , getSetterName ( fieldName ) , NULL_ARG ) ; } return value ; } | Return the primary key of the model and set it to null |
31,642 | public static < T > T [ ] toArray ( List < T > list ) { T [ ] toR = ( T [ ] ) Array . newInstance ( list . get ( 0 ) . getClass ( ) , list . size ( ) ) ; for ( int i = 0 ; i < list . size ( ) ; i ++ ) { toR [ i ] = list . get ( i ) ; } return toR ; } | Convert a List to a generic array |
31,643 | public AnimaQuery < ? extends Model > set ( String column , Object value ) { return query . set ( column , value ) ; } | Update set statement |
31,644 | public < T extends Model , R > AnimaQuery < ? extends Model > set ( TypeFunction < T , R > function , Object value ) { return query . set ( function , value ) ; } | Update set statement with lambda |
31,645 | public static Anima open ( Sql2o sql2o ) { Anima anima = new Anima ( ) ; anima . setSql2o ( sql2o ) ; instance = anima ; return anima ; } | Create anima with Sql2o |
31,646 | public static Anima open ( String url , Quirks quirks ) { return open ( url , null , null , quirks ) ; } | Create anima with url like Sqlite or h2 |
31,647 | public static Anima open ( DataSource dataSource , Quirks quirks ) { return open ( new Sql2o ( dataSource , quirks ) ) ; } | Create anima with datasource and quirks |
31,648 | public static Atomic atomic ( Runnable runnable ) { try { AnimaQuery . beginTransaction ( ) ; runnable . run ( ) ; AnimaQuery . commit ( ) ; return Atomic . ok ( ) ; } catch ( Exception e ) { boolean isRollback = ifReturn ( of ( ) . rollbackException . isInstance ( e ) , ( ) -> { AnimaQuery . rollback ( ) ; return true ; } , ( ) -> false ) ; return Atomic . error ( e ) . rollback ( isRollback ) ; } finally { AnimaQuery . endTransaction ( ) ; } } | Code that performs a transaction operation . |
31,649 | public Anima addConverter ( Converter < ? > ... converters ) { ifThrow ( null == converters || converters . length == 0 , new AnimaException ( "converters not be null." ) ) ; for ( Converter < ? > converter : converters ) { Class < ? > type = AnimaUtils . getConverterType ( converter ) ; sql2o . getQuirks ( ) . addConverter ( type , converter ) ; } return this ; } | Add custom Type converter |
31,650 | public static < T extends Model , R > Select select ( TypeFunction < T , R > ... functions ) { return select ( Arrays . stream ( functions ) . map ( AnimaUtils :: getLambdaColumnName ) . collect ( joining ( ", " ) ) ) ; } | Set the query to fix columns with lambda |
31,651 | public static < T extends Model > void saveBatch ( List < T > models ) { atomic ( ( ) -> models . forEach ( Anima :: save ) ) . catchException ( e -> log . error ( "Batch save model error, message: {}" , e ) ) ; } | Batch save model |
31,652 | public static < T extends Model , S extends Serializable > void deleteBatch ( Class < T > model , S ... ids ) { atomic ( ( ) -> Arrays . stream ( ids ) . forEach ( new AnimaQuery < > ( model ) :: deleteById ) ) . catchException ( e -> log . error ( "Batch save model error, message: {}" , e ) ) ; } | Batch delete model |
31,653 | public static < T extends Model , S extends Serializable > void deleteBatch ( Class < T > model , List < S > idList ) { deleteBatch ( model , AnimaUtils . toArray ( idList ) ) ; } | Batch delete model with List |
31,654 | public static < T extends Model > int deleteById ( Class < T > model , Serializable id ) { return new AnimaQuery < > ( model ) . deleteById ( id ) ; } | Delete model by id |
31,655 | public Map < String , Object > asMap ( ) { Map < String , Object > map = new HashMap < > ( ) ; Set < String > keys = columnNameToIdxMap . keySet ( ) ; Iterator < String > iterator = keys . iterator ( ) ; while ( iterator . hasNext ( ) ) { String colum = iterator . next ( ) . toString ( ) ; int index = columnNameToIdxMap . get ( colum ) ; map . put ( colum , values [ index ] ) ; } return map ; } | View row as a simple map . |
31,656 | public static String getTableName ( String className , String prefix ) { boolean hasPrefix = prefix != null && prefix . trim ( ) . length ( ) > 0 ; return hasPrefix ? English . plural ( prefix + "_" + AnimaUtils . toUnderline ( className ) , 2 ) : English . plural ( AnimaUtils . toUnderline ( className ) , 2 ) ; } | User - > users User - > t_users |
31,657 | X509Certificate selectCertificate ( final CertStore store , final Collection < X509CertSelector > selectors ) throws CertStoreException { for ( CertSelector selector : selectors ) { LOGGER . debug ( "Selecting certificate using {}" , selector ) ; Collection < ? extends Certificate > certs = store . getCertificates ( selector ) ; if ( certs . size ( ) > 0 ) { LOGGER . debug ( "Selected {} certificate(s) using {}" , certs . size ( ) , selector ) ; return ( X509Certificate ) certs . iterator ( ) . next ( ) ; } else { LOGGER . debug ( "No certificates selected" ) ; } } return ( X509Certificate ) store . getCertificates ( null ) . iterator ( ) . next ( ) ; } | Finds the certificate of the SCEP message object recipient . |
31,658 | private void validateInput ( ) { if ( url == null ) { throw new NullPointerException ( "URL should not be null" ) ; } if ( ! url . getProtocol ( ) . matches ( "^https?$" ) ) { throw new IllegalArgumentException ( "URL protocol should be HTTP or HTTPS" ) ; } if ( url . getRef ( ) != null ) { throw new IllegalArgumentException ( "URL should contain no reference" ) ; } if ( url . getQuery ( ) != null ) { throw new IllegalArgumentException ( "URL should contain no query string" ) ; } if ( handler == null ) { throw new NullPointerException ( "Callback handler should not be null" ) ; } } | Validates all the input to this client . |
31,659 | private Transport createTransport ( final String profile ) { if ( getCaCapabilities ( profile ) . isPostSupported ( ) ) { return transportFactory . forMethod ( Method . POST , url ) ; } else { return transportFactory . forMethod ( Method . GET , url ) ; } } | Creates a new transport based on the capabilities of the server . |
31,660 | public boolean verify ( final X509Certificate cert ) { final List < String > algs = new ArrayList < String > ( getAlgorithms ( MessageDigest . class . getSimpleName ( ) ) ) ; Collections . sort ( algs ) ; int max = 0 ; for ( final String alg : algs ) { if ( alg . length ( ) > max ) { max = alg . length ( ) ; } } for ( final String alg : algs ) { MessageDigest digest ; try { digest = MessageDigest . getInstance ( alg ) ; } catch ( NoSuchAlgorithmException e ) { return false ; } byte [ ] hash ; try { hash = digest . digest ( cert . getEncoded ( ) ) ; } catch ( CertificateEncodingException e ) { return false ; } System . out . format ( "%" + max + "s: %s%n" , alg , Hex . encodeHexString ( hash ) ) ; } final Scanner scanner = new Scanner ( System . in , Charset . defaultCharset ( ) . name ( ) ) . useDelimiter ( String . format ( "%n" ) ) ; while ( true ) { System . out . format ( "%nAccept? (Y/N): [N]%n" ) ; try { final String answer = scanner . next ( ) ; System . out . println ( answer ) ; if ( answer . equals ( "Y" ) ) { return true ; } else if ( answer . equals ( "N" ) ) { return false ; } } catch ( final NoSuchElementException e ) { return false ; } } } | Use the system console to prompt the user with each available hash . |
31,661 | public CMSEnvelopedData encode ( final byte [ ] messageData ) throws MessageEncodingException { LOGGER . debug ( "Encoding pkcsPkiEnvelope" ) ; CMSEnvelopedDataGenerator edGenerator = new CMSEnvelopedDataGenerator ( ) ; CMSTypedData envelopable = new CMSProcessableByteArray ( messageData ) ; RecipientInfoGenerator recipientGenerator ; try { recipientGenerator = new JceKeyTransRecipientInfoGenerator ( recipient ) ; } catch ( CertificateEncodingException e ) { throw new MessageEncodingException ( e ) ; } edGenerator . addRecipientInfoGenerator ( recipientGenerator ) ; LOGGER . debug ( "Encrypting pkcsPkiEnvelope using key belonging to [dn={}; serial={}]" , recipient . getSubjectDN ( ) , recipient . getSerialNumber ( ) ) ; OutputEncryptor encryptor ; try { encryptor = new JceCMSContentEncryptorBuilder ( encAlgId ) . build ( ) ; } catch ( CMSException e ) { throw new MessageEncodingException ( e ) ; } try { CMSEnvelopedData pkcsPkiEnvelope = edGenerator . generate ( envelopable , encryptor ) ; LOGGER . debug ( "Finished encoding pkcsPkiEnvelope" ) ; return pkcsPkiEnvelope ; } catch ( CMSException e ) { throw new MessageEncodingException ( e ) ; } } | Encrypts and envelops the provided messageData . |
31,662 | public String getStrongestCipher ( ) { final String cipher ; if ( cipherExists ( "AES" ) && caps . contains ( Capability . AES ) ) { cipher = "AES" ; } else if ( cipherExists ( "DESede" ) && caps . contains ( Capability . TRIPLE_DES ) ) { cipher = "DESede" ; } else { cipher = "DES" ; } return cipher ; } | Returns the strongest cipher algorithm supported by the server and client . |
31,663 | public MessageDigest getStrongestMessageDigest ( ) { if ( digestExists ( "SHA-512" ) && caps . contains ( Capability . SHA_512 ) ) { return getDigest ( "SHA-512" ) ; } else if ( digestExists ( "SHA-256" ) && caps . contains ( Capability . SHA_256 ) ) { return getDigest ( "SHA-256" ) ; } else if ( digestExists ( "SHA-1" ) && caps . contains ( Capability . SHA_1 ) ) { return getDigest ( "SHA-1" ) ; } else if ( digestExists ( "MD5" ) ) { return getDigest ( "MD5" ) ; } return null ; } | Returns the strongest message digest algorithm supported by the server and client . |
31,664 | public static boolean isSignedBy ( final CMSSignedData sd , final X509Certificate signer ) { SignerInformationStore store = sd . getSignerInfos ( ) ; SignerInformation signerInfo = store . get ( new JcaSignerId ( signer ) ) ; if ( signerInfo == null ) { return false ; } CMSSignatureAlgorithmNameGenerator sigNameGenerator = new DefaultCMSSignatureAlgorithmNameGenerator ( ) ; SignatureAlgorithmIdentifierFinder sigAlgorithmFinder = new DefaultSignatureAlgorithmIdentifierFinder ( ) ; ContentVerifierProvider verifierProvider ; try { verifierProvider = new JcaContentVerifierProviderBuilder ( ) . build ( signer ) ; } catch ( OperatorCreationException e ) { throw new RuntimeException ( e ) ; } DigestCalculatorProvider digestProvider ; try { digestProvider = new JcaDigestCalculatorProviderBuilder ( ) . build ( ) ; } catch ( OperatorCreationException e1 ) { throw new RuntimeException ( e1 ) ; } SignerInformationVerifier verifier = new SignerInformationVerifier ( sigNameGenerator , sigAlgorithmFinder , verifierProvider , digestProvider ) ; try { return signerInfo . verify ( verifier ) ; } catch ( CMSException e ) { return false ; } } | Checks if the provided signedData was signed by the entity represented by the provided certificate . |
31,665 | public static X500Name toX500Name ( final X500Principal principal ) { byte [ ] bytes = principal . getEncoded ( ) ; return X500Name . getInstance ( bytes ) ; } | Converts a Java SE X500Principal to a Bouncy Castle X500Name . |
31,666 | private String provideRepresentation ( int number ) { String key ; if ( number == 0 ) key = "zero" ; else if ( number < 20 ) key = numNames [ number ] ; else if ( number < 100 ) { int unit = number % 10 ; key = tensNames [ number / 10 ] + numNames [ unit ] ; } else { int unit = number % 10 ; int ten = number % 100 - unit ; int hundred = ( number - ten ) / 100 ; if ( hundred < 20 ) key = numNames [ hundred ] + " hundred" ; else key = tensNames [ hundred / 10 ] + numNames [ hundred % 10 ] + " hundred" ; if ( ten + unit < 20 && ten + unit > 10 ) key += numNames [ ten + unit ] ; else key += tensNames [ ten / 10 ] + numNames [ unit ] ; } return key . trim ( ) ; } | Provides a string representation for the number passed . This method works for limited set of numbers as parsing will only be done at maximum for 2400 which will be used in military time format . |
31,667 | private void flushBuffer ( ) throws IOException { if ( buffer . position ( ) > 0 ) { buffer . flip ( ) ; writeCompressed ( buffer ) ; buffer . clear ( ) ; } } | Compresses and writes out any buffered data . This does nothing if there is no currently buffered data . |
31,668 | public static void arrayCopy ( Object src , int offset , int byteLength , Object dest , int dest_offset ) throws IOException { impl . arrayCopy ( src , offset , byteLength , dest , dest_offset ) ; } | Copy bytes from source to destination |
31,669 | public static int compress ( byte [ ] input , int inputOffset , int inputLength , byte [ ] output , int outputOffset ) throws IOException { return rawCompress ( input , inputOffset , inputLength , output , outputOffset ) ; } | Compress the input buffer content in [ inputOffset ... inputOffset + inputLength ) then output to the specified output buffer . |
31,670 | public static String getNativeLibraryVersion ( ) { URL versionFile = SnappyLoader . class . getResource ( "/org/xerial/snappy/VERSION" ) ; String version = "unknown" ; try { if ( versionFile != null ) { InputStream in = null ; try { Properties versionData = new Properties ( ) ; in = versionFile . openStream ( ) ; versionData . load ( in ) ; version = versionData . getProperty ( "version" , version ) ; if ( version . equals ( "unknown" ) ) { version = versionData . getProperty ( "SNAPPY_VERSION" , version ) ; } version = version . trim ( ) . replaceAll ( "[^0-9\\.]" , "" ) ; } finally { if ( in != null ) { in . close ( ) ; } } } } catch ( IOException e ) { e . printStackTrace ( ) ; } return version ; } | Get the native library version of the snappy |
31,671 | public static long rawCompress ( long inputAddr , long inputSize , long destAddr ) throws IOException { return impl . rawCompress ( inputAddr , inputSize , destAddr ) ; } | Zero - copy compress using memory addresses . |
31,672 | public static long rawUncompress ( long inputAddr , long inputSize , long destAddr ) throws IOException { return impl . rawUncompress ( inputAddr , inputSize , destAddr ) ; } | Zero - copy decompress using memory addresses . |
31,673 | public static byte [ ] rawCompress ( Object data , int byteSize ) throws IOException { byte [ ] buf = new byte [ Snappy . maxCompressedLength ( byteSize ) ] ; int compressedByteSize = impl . rawCompress ( data , 0 , byteSize , buf , 0 ) ; byte [ ] result = new byte [ compressedByteSize ] ; System . arraycopy ( buf , 0 , result , 0 , compressedByteSize ) ; return result ; } | Compress the input data and produce a byte array of the uncompressed data |
31,674 | public static int rawCompress ( Object input , int inputOffset , int inputLength , byte [ ] output , int outputOffset ) throws IOException { if ( input == null || output == null ) { throw new NullPointerException ( "input or output is null" ) ; } int compressedSize = impl . rawCompress ( input , inputOffset , inputLength , output , outputOffset ) ; return compressedSize ; } | Compress the input buffer [ offset ... offset + length ) contents then write the compressed data to the output buffer [ offset ... ) |
31,675 | public static byte [ ] uncompress ( byte [ ] input ) throws IOException { byte [ ] result = new byte [ Snappy . uncompressedLength ( input ) ] ; Snappy . uncompress ( input , 0 , input . length , result , 0 ) ; return result ; } | High - level API for uncompressing the input byte array . |
31,676 | public static double [ ] uncompressDoubleArray ( byte [ ] input ) throws IOException { int uncompressedLength = Snappy . uncompressedLength ( input , 0 , input . length ) ; double [ ] result = new double [ uncompressedLength / 8 ] ; impl . rawUncompress ( input , 0 , input . length , result , 0 ) ; return result ; } | Uncompress the input as a double array |
31,677 | public static float [ ] uncompressFloatArray ( byte [ ] input , int offset , int length ) throws IOException { int uncompressedLength = Snappy . uncompressedLength ( input , offset , length ) ; float [ ] result = new float [ uncompressedLength / 4 ] ; impl . rawUncompress ( input , offset , length , result , 0 ) ; return result ; } | Uncompress the input [ offset offset + length ) as a float array |
31,678 | public static String uncompressString ( byte [ ] input , int offset , int length ) throws IOException { try { return uncompressString ( input , offset , length , "UTF-8" ) ; } catch ( UnsupportedEncodingException e ) { throw new IllegalStateException ( "UTF-8 decoder is not found" ) ; } } | Uncompress the input [ offset offset + length ) as a String |
31,679 | public static String uncompressString ( byte [ ] input , int offset , int length , String encoding ) throws IOException , UnsupportedEncodingException { byte [ ] uncompressed = new byte [ uncompressedLength ( input , offset , length ) ] ; uncompress ( input , offset , length , uncompressed , 0 ) ; return new String ( uncompressed , encoding ) ; } | Uncompress the input [ offset offset + length ) as a String of the given encoding |
31,680 | public static String uncompressString ( byte [ ] input , String encoding ) throws IOException , UnsupportedEncodingException { byte [ ] uncompressed = uncompress ( input ) ; return new String ( uncompressed , encoding ) ; } | Uncompress the input as a String of the given encoding |
31,681 | public int rawRead ( Object array , int byteOffset , int byteLength ) throws IOException { int writtenBytes = 0 ; for ( ; writtenBytes < byteLength ; ) { if ( uncompressedCursor >= uncompressedLimit ) { if ( hasNextChunk ( ) ) { continue ; } else { return writtenBytes == 0 ? - 1 : writtenBytes ; } } int bytesToWrite = Math . min ( uncompressedLimit - uncompressedCursor , byteLength - writtenBytes ) ; Snappy . arrayCopy ( uncompressed , uncompressedCursor , bytesToWrite , array , byteOffset + writtenBytes ) ; writtenBytes += bytesToWrite ; uncompressedCursor += bytesToWrite ; } return writtenBytes ; } | Read uncompressed data into the specified array |
31,682 | private int readNext ( byte [ ] dest , int offset , int len ) throws IOException { int readBytes = 0 ; while ( readBytes < len ) { int ret = in . read ( dest , readBytes + offset , len - readBytes ) ; if ( ret == - 1 ) { finishedReading = true ; return readBytes ; } readBytes += ret ; } return readBytes ; } | Read next len bytes |
31,683 | public static byte [ ] shuffle ( short [ ] input ) throws IOException { byte [ ] output = new byte [ input . length * 2 ] ; int numProcessed = impl . shuffle ( input , 0 , 2 , input . length * 2 , output , 0 ) ; assert ( numProcessed == input . length * 2 ) ; return output ; } | Apply a bit - shuffling filter into the input short array . |
31,684 | public static int unshuffle ( ByteBuffer shuffled , BitShuffleType type , ByteBuffer output ) throws IOException { if ( ! shuffled . isDirect ( ) ) { throw new SnappyError ( SnappyErrorCode . NOT_A_DIRECT_BUFFER , "input is not a direct buffer" ) ; } if ( ! output . isDirect ( ) ) { throw new SnappyError ( SnappyErrorCode . NOT_A_DIRECT_BUFFER , "destination is not a direct buffer" ) ; } int uPos = shuffled . position ( ) ; int uLen = shuffled . remaining ( ) ; int typeSize = type . getTypeSize ( ) ; if ( uLen % typeSize != 0 ) { throw new IllegalArgumentException ( "length of input shuffled data must be a multiple of the given type size: " + typeSize ) ; } if ( output . remaining ( ) < uLen ) { throw new IllegalArgumentException ( "not enough space for output" ) ; } int numProcessed = impl . unshuffleDirectBuffer ( shuffled , uPos , typeSize , uLen , output , shuffled . position ( ) ) ; assert ( numProcessed == uLen ) ; shuffled . limit ( shuffled . position ( ) + numProcessed ) ; return numProcessed ; } | Convert the input bit - shuffled byte array into an original array . The result is dumped to the specified output buffer . |
31,685 | public static short [ ] unshuffleShortArray ( byte [ ] input ) throws IOException { short [ ] output = new short [ input . length / 2 ] ; int numProcessed = impl . unshuffle ( input , 0 , 2 , input . length , output , 0 ) ; assert ( numProcessed == input . length ) ; return output ; } | Convert the input bit - shuffled byte array into an original short array . |
31,686 | public static int [ ] unshuffleIntArray ( byte [ ] input ) throws IOException { int [ ] output = new int [ input . length / 4 ] ; int numProcessed = impl . unshuffle ( input , 0 , 4 , input . length , output , 0 ) ; assert ( numProcessed == input . length ) ; return output ; } | Convert the input bit - shuffled byte array into an original int array . |
31,687 | public static long [ ] unshuffleLongArray ( byte [ ] input ) throws IOException { long [ ] output = new long [ input . length / 8 ] ; int numProcessed = impl . unshuffle ( input , 0 , 8 , input . length , output , 0 ) ; assert ( numProcessed == input . length ) ; return output ; } | Convert the input bit - shuffled byte array into an original long array . |
31,688 | public static float [ ] unshuffleFloatArray ( byte [ ] input ) throws IOException { float [ ] output = new float [ input . length / 4 ] ; int numProcessed = impl . unshuffle ( input , 0 , 4 , input . length , output , 0 ) ; assert ( numProcessed == input . length ) ; return output ; } | Convert the input bit - shuffled byte array into an original float array . |
31,689 | public static double [ ] unshuffleDoubleArray ( byte [ ] input ) throws IOException { double [ ] output = new double [ input . length / 8 ] ; int numProcessed = impl . unshuffle ( input , 0 , 8 , input . length , output , 0 ) ; assert ( numProcessed == input . length ) ; return output ; } | Convert the input bit - shuffled byte array into an original double array . |
31,690 | public void rawWrite ( Object array , int byteOffset , int byteLength ) throws IOException { if ( closed ) { throw new IOException ( "Stream is closed" ) ; } int cursor = 0 ; while ( cursor < byteLength ) { int readLen = Math . min ( byteLength - cursor , blockSize - inputCursor ) ; if ( readLen > 0 ) { Snappy . arrayCopy ( array , byteOffset + cursor , readLen , inputBuffer , inputCursor ) ; inputCursor += readLen ; } if ( inputCursor < blockSize ) { return ; } compressInput ( ) ; cursor += readLen ; } } | Compress the raw byte array data . |
31,691 | private synchronized static void loadNativeLibrary ( ) { if ( ! isLoaded ) { try { nativeLibFile = findNativeLibrary ( ) ; if ( nativeLibFile != null ) { System . load ( nativeLibFile . getAbsolutePath ( ) ) ; } else { System . loadLibrary ( "snappyjava" ) ; } } catch ( Exception e ) { e . printStackTrace ( ) ; throw new SnappyError ( SnappyErrorCode . FAILED_TO_LOAD_NATIVE_LIBRARY , e . getMessage ( ) ) ; } isLoaded = true ; } } | Load a native library of snappy - java |
31,692 | private static File extractLibraryFile ( String libFolderForCurrentOS , String libraryFileName , String targetFolder ) { String nativeLibraryFilePath = libFolderForCurrentOS + "/" + libraryFileName ; String uuid = UUID . randomUUID ( ) . toString ( ) ; String extractedLibFileName = String . format ( "snappy-%s-%s-%s" , getVersion ( ) , uuid , libraryFileName ) ; File extractedLibFile = new File ( targetFolder , extractedLibFileName ) ; try { InputStream reader = null ; FileOutputStream writer = null ; try { reader = SnappyLoader . class . getResourceAsStream ( nativeLibraryFilePath ) ; try { writer = new FileOutputStream ( extractedLibFile ) ; byte [ ] buffer = new byte [ 8192 ] ; int bytesRead = 0 ; while ( ( bytesRead = reader . read ( buffer ) ) != - 1 ) { writer . write ( buffer , 0 , bytesRead ) ; } } finally { if ( writer != null ) { writer . close ( ) ; } } } finally { if ( reader != null ) { reader . close ( ) ; } extractedLibFile . deleteOnExit ( ) ; } boolean success = extractedLibFile . setReadable ( true ) && extractedLibFile . setWritable ( true , true ) && extractedLibFile . setExecutable ( true ) ; if ( ! success ) { } { InputStream nativeIn = null ; InputStream extractedLibIn = null ; try { nativeIn = SnappyLoader . class . getResourceAsStream ( nativeLibraryFilePath ) ; extractedLibIn = new FileInputStream ( extractedLibFile ) ; if ( ! contentsEquals ( nativeIn , extractedLibIn ) ) { throw new SnappyError ( SnappyErrorCode . FAILED_TO_LOAD_NATIVE_LIBRARY , String . format ( "Failed to write a native library file at %s" , extractedLibFile ) ) ; } } finally { if ( nativeIn != null ) { nativeIn . close ( ) ; } if ( extractedLibIn != null ) { extractedLibIn . close ( ) ; } } } return new File ( targetFolder , extractedLibFileName ) ; } catch ( IOException e ) { e . printStackTrace ( System . err ) ; return null ; } } | Extract the specified library file to the target folder |
31,693 | public static String getVersion ( ) { URL versionFile = SnappyLoader . class . getResource ( "/META-INF/maven/org.xerial.snappy/snappy-java/pom.properties" ) ; if ( versionFile == null ) { versionFile = SnappyLoader . class . getResource ( "/org/xerial/snappy/VERSION" ) ; } String version = "unknown" ; try { if ( versionFile != null ) { Properties versionData = new Properties ( ) ; versionData . load ( versionFile . openStream ( ) ) ; version = versionData . getProperty ( "version" , version ) ; if ( version . equals ( "unknown" ) ) { version = versionData . getProperty ( "SNAPPY_VERSION" , version ) ; } version = version . trim ( ) . replaceAll ( "[^0-9M\\.]" , "" ) ; } } catch ( IOException e ) { System . err . println ( e ) ; } return version ; } | Get the snappy - java version by reading pom . properties embedded in jar . This version data is used as a suffix of a dll file extracted from the jar . |
31,694 | public boolean run ( ) { otherApks . forEach ( otherApk -> { checkArgument ( otherApk . exists ( ) , "Could not find other APK: " + otherApk ) ; } ) ; checkArgument ( testApk . exists ( ) , "Could not find test APK: " + testApk ) ; AndroidDebugBridge adb = SpoonUtils . initAdb ( androidSdk , adbTimeout ) ; try { final SpoonInstrumentationInfo testInfo = parseFromFile ( testApk ) ; Set < String > serials = this . serials ; if ( serials . isEmpty ( ) ) { serials = SpoonUtils . findAllDevices ( adb , testInfo . getMinSdkVersion ( ) ) ; } if ( this . skipDevices != null && ! this . skipDevices . isEmpty ( ) ) { serials = new LinkedHashSet < > ( serials ) ; serials . removeAll ( this . skipDevices ) ; } if ( serials . isEmpty ( ) && ! allowNoDevices ) { throw new RuntimeException ( "No device(s) found." ) ; } SpoonSummary summary = runTests ( adb , serials , testInfo ) ; new HtmlRenderer ( summary , SpoonUtils . GSON , output ) . render ( ) ; if ( codeCoverage ) { try { SpoonCoverageMerger . mergeCoverageFiles ( serials , output ) ; logDebug ( debug , "Merging of coverage files done." ) ; } catch ( IOException exception ) { throw new RuntimeException ( "Error while merging coverage files. " + "Did you set the \"testCoverageEnabled\" flag in your build.gradle?" , exception ) ; } } return parseOverallSuccess ( summary ) ; } finally { if ( terminateAdb ) { AndroidDebugBridge . terminate ( ) ; } } } | Install and execute the tests on all specified devices . |
31,695 | static String scrubModel ( String manufacturer , String model ) { if ( manufacturer == null || model == null ) { return model ; } if ( model . regionMatches ( true , 0 , manufacturer , 0 , manufacturer . length ( ) ) ) { model = model . substring ( manufacturer . length ( ) ) ; } if ( model . length ( ) > 0 && ( model . charAt ( 0 ) == ' ' || model . charAt ( 0 ) == '-' ) ) { model = model . substring ( 1 ) ; } return model ; } | Scrub the model so that it does not contain redundant data . |
31,696 | static String scrubLanguage ( String language ) { if ( "ldpi" . equals ( language ) || "mdpi" . equals ( language ) || "hdpi" . equals ( language ) || "xhdpi" . equals ( language ) ) { return null ; } return language ; } | Scrub the language so it does not contain bad data . |
31,697 | public int find ( String string ) { if ( m_strings == null ) { return - 1 ; } for ( int i = 0 ; i < m_strings . length - 1 ; i ++ ) { if ( m_strings [ i ] . equals ( string ) ) { return i ; } } return - 1 ; } | Finds index of the string . Returns - 1 if the string was not found . |
31,698 | private String stringAt ( int index ) { int offset = m_stringOffsets [ index ] ; ByteBuffer buffer = ByteBuffer . wrap ( m_stringPool , offset , m_stringPool . length - offset ) . order ( ByteOrder . BIG_ENDIAN ) ; int length = decodeLength ( buffer ) ; StringBuilder stringBuilder = new StringBuilder ( ) ; for ( int i = 0 ; i < length ; i ++ ) { if ( m_isUtf8 ) { stringBuilder . append ( ( char ) buffer . get ( ) ) ; } else { int byte1 = buffer . get ( ) ; int byte2 = buffer . get ( ) ; stringBuilder . append ( ( char ) ( byte2 | byte1 ) ) ; } } return stringBuilder . toString ( ) ; } | Extracts a string from the string pool at the given index . |
31,699 | static SpoonInstrumentationInfo parseFromFile ( File apkTestFile ) { try ( ZipFile zip = new ZipFile ( apkTestFile ) ) { ZipEntry entry = zip . getEntry ( "AndroidManifest.xml" ) ; InputStream is = zip . getInputStream ( entry ) ; AXMLParser parser = new AXMLParser ( is ) ; int eventType = parser . getType ( ) ; String appPackage = null ; Integer minSdkVersion = null ; String testPackage = null ; String testRunnerClass = null ; while ( eventType != AXMLParser . END_DOCUMENT ) { if ( eventType == AXMLParser . START_TAG ) { String parserName = parser . getName ( ) ; boolean isManifest = "manifest" . equals ( parserName ) ; boolean isUsesSdk = "uses-sdk" . equals ( parserName ) ; boolean isInstrumentation = "instrumentation" . equals ( parserName ) ; if ( isManifest || isInstrumentation || isUsesSdk ) { for ( int i = 0 ; i < parser . getAttributeCount ( ) ; i ++ ) { String parserAttributeName = parser . getAttributeName ( i ) ; if ( isManifest && "package" . equals ( parserAttributeName ) ) { testPackage = parser . getAttributeValueString ( i ) ; } else if ( isUsesSdk && "minSdkVersion" . equals ( parserAttributeName ) ) { minSdkVersion = parser . getAttributeValue ( i ) ; } else if ( isInstrumentation && "targetPackage" . equals ( parserAttributeName ) ) { appPackage = parser . getAttributeValueString ( i ) ; } else if ( isInstrumentation && "name" . equals ( parserAttributeName ) ) { testRunnerClass = parser . getAttributeValueString ( i ) ; } } } } eventType = parser . next ( ) ; } checkNotNull ( testPackage , "Could not find test application package." ) ; checkNotNull ( appPackage , "Could not find application package." ) ; checkNotNull ( testRunnerClass , "Could not find test runner class." ) ; if ( testRunnerClass . startsWith ( "." ) ) { testRunnerClass = testPackage + testRunnerClass ; } else if ( ! testRunnerClass . contains ( "." ) ) { testRunnerClass = testPackage + "." + testRunnerClass ; } return new SpoonInstrumentationInfo ( appPackage , minSdkVersion , testPackage , testRunnerClass ) ; } catch ( IOException e ) { throw new RuntimeException ( "Unable to parse test app AndroidManifest.xml." , e ) ; } } | Parse key information from an instrumentation APK s manifest . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.