idx
int64
0
41.2k
question
stringlengths
73
5.81k
target
stringlengths
5
918
21,300
public static void copyAll ( Resource base , Resource [ ] resources , File targetDir ) throws IOException { final URL baseUrl = base . getURL ( ) ; for ( Resource resource : resources ) { final InputStream input = resource . getInputStream ( ) ; final File target = new File ( targetDir , resource . getURL ( ) . toStrin...
Copies all the resources for the given target directory . The base resource serves to calculate the relative path such that the directory structure is maintained .
21,301
public static void copy ( byte [ ] in , OutputStream out ) throws IOException { assert in != null : "No input byte array specified" ; assert out != null : "No output stream specified" ; try { out . write ( in ) ; } finally { try { out . close ( ) ; } catch ( IOException ex ) { } } }
Copy the contents of the given byte array to the given OutputStream . Closes the stream when done .
21,302
public static byte [ ] copyToByteArray ( InputStream in ) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream ( BUFFER_SIZE ) ; copy ( in , out ) ; return out . toByteArray ( ) ; }
Copy the contents of the given InputStream into a new byte array . Closes the stream when done .
21,303
public static int copy ( Reader in , Writer out ) throws IOException { assert in != null : "No input Reader specified" ; assert out != null : "No output Writer specified" ; try { int byteCount = 0 ; char [ ] buffer = new char [ BUFFER_SIZE ] ; int bytesRead = - 1 ; while ( ( bytesRead = in . read ( buffer ) ) != - 1 ) ...
Copy the contents of the given Reader to the given Writer . Closes both when done .
21,304
public static void copy ( String in , Writer out ) throws IOException { assert in != null : "No input String specified" ; assert out != null : "No output Writer specified" ; try { out . write ( in ) ; } finally { try { out . close ( ) ; } catch ( IOException ex ) { } } }
Copy the contents of the given String to the given output Writer . Closes the write when done .
21,305
public static String copyToString ( Reader in ) throws IOException { StringWriter out = new StringWriter ( ) ; copy ( in , out ) ; return out . toString ( ) ; }
Copy the contents of the given Reader into a String . Closes the reader when done .
21,306
protected void pulsate ( ServiceInstance instance , HealthStatus status ) { Optional < String > opt = instance . getInstanceId ( ) ; if ( ! opt . isPresent ( ) ) { if ( instance . getMetadata ( ) . contains ( "instanceId" ) ) { opt = Optional . of ( instance . getMetadata ( ) . asMap ( ) . get ( "instanceId" ) ) ; } el...
If custom health check is enabled this sends a heartbeat to it . In most cases aws monitoring works off polling an application s endpoint
21,307
protected void deregister ( ServiceInstance instance ) { if ( instance . getInstanceId ( ) . isPresent ( ) ) { DeregisterInstanceRequest deregisterInstanceRequest = new DeregisterInstanceRequest ( ) . withServiceId ( route53AutoRegistrationConfiguration . getAwsServiceId ( ) ) . withInstanceId ( instance . getInstanceI...
shutdown instance if it fails health check can gracefully stop .
21,308
public void deleteService ( String serviceId ) { DeleteServiceRequest deleteServiceRequest = new DeleteServiceRequest ( ) . withId ( serviceId ) ; getDiscoveryClient ( ) . deleteService ( deleteServiceRequest ) ; }
These are convenience methods to help cleanup things like integration test data .
21,309
public void deleteNamespace ( String namespaceId ) { DeleteNamespaceRequest deleteNamespaceRequest = new DeleteNamespaceRequest ( ) . withId ( namespaceId ) ; getDiscoveryClient ( ) . deleteNamespace ( deleteNamespaceRequest ) ; }
these are convenience methods to help cleanup things like integration test data .
21,310
public String createService ( AWSServiceDiscovery serviceDiscovery , String name , String description , String namespaceId , Long ttl ) { if ( serviceDiscovery == null ) { serviceDiscovery = AWSServiceDiscoveryClient . builder ( ) . withClientConfiguration ( clientConfiguration . getClientConfiguration ( ) ) . build ( ...
Create service helper for integration tests .
21,311
private GetOperationResult checkOperation ( String operationId ) { String result = "" ; GetOperationResult opResult = null ; try { while ( ! result . equals ( "SUCCESS" ) && ! result . equals ( "FAIL" ) ) { opResult = getDiscoveryClient ( ) . getOperation ( new GetOperationRequest ( ) . withOperationId ( operationId ) ...
Loop for checking of the call to aws is complete or not . This is the non - async version used for testing
21,312
public void setSerialization ( Map < SerializationFeature , Boolean > serialization ) { if ( CollectionUtils . isNotEmpty ( serialization ) ) { this . serialization = serialization ; } }
Sets the serialization features to use .
21,313
public void setDeserialization ( Map < DeserializationFeature , Boolean > deserialization ) { if ( CollectionUtils . isNotEmpty ( deserialization ) ) { this . deserialization = deserialization ; } }
Sets the deserialization features to use .
21,314
public void setMapper ( Map < MapperFeature , Boolean > mapper ) { if ( CollectionUtils . isNotEmpty ( mapper ) ) { this . mapper = mapper ; } }
Sets the object mapper features to use .
21,315
public void setParser ( Map < JsonParser . Feature , Boolean > parser ) { if ( CollectionUtils . isNotEmpty ( parser ) ) { this . parser = parser ; } }
Sets the parser features to use .
21,316
public void setGenerator ( Map < JsonGenerator . Feature , Boolean > generator ) { if ( CollectionUtils . isNotEmpty ( generator ) ) { this . generator = generator ; } }
Sets the generator features to use .
21,317
@ SuppressWarnings ( "unused" ) protected final void warnMissingProperty ( Class type , String method , String property ) { if ( LOG . isWarnEnabled ( ) ) { LOG . warn ( "Configuration property [{}] could not be set as the underlying method [{}] does not exist on builder [{}]. This usually indicates the configuration o...
Allows printing warning messages produced by the compiler .
21,318
@ SuppressWarnings ( { "unchecked" , "unused" } ) protected final Object getProxiedBean ( BeanContext beanContext ) { DefaultBeanContext defaultBeanContext = ( DefaultBeanContext ) beanContext ; Optional < String > qualifier = getAnnotationMetadata ( ) . getAnnotationNameByStereotype ( javax . inject . Qualifier . clas...
Resolves the proxied bean instance for this bean .
21,319
@ SuppressWarnings ( "unused" ) protected final AbstractBeanDefinition addPreDestroy ( Class declaringType , String method , Argument [ ] arguments , AnnotationMetadata annotationMetadata , boolean requiresReflection ) { return addInjectionPointInternal ( declaringType , method , arguments , annotationMetadata , requir...
Adds a pre destroy method definition .
21,320
@ SuppressWarnings ( { "WeakerAccess" , "unused" } ) protected Object injectBean ( BeanResolutionContext resolutionContext , BeanContext context , Object bean ) { return bean ; }
The default implementation which provides no injection . To be overridden by compile time tooling .
21,321
@ SuppressWarnings ( { "WeakerAccess" , "unused" } ) protected Object injectAnother ( BeanResolutionContext resolutionContext , BeanContext context , Object bean ) { DefaultBeanContext defaultContext = ( DefaultBeanContext ) context ; if ( bean == null ) { throw new BeanInstantiationException ( resolutionContext , "Bea...
Inject another bean for example one created via factory .
21,322
@ SuppressWarnings ( { "WeakerAccess" , "unused" , "unchecked" } ) protected Object postConstruct ( BeanResolutionContext resolutionContext , BeanContext context , Object bean ) { DefaultBeanContext defaultContext = ( DefaultBeanContext ) context ; Collection < BeanRegistration < BeanInitializedEventListener > > beanIn...
Default postConstruct hook that only invokes methods that require reflection . Generated subclasses should override to call methods that don t require reflection .
21,323
protected Object preDestroy ( BeanResolutionContext resolutionContext , BeanContext context , Object bean ) { DefaultBeanContext defaultContext = ( DefaultBeanContext ) context ; for ( int i = 0 ; i < methodInjectionPoints . size ( ) ; i ++ ) { MethodInjectionPoint methodInjectionPoint = methodInjectionPoints . get ( i...
Default preDestroy hook that only invokes methods that require reflection . Generated subclasses should override to call methods that don t require reflection .
21,324
@ SuppressWarnings ( "WeakerAccess" ) protected void injectBeanMethod ( BeanResolutionContext resolutionContext , DefaultBeanContext context , int methodIndex , Object bean ) { MethodInjectionPoint methodInjectionPoint = methodInjectionPoints . get ( methodIndex ) ; Argument [ ] methodArgumentTypes = methodInjectionPoi...
Inject a bean method that requires reflection .
21,325
@ SuppressWarnings ( "unused" ) protected final void injectBeanField ( BeanResolutionContext resolutionContext , DefaultBeanContext context , int index , Object bean ) { FieldInjectionPoint fieldInjectionPoint = fieldInjectionPoints . get ( index ) ; boolean isInject = fieldInjectionPoint . getAnnotationMetadata ( ) . ...
Injects the value of a field of a bean that requires reflection .
21,326
@ SuppressWarnings ( "unused" ) protected final < T1 > Optional < T1 > getValueForPath ( BeanResolutionContext resolutionContext , BeanContext context , Argument < T1 > propertyType , String ... propertyPath ) { if ( context instanceof PropertyResolver ) { PropertyResolver propertyResolver = ( PropertyResolver ) contex...
Resolve a value for the given field of the given type and path .
21,327
protected final boolean containsValueForField ( BeanResolutionContext resolutionContext , BeanContext context , int fieldIndex ) { if ( context instanceof ApplicationContext ) { FieldInjectionPoint injectionPoint = fieldInjectionPoints . get ( fieldIndex ) ; final AnnotationMetadata annotationMetadata = injectionPoint ...
Obtains a value for the given field argument .
21,328
@ SuppressWarnings ( "MagicNumber" ) protected Resource [ ] findAllClassPathResources ( String location ) throws IOException { String path = location ; if ( path . startsWith ( "/" ) ) { path = path . substring ( 1 ) ; } Enumeration < URL > resourceUrls = getClassLoader ( ) . getResources ( path ) ; Set < Resource > re...
Find all class location resources with the given location via the ClassLoader .
21,329
@ SuppressWarnings ( "MagicNumber" ) protected Set < Resource > doFindPathMatchingJarResources ( Resource rootDirResource , String subPattern ) throws IOException { URLConnection con = rootDirResource . getURL ( ) . openConnection ( ) ; JarFile jarFile ; String jarFileUrl ; String rootEntryPath ; boolean newJarFile = f...
Find all resources in jar files that match the given location pattern via the Ant - style PathMatcher .
21,330
@ SuppressWarnings ( "MagicNumber" ) protected Set < File > retrieveMatchingFiles ( File rootDir , String pattern ) throws IOException { if ( ! rootDir . exists ( ) ) { return Collections . emptySet ( ) ; } if ( ! rootDir . isDirectory ( ) ) { return Collections . emptySet ( ) ; } if ( ! rootDir . canRead ( ) ) { retur...
Retrieve files that match the given path pattern checking the given directory and its subdirectories .
21,331
protected void doRetrieveMatchingFiles ( String fullPattern , File dir , Set < File > result ) throws IOException { File [ ] dirContents = dir . listFiles ( ) ; if ( dirContents == null ) { return ; } for ( File content : dirContents ) { String currPath = content . getAbsolutePath ( ) . replace ( File . separator , "/"...
Recursively retrieve files that match the given pattern adding them to the given result list .
21,332
public Cookie put ( CharSequence name , Cookie cookie ) { return cookies . put ( name , cookie ) ; }
Put a new cookie .
21,333
public boolean canRetry ( Throwable exception ) { if ( exception == null ) { return false ; } Class < ? extends Throwable > exceptionClass = exception . getClass ( ) ; if ( hasIncludes && ! includes . contains ( exceptionClass ) ) { return false ; } else if ( hasExcludes && excludes . contains ( exceptionClass ) ) { re...
Should a retry attempt occur .
21,334
public static SQLMethodInvokeExpr makeBinaryMethodField ( SQLBinaryOpExpr expr , String alias , boolean first ) throws SqlParseException { List < SQLExpr > params = new ArrayList < > ( ) ; String scriptFieldAlias ; if ( first && ( alias == null || alias . equals ( "" ) ) ) { scriptFieldAlias = "field_" + SQLFunctions ....
binary method can nested
21,335
public static QueryAction create ( Client client , String sql ) throws SqlParseException , SQLFeatureNotSupportedException { sql = sql . replaceAll ( "\n" , " " ) ; String firstWord = sql . substring ( 0 , sql . indexOf ( ' ' ) ) ; switch ( firstWord . toUpperCase ( ) ) { case "SELECT" : SQLQueryExpr sqlExpr = ( SQLQue...
Create the compatible Query object based on the SQL query .
21,336
public static String hitsAsStringResult ( SearchHits results , MetaSearchResult metaResults ) throws IOException { if ( results == null ) return null ; Object [ ] searchHits ; searchHits = new Object [ ( int ) results . getTotalHits ( ) ] ; int i = 0 ; for ( SearchHit hit : results ) { HashMap < String , Object > value...
use our deserializer instead of results toXcontent because the source field is differnet from sourceAsMap .
21,337
public void execute ( ) throws Exception { ActionRequest request = requestBuilder . request ( ) ; if ( requestBuilder instanceof JoinRequestBuilder ) { executeJoinRequestAndSendResponse ( ) ; } else if ( request instanceof SearchRequest ) { client . search ( ( SearchRequest ) request , new RestStatusToXContentListener ...
Execute the ActionRequest and returns the REST response using the channel .
21,338
public String [ ] getIndexArr ( ) { String [ ] indexArr = new String [ this . from . size ( ) ] ; for ( int i = 0 ; i < indexArr . length ; i ++ ) { indexArr [ i ] = this . from . get ( i ) . getIndex ( ) ; } return indexArr ; }
Get the indexes the query refer to .
21,339
public String [ ] getTypeArr ( ) { List < String > list = new ArrayList < > ( ) ; From index = null ; for ( int i = 0 ; i < from . size ( ) ; i ++ ) { index = from . get ( i ) ; if ( index . getType ( ) != null && index . getType ( ) . trim ( ) . length ( ) > 0 ) { list . add ( index . getType ( ) ) ; } } if ( list . s...
Get the types the query refer to .
21,340
private void initFromSPIServiceLoader ( ) { String property = System . getProperty ( "druid.load.spifilter.skip" ) ; if ( property != null ) { return ; } ServiceLoader < Filter > druidAutoFilterLoader = ServiceLoader . load ( Filter . class ) ; for ( Filter autoFilter : druidAutoFilterLoader ) { AutoLoad autoLoad = aut...
load filters from SPI ServiceLoader
21,341
private boolean explanSpecialCondWithBothSidesAreLiterals ( SQLBinaryOpExpr bExpr , Where where ) throws SqlParseException { if ( ( bExpr . getLeft ( ) instanceof SQLNumericLiteralExpr || bExpr . getLeft ( ) instanceof SQLCharExpr ) && ( bExpr . getRight ( ) instanceof SQLNumericLiteralExpr || bExpr . getRight ( ) inst...
some where conditions eg . 1 = 1 or 3 > 2 or a = b
21,342
private boolean explanSpecialCondWithBothSidesAreProperty ( SQLBinaryOpExpr bExpr , Where where ) throws SqlParseException { if ( ( bExpr . getLeft ( ) instanceof SQLPropertyExpr || bExpr . getLeft ( ) instanceof SQLIdentifierExpr ) && ( bExpr . getRight ( ) instanceof SQLPropertyExpr || bExpr . getRight ( ) instanceof...
some where conditions eg . field1 = field2 or field1 > field2
21,343
private void setIndicesAndTypes ( ) { request . setIndices ( query . getIndexArr ( ) ) ; String [ ] typeArr = query . getTypeArr ( ) ; if ( typeArr != null ) { request . setTypes ( typeArr ) ; } }
Set indices and types to the search request .
21,344
private void setWhere ( Where where ) throws SqlParseException { if ( where != null ) { BoolQueryBuilder boolQuery = QueryMaker . explan ( where , this . select . isQuery ) ; request . setQuery ( boolQuery ) ; } }
Create filters or queries based on the Where clause .
21,345
private void setSorts ( List < Order > orderBys ) { for ( Order order : orderBys ) { if ( order . getNestedPath ( ) != null ) { request . addSort ( SortBuilders . fieldSort ( order . getName ( ) ) . order ( SortOrder . valueOf ( order . getType ( ) ) ) . setNestedSort ( new NestedSortBuilder ( order . getNestedPath ( )...
Add sorts to the elasticsearch query based on the ORDER BY clause .
21,346
private void setLimit ( int from , int size ) { request . setFrom ( from ) ; if ( size > - 1 ) { request . setSize ( size ) ; } }
Add from and size to the ES query based on the LIMIT clause
21,347
public QueryAction explain ( String sql ) throws SqlParseException , SQLFeatureNotSupportedException { return ESActionFactory . create ( client , sql ) ; }
Prepare action And transform sql into ES ActionRequest
21,348
private ValuesSourceAggregationBuilder makeCountAgg ( MethodField field ) { if ( "DISTINCT" . equals ( field . getOption ( ) ) ) { if ( field . getParams ( ) . size ( ) == 1 ) { return AggregationBuilders . cardinality ( field . getAlias ( ) ) . field ( field . getParams ( ) . get ( 0 ) . value . toString ( ) ) ; } els...
Create count aggregation .
21,349
private void setIndicesAndTypes ( ) { DeleteByQueryRequest innerRequest = request . request ( ) ; innerRequest . indices ( query . getIndexArr ( ) ) ; String [ ] typeArr = query . getTypeArr ( ) ; if ( typeArr != null ) { innerRequest . getSearchRequest ( ) . types ( typeArr ) ; } }
Set indices and types to the delete by query request .
21,350
private MinusOneFieldAndOptimizationResult runWithScrollingAndAddFilter ( String firstFieldName , String secondFieldName ) throws SqlParseException { SearchResponse scrollResp = ElasticUtils . scrollOneTimeWithHits ( this . client , this . builder . getFirstSearchRequest ( ) , builder . getOriginalSelect ( true ) , thi...
1 . 1 . 2 add all results left from miniset to bigset
21,351
public static String convertClassNameToUnderscoreName ( String name ) { StringBuilder result = new StringBuilder ( ) ; if ( name != null ) { int len = name . length ( ) ; if ( len > 0 ) { result . append ( name . charAt ( 0 ) ) ; for ( int i = 1 ; i < len ; i ++ ) { if ( true == Character . isUpperCase ( name . charAt ...
Convert a class name with underscores to the corresponding column name using _ . A name like CustomerNumber class name would match a CUSTOMER_NUMBER .
21,352
public static String convertUnderscoreNameToClassName ( String name ) { StringBuffer result = new StringBuffer ( ) ; boolean nextIsUpper = false ; if ( name != null ) { int len = name . length ( ) ; if ( len > 0 ) { String s = String . valueOf ( name . charAt ( 0 ) ) ; result . append ( s . toUpperCase ( ) ) ; for ( in...
Convert a column name with underscores to the corresponding class name using camel case . A name like customer_number would match a CustomerNumber class name .
21,353
public Object convert ( Class type , Object value ) { if ( value == null ) { if ( useDefault ) { return ( defaultValue ) ; } else { throw new ConversionException ( "No value specified" ) ; } } if ( value instanceof java . sql . Date && java . sql . Date . class . equals ( type ) ) { return value ; } else if ( value ins...
Convert the specified input object into an output object of the specified type .
21,354
private static void makeAllColumnsPrimaryKeysIfNoPrimaryKeysFound ( Table table ) { if ( ( table != null ) && ( table . getPrimaryKeyColumns ( ) != null ) && ( table . getPrimaryKeyColumns ( ) . length == 0 ) ) { Column [ ] allCoumns = table . getColumns ( ) ; for ( Column column : allCoumns ) { column . setPrimaryKey ...
Treat tables with no primary keys as a table with all primary keys .
21,355
public static long sizeof ( final Object obj ) { if ( null == obj || isSharedFlyweight ( obj ) ) { return 0 ; } final IdentityHashMap visited = new IdentityHashMap ( 80000 ) ; try { return computeSizeof ( obj , visited , CLASS_METADATA_CACHE ) ; } catch ( RuntimeException re ) { return - 1 ; } catch ( NoClassDefFoundEr...
Estimates the full size of the object graph rooted at obj . Duplicate data instances are correctly accounted for . The implementation is not recursive .
21,356
public static long sizedelta ( final Object base , final Object obj ) { if ( null == obj || isSharedFlyweight ( obj ) ) { return 0 ; } if ( null == base ) { throw new IllegalArgumentException ( "null input: base" ) ; } final IdentityHashMap visited = new IdentityHashMap ( 40000 ) ; try { computeSizeof ( base , visited ...
Estimates the full size of the object graph rooted at obj by pre - populating the visited set with the object graph rooted at base . The net effect is to compute the size of obj by summing over all instance data contained in obj but not in base .
21,357
protected boolean isPackableWith ( Object value , int choose ) { if ( value == null ) { return false ; } if ( choose == CHOOSE_EXTENSION ) { if ( value . equals ( getDefaultFileExtension ( ) ) ) { return true ; } } else if ( choose == CHOOSE_NAME ) { if ( value . equals ( getName ( ) ) ) { return true ; } } return fals...
String Chooser .
21,358
public static PackableObject identifyByHeader ( File file , List packables ) throws IOException { FileInputStream fis = null ; try { fis = new FileInputStream ( file ) ; byte [ ] headerBytes = new byte [ 20 ] ; fis . read ( headerBytes , 0 , 20 ) ; Iterator iter = packables . iterator ( ) ; while ( iter . hasNext ( ) )...
Compares a file to a list of packables and identifies an object by header . If no matching header is found it identifies the file by file extension . If identification was not successfull null is returned
21,359
public static boolean isNumeric ( int sqlType ) { return ( Types . BIT == sqlType ) || ( Types . BIGINT == sqlType ) || ( Types . DECIMAL == sqlType ) || ( Types . DOUBLE == sqlType ) || ( Types . FLOAT == sqlType ) || ( Types . INTEGER == sqlType ) || ( Types . NUMERIC == sqlType ) || ( Types . REAL == sqlType ) || ( ...
Check whether the given SQL type is numeric .
21,360
protected AuthenticationInfo customInfoIfNecessay ( AuthenticationInfo authenticationInfo ) { if ( StringUtils . isNotBlank ( customUser ) ) { authenticationInfo . setUsername ( customUser ) ; } if ( StringUtils . isNotBlank ( customPasswd ) ) { authenticationInfo . setPassword ( customPasswd ) ; } if ( StringUtils . i...
override custom field
21,361
public void createPersistent ( String path , Object data , boolean createParents ) throws ZkInterruptedException , IllegalArgumentException , ZkException , RuntimeException { try { create ( path , data , CreateMode . PERSISTENT ) ; } catch ( ZkNodeExistsException e ) { if ( ! createParents ) { throw e ; } } catch ( ZkN...
Create a persistent Sequential node .
21,362
public String createPersistentSequential ( String path , Object data ) throws ZkInterruptedException , IllegalArgumentException , ZkException , RuntimeException { return create ( path , data , CreateMode . PERSISTENT_SEQUENTIAL ) ; }
Create a persistent sequental node .
21,363
public void createEphemeral ( final String path ) throws ZkInterruptedException , IllegalArgumentException , ZkException , RuntimeException { create ( path , null , CreateMode . EPHEMERAL ) ; }
Create an ephemeral node .
21,364
public String createEphemeralSequential ( final String path , final Object data ) throws ZkInterruptedException , IllegalArgumentException , ZkException , RuntimeException { return create ( path , data , CreateMode . EPHEMERAL_SEQUENTIAL ) ; }
Create an ephemeral sequential node .
21,365
public List < String > watchForChilds ( final String path ) { if ( _zookeeperEventThread != null && Thread . currentThread ( ) == _zookeeperEventThread ) { throw new IllegalArgumentException ( "Must not be done in the zookeeper event thread." ) ; } return retryUntilConnected ( new Callable < List < String > > ( ) { pub...
Installs a child watch for the given path .
21,366
public void close ( ) throws ZkInterruptedException { if ( _connection == null ) { return ; } LOG . debug ( "Closing ZkClient..." ) ; getEventLock ( ) . lock ( ) ; try { setShutdownTrigger ( true ) ; _eventThread . interrupt ( ) ; _eventThread . join ( 2000 ) ; _connection . close ( ) ; _connection = null ; } catch ( I...
Close the client .
21,367
public String createNoRetry ( final String path , final byte [ ] data , final CreateMode mode ) throws KeeperException , InterruptedException { return zookeeper . create ( path , data , acl , mode ) ; }
add by ljh at 2012 - 09 - 13
21,368
public java . util . logging . Logger getParentLogger ( ) throws SQLFeatureNotSupportedException { try { Method getParentLoggerMethod = CommonDataSource . class . getDeclaredMethod ( "getParentLogger" , new Class < ? > [ 0 ] ) ; return ( java . util . logging . Logger ) getParentLoggerMethod . invoke ( delegate , new O...
implemented from JDK7
21,369
static Iterator < Page > lazySearch ( final Wikipedia wikipedia , final String query ) { final Response < Page > first = wikipedia . search ( query ) ; if ( first . nextOffset == null ) { return first . iterator ( ) ; } return new Iterator < Page > ( ) { Iterator < Page > current = first . iterator ( ) ; Long nextOffse...
this will lazily continue searches making new http calls as necessary .
21,370
public WikipediaExample . Response < X > read ( JsonReader reader ) throws IOException { WikipediaExample . Response < X > pages = new WikipediaExample . Response < X > ( ) ; reader . beginObject ( ) ; while ( reader . hasNext ( ) ) { String nextName = reader . nextName ( ) ; if ( "query" . equals ( nextName ) ) { read...
the wikipedia api doesn t use json arrays rather a series of nested objects .
21,371
public static HeaderTemplate append ( HeaderTemplate headerTemplate , Iterable < String > values ) { Set < String > headerValues = new LinkedHashSet < > ( headerTemplate . getValues ( ) ) ; headerValues . addAll ( StreamSupport . stream ( values . spliterator ( ) , false ) . filter ( Util :: isNotBlank ) . collect ( Co...
Append values to a Header Template .
21,372
public String expand ( Map < String , ? > variables ) { if ( variables == null ) { throw new IllegalArgumentException ( "variable map is required." ) ; } StringBuilder resolved = new StringBuilder ( ) ; for ( TemplateChunk chunk : this . templateChunks ) { if ( chunk instanceof Expression ) { String resolvedExpression ...
Expand the template .
21,373
public List < String > getVariables ( ) { return this . templateChunks . stream ( ) . filter ( templateChunk -> Expression . class . isAssignableFrom ( templateChunk . getClass ( ) ) ) . map ( templateChunk -> ( ( Expression ) templateChunk ) . getName ( ) ) . filter ( Objects :: nonNull ) . collect ( Collectors . toLi...
Variable names contained in the template .
21,374
public List < String > getLiterals ( ) { return this . templateChunks . stream ( ) . filter ( templateChunk -> Literal . class . isAssignableFrom ( templateChunk . getClass ( ) ) ) . map ( TemplateChunk :: toString ) . filter ( Objects :: nonNull ) . collect ( Collectors . toList ( ) ) ; }
List of all Literals in the Template .
21,375
private void parseFragment ( String fragment , boolean query ) { ChunkTokenizer tokenizer = new ChunkTokenizer ( fragment ) ; while ( tokenizer . hasNext ( ) ) { String chunk = tokenizer . next ( ) ; if ( chunk . startsWith ( "{" ) ) { FragmentType type = ( query ) ? FragmentType . QUERY : FragmentType . PATH_SEGMENT ;...
Parse a template fragment .
21,376
Callable < ? > invokeMethod ( MethodHandler methodHandler , Object [ ] arguments ) { return ( ) -> { try { return methodHandler . invoke ( arguments ) ; } catch ( Throwable th ) { if ( th instanceof FeignException ) { throw ( FeignException ) th ; } throw new RuntimeException ( th ) ; } } ; }
Invoke the Method Handler as a Callable .
21,377
boolean matches ( String value ) { if ( pattern == null ) { return true ; } return pattern . matcher ( value ) . matches ( ) ; }
Checks if the provided value matches the variable pattern if one is defined . Always true if no pattern is defined .
21,378
public static UriTemplate append ( UriTemplate uriTemplate , String fragment ) { return new UriTemplate ( uriTemplate . toString ( ) + fragment , uriTemplate . encodeSlash ( ) , uriTemplate . getCharset ( ) ) ; }
Append a uri fragment to the template .
21,379
private boolean isReactive ( Type type ) { if ( ! ParameterizedType . class . isAssignableFrom ( type . getClass ( ) ) ) { return false ; } ParameterizedType parameterizedType = ( ParameterizedType ) type ; Type raw = parameterizedType . getRawType ( ) ; return Arrays . asList ( ( ( Class ) raw ) . getInterfaces ( ) ) ...
Ensure that the type provided implements a Reactive Streams Publisher .
21,380
public static String encode ( String value ) { return encodeReserved ( value , FragmentType . URI , Util . UTF_8 ) ; }
Uri Encode the value using the default Charset . Already encoded values are skipped .
21,381
public static String encode ( String value , Charset charset ) { return encodeReserved ( value , FragmentType . URI , charset ) ; }
Uri Encode the value . Already encoded values are skipped .
21,382
public static String decode ( String value , Charset charset ) { try { return URLDecoder . decode ( value , charset . name ( ) ) ; } catch ( UnsupportedEncodingException uee ) { return value ; } }
Uri Decode the value .
21,383
public static String pathEncode ( String path , Charset charset ) { return encodeReserved ( path , FragmentType . PATH_SEGMENT , charset ) ; }
Uri Encode a Path Fragment .
21,384
public static String queryEncode ( String query , Charset charset ) { return encodeReserved ( query , FragmentType . QUERY , charset ) ; }
Uri Encode a Query Fragment .
21,385
public static String queryParamEncode ( String queryParam , Charset charset ) { return encodeReserved ( queryParam , FragmentType . QUERY_PARAM , charset ) ; }
Uri Encode a Query Parameter name or value .
21,386
public static String encodeReserved ( String value , FragmentType type , Charset charset ) { Matcher matcher = PCT_ENCODED_PATTERN . matcher ( value ) ; if ( ! matcher . find ( ) ) { return encodeChunk ( value , type , charset ) ; } int length = value . length ( ) ; StringBuilder encoded = new StringBuilder ( length + ...
Encodes the value preserving all reserved characters .. Values that are already pct - encoded are ignored .
21,387
private static String encodeChunk ( String value , FragmentType type , Charset charset ) { byte [ ] data = value . getBytes ( charset ) ; ByteArrayOutputStream encoded = new ByteArrayOutputStream ( ) ; for ( byte b : data ) { if ( type . isAllowed ( b ) ) { encoded . write ( b ) ; } else { pctEncode ( b , encoded ) ; }...
Encode a Uri Chunk ensuring that all reserved characters are also encoded .
21,388
private static void pctEncode ( byte data , ByteArrayOutputStream bos ) { bos . write ( '%' ) ; char hex1 = Character . toUpperCase ( Character . forDigit ( ( data >> 4 ) & 0xF , 16 ) ) ; char hex2 = Character . toUpperCase ( Character . forDigit ( data & 0xF , 16 ) ) ; bos . write ( hex1 ) ; bos . write ( hex2 ) ; }
Percent Encode the provided byte .
21,389
public static RequestTemplate from ( RequestTemplate requestTemplate ) { RequestTemplate template = new RequestTemplate ( requestTemplate . target , requestTemplate . fragment , requestTemplate . uriTemplate , requestTemplate . method , requestTemplate . charset , requestTemplate . body , requestTemplate . decodeSlash ...
Create a Request Template from an existing Request Template .
21,390
public RequestTemplate resolve ( Map < String , ? > variables ) { StringBuilder uri = new StringBuilder ( ) ; RequestTemplate resolved = RequestTemplate . from ( this ) ; if ( this . uriTemplate == null ) { this . uriTemplate = UriTemplate . create ( "" , ! this . decodeSlash , this . charset ) ; } uri . append ( this ...
Resolve all expressions using the variable value substitutions provided . Variable values will be pct - encoded if they are not already .
21,391
public RequestTemplate method ( String method ) { checkNotNull ( method , "method" ) ; try { this . method = HttpMethod . valueOf ( method ) ; } catch ( IllegalArgumentException iae ) { throw new IllegalArgumentException ( "Invalid HTTP Method: " + method ) ; } return this ; }
Set the Http Method .
21,392
public RequestTemplate uri ( String uri , boolean append ) { if ( UriUtils . isAbsolute ( uri ) ) { throw new IllegalArgumentException ( "url values must be not be absolute." ) ; } if ( uri == null ) { uri = "/" ; } else if ( ( ! uri . isEmpty ( ) && ! uri . startsWith ( "/" ) && ! uri . startsWith ( "{" ) && ! uri . s...
Set the uri for the request .
21,393
public RequestTemplate target ( String target ) { if ( Util . isBlank ( target ) ) { return this ; } if ( ! UriUtils . isAbsolute ( target ) ) { throw new IllegalArgumentException ( "target values must be absolute." ) ; } if ( target . endsWith ( "/" ) ) { target = target . substring ( 0 , target . length ( ) - 1 ) ; }...
Set the target host for this request .
21,394
public String url ( ) { StringBuilder url = new StringBuilder ( this . path ( ) ) ; if ( ! this . queries . isEmpty ( ) ) { url . append ( this . queryLine ( ) ) ; } if ( fragment != null ) { url . append ( fragment ) ; } return url . toString ( ) ; }
The URL for the request . If the template has not been resolved the url will represent a uri template .
21,395
public String path ( ) { StringBuilder path = new StringBuilder ( ) ; if ( this . target != null ) { path . append ( this . target ) ; } if ( this . uriTemplate != null ) { path . append ( this . uriTemplate . toString ( ) ) ; } if ( path . length ( ) == 0 ) { path . append ( "/" ) ; } return path . toString ( ) ; }
The Uri Path .
21,396
public List < String > variables ( ) { List < String > variables = new ArrayList < > ( this . uriTemplate . getVariables ( ) ) ; for ( QueryTemplate queryTemplate : this . queries . values ( ) ) { variables . addAll ( queryTemplate . getVariables ( ) ) ; } for ( HeaderTemplate headerTemplate : this . headers . values (...
List all of the template variable expressions for this template .
21,397
public RequestTemplate query ( String name , Iterable < String > values ) { return appendQuery ( name , values , this . collectionFormat ) ; }
Specify a Query String parameter with the specified values . Values can be literals or template expressions .
21,398
private RequestTemplate appendQuery ( String name , Iterable < String > values , CollectionFormat collectionFormat ) { if ( ! values . iterator ( ) . hasNext ( ) ) { this . queries . remove ( name ) ; return this ; } this . queries . compute ( name , ( key , queryTemplate ) -> { if ( queryTemplate == null ) { return Qu...
Appends the query name and values .
21,399
@ SuppressWarnings ( "unused" ) public RequestTemplate queries ( Map < String , Collection < String > > queries ) { if ( queries == null || queries . isEmpty ( ) ) { this . queries . clear ( ) ; } else { queries . forEach ( this :: query ) ; } return this ; }
Sets the Query Parameters .