idx
int64
0
165k
question
stringlengths
73
4.15k
target
stringlengths
5
918
len_question
int64
21
890
len_target
int64
3
255
40,000
private static ConditionWithApplicables methodWithUriAndAutoDiscovery ( final Method m , String uri ) { try { final URL resource = new SmartDiscoverer ( "restito" ) . discoverResource ( m , uri ) ; return new ConditionWithApplicables ( composite ( method ( m ) , uri ( uri ) ) , resourceContent ( resource ) ) ; } catch ...
Checks HTTP method URI and enables AutoDiscovery
145
10
40,001
public static Condition parameter ( final String key , final String ... parameterValues ) { return new Condition ( input -> Arrays . equals ( input . getParameters ( ) . get ( key ) , parameterValues ) ) ; }
Checks HTTP parameters . Also work with multi - valued parameters
45
12
40,002
public static Condition endsWithUri ( final String uri ) { return new Condition ( input -> input . getUri ( ) . endsWith ( uri ) ) ; }
URI ends with
37
3
40,003
public static Condition withPostBody ( ) { return new Condition ( input -> input . getPostBody ( ) != null && input . getPostBody ( ) . length ( ) > 0 ) ; }
Contains non - empty POST body
41
7
40,004
public static Condition basicAuth ( String username , String password ) { final String authString = username + ":" + password ; final String encodedAuthString = new String ( Base64 . encodeBase64 ( authString . getBytes ( ) ) ) ; return new Condition ( input -> ( "Basic " + encodedAuthString ) . equals ( input . getAut...
If basic authentication is provided
80
5
40,005
public static Condition withPostBodyContaining ( final String str ) { return new Condition ( input -> input . getPostBody ( ) != null && input . getPostBody ( ) . contains ( str ) ) ; }
With POST body containing string
45
5
40,006
public static Condition withPostBodyContaining ( final Pattern pattern ) { return new Condition ( input -> input . getPostBody ( ) . matches ( pattern . pattern ( ) ) ) ; }
With post body matching pattern
39
5
40,007
public < Result > Result submitRequest ( TDApiRequest apiRequest , Optional < String > apiKeyCache , TDHttpRequestHandler < Result > handler ) throws TDClientException { RequestContext requestContext = new RequestContext ( config , apiRequest , apiKeyCache ) ; try { return submitRequest ( requestContext , handler ) ; }...
A low - level method to submit a TD API request .
142
12
40,008
public < Result > Result call ( TDApiRequest apiRequest , Optional < String > apiKeyCache , final Function < InputStream , Result > contentStreamHandler ) { return submitRequest ( apiRequest , apiKeyCache , newByteStreamHandler ( contentStreamHandler ) ) ; }
Submit an API request and returns the byte InputStream . This stream is valid until exiting this function .
58
20
40,009
public < Result > Result call ( TDApiRequest apiRequest , Optional < String > apiKeyCache , final Class < Result > resultType ) throws TDClientException { return call ( apiRequest , apiKeyCache , objectMapper . getTypeFactory ( ) . constructType ( resultType ) ) ; }
Submit an API request and bind the returned JSON data into an object of the given result type . For mapping it uses Jackson object mapper .
64
28
40,010
@ SuppressWarnings ( value = "unchecked cast" ) public < Result > Result call ( TDApiRequest apiRequest , Optional < String > apiKeyCache , final JavaType resultType ) throws TDClientException { try { byte [ ] content = submitRequest ( apiRequest , apiKeyCache , byteArrayContentHandler ) ; if ( logger . isTraceEnabled ...
Submit an API request and bind the returned JSON data into an object of the given result jackson JavaType . For mapping it uses Jackson object mapper .
240
31
40,011
public Properties toProperties ( ) { Properties p = new Properties ( ) ; saveProperty ( p , Type . API_ENDPOINT , endpoint ) ; saveProperty ( p , Type . API_PORT , port ) ; saveProperty ( p , Type . USESSL , useSSL ) ; saveProperty ( p , Type . APIKEY , apiKey ) ; saveProperty ( p , Type . USER , user ) ; saveProperty ...
Output this configuration as a Properties object
377
7
40,012
@ Override public TDClient withApiKey ( String newApiKey ) { return new TDClient ( config , httpClient , Optional . of ( newApiKey ) ) ; }
Create a new TDClient that uses the given api key for the authentication . The new instance of TDClient shares the same HttpClient so closing this will invalidate the other copy of TDClient instances
40
40
40,013
private static TDClientHttpException clientError ( TDClientHttpException e , ResponseContext responseContext ) { boolean showWarning = true ; boolean showStackTrace = false ; int code = e . getStatusCode ( ) ; switch ( code ) { case HttpStatus . NOT_FOUND_404 : // Not found (e.g., database, table, table distribution da...
Show or suppress warning messages for TDClientHttpException
281
10
40,014
@ VisibleForTesting public TDSaveQueryRequest merge ( TDSavedQuery base ) { return new TDSaveQueryRequest ( name . or ( base . getName ( ) ) , cron . or ( base . getCron ( ) ) , type . or ( base . getType ( ) ) , query . or ( base . getQuery ( ) ) , timezone . or ( base . getTimezone ( ) ) , delay . or ( base . getDela...
Apply this update to the given TDSaveQuery objects and create a new TDSaveQueryRequest object .
183
22
40,015
public String getCmdOut ( ) { return debug . transform ( new Function < Debug , String > ( ) { @ Override public String apply ( Debug input ) { return input . getCmdout ( ) ; } } ) . or ( "" ) ; }
A short cut for reading cmdout message
53
8
40,016
public String getStdErr ( ) { return debug . transform ( new Function < Debug , String > ( ) { @ Override public String apply ( Debug input ) { return input . getStderr ( ) ; } } ) . or ( "" ) ; }
A short cut for reading stderr messsage
56
11
40,017
public TDClientConfig buildConfig ( ) { return new TDClientConfig ( endpoint , port , useSSL , apiKey , user , password , proxy , retryLimit , retryInitialIntervalMillis , retryMaxIntervalMillis , retryMultiplier , connectTimeoutMillis , readTimeoutMillis , connectionPoolSize , headers ) ; }
Build a config object .
75
5
40,018
public static String [ ] fastSplitKey ( String key ) { int i = key . indexOf ( ' ' ) ; if ( - 1 == i ) { return new String [ ] { key } ; } else { int j = key . indexOf ( ' ' , i + 1 ) ; if ( - 1 != j ) { return null ; } else { return new String [ ] { key . substring ( 0 , i ) , key . substring ( i + 1 ) } ; } } }
Java s string split is very expensive due to regexes . Implement our own simple version instead .
105
19
40,019
protected Kryo newKryoWithEx ( ) throws InstantiationException , IllegalAccessException { Kryo k = kryoClass . newInstance ( ) ; k . setInstantiatorStrategy ( instStratClass . newInstance ( ) ) ; k . setRegistrationRequired ( regRequired ) ; for ( IKryoRegistrar kr : registrations ) { kr . apply ( k ) ; } for ( IKryoRe...
This one adds expeption annotations that the interface does not have
119
13
40,020
public KryoInstantiator setClassLoader ( final ClassLoader cl ) { return new KryoInstantiator ( ) { public Kryo newKryo ( ) { Kryo k = KryoInstantiator . this . newKryo ( ) ; k . setClassLoader ( cl ) ; return k ; } } ; }
Use this to set a specific classloader
71
8
40,021
public KryoInstantiator setReferences ( final boolean ref ) { return new KryoInstantiator ( ) { public Kryo newKryo ( ) { Kryo k = KryoInstantiator . this . newKryo ( ) ; /** * Kryo 2.17, used in storm, has this method returning void, * 2.21 has it returning boolean. * Try not to call the method if you don't need to. *...
If true Kryo keeps a map of all the objects it has seen . this can use a ton of memory on hadoop but save serialization costs in some cases
123
33
40,022
@ Override public String get ( String key ) { Object value = conf . get ( key ) ; if ( null != value ) { return value . toString ( ) ; } else { return null ; } }
Return null if this key is undefined
44
7
40,023
public void writeOutputTo ( OutputStream os ) throws IOException { os . write ( output . getBuffer ( ) , 0 , output . position ( ) ) ; }
There for ByteArrayOutputStream cases this can be optimized
35
11
40,024
private static InputStream openResource ( final String file ) throws IOException { InputStream stream = HtmlConverterApplication . class . getResourceAsStream ( "/" + file ) ; if ( stream == null ) { throw new FileNotFoundException ( file ) ; } else { return stream ; } }
Opens a resource from classpath .
64
8
40,025
private static RuntimeDialect resolveDialect ( ) { if ( getJavaVersion ( ) >= MINIMUM_VERSION_MODERN_JAVA ) { return new ModernJavaRuntime ( ) ; } else if ( "Android Runtime" . equalsIgnoreCase ( System . getProperty ( "java.runtime.name" ) ) ) { return new AndroidRuntime ( ) ; } else { return new LegacyJavaRuntime ( )...
Resolves the runtime dialect for the current VM .
91
10
40,026
private static int getJavaVersion ( ) { String version = System . getProperty ( "java.version" ) ; if ( version == null ) { return - 1 ; } else { int index = version . indexOf ( ' ' ) ; if ( index > 0 ) { version = version . substring ( 0 , index ) ; } try { return Integer . parseInt ( version ) ; } catch ( NumberForma...
Gets the major version number of Java .
97
9
40,027
private static String stripAnonymousPart ( final String className ) { for ( int index = className . indexOf ( "$" , 0 ) ; index != - 1 ; index = className . indexOf ( ' ' , index + 2 ) ) { /* Trailing dollar sign */ if ( index >= className . length ( ) - 1 ) { return className . substring ( 0 , index ) ; } char firstLe...
Strips the the anonymous part from a class name .
151
12
40,028
private static StackTraceElement normalizeClassName ( final StackTraceElement element ) { String className = element . getClassName ( ) ; int dollarIndex = className . indexOf ( "$" ) ; if ( dollarIndex == - 1 ) { return element ; } else { className = stripAnonymousPart ( className ) ; return new StackTraceElement ( cl...
Strips the the anonymous part from a class name of stack trace element .
108
16
40,029
protected String renderTag ( final LogEntry logEntry ) { StringBuilder builder = reuseOrCreate ( tagBuilder , TAG_MAX_LENGTH ) ; tagToken . render ( logEntry , builder ) ; if ( builder . length ( ) > TAG_MAX_LENGTH ) { return builder . substring ( 0 , TAG_MAX_LENGTH - ELLIPSIS . length ( ) ) + ELLIPSIS ; } else { retur...
Renders the tag from a log entry .
101
9
40,030
protected String renderMessage ( final LogEntry logEntry ) { StringBuilder builder = reuseOrCreate ( messageBuilder , MESSAGE_BUILDER_CAPACITY ) ; messageToken . render ( logEntry , builder ) ; return builder . toString ( ) ; }
Renders the log message from a log entry .
57
10
40,031
private static boolean isCoveredByMinimumLevel ( final String tag , final Level level ) { return provider . getMinimumLevel ( tag ) . ordinal ( ) <= level . ordinal ( ) ; }
Checks if a given tag and severity level is covered by the logging provider s minimum level .
42
19
40,032
public static Locale getLocale ( ) { String tag = Configuration . get ( "locale" ) ; if ( tag == null ) { return Locale . ROOT ; } else { String [ ] splittedTag = tag . split ( "_" , MAX_LOCALE_ARGUMENTS ) ; if ( splittedTag . length == 1 ) { return new Locale ( splittedTag [ 0 ] ) ; } else if ( splittedTag . length ==...
Loads the locale from configuration .
155
7
40,033
public static Map < String , Level > getCustomLevels ( ) { Map < String , Level > levels = new HashMap < String , Level > ( ) ; for ( Entry < String , String > entry : Configuration . getSiblings ( "level@" ) . entrySet ( ) ) { String packageOrClass = entry . getKey ( ) . substring ( "level@" . length ( ) ) ; Level lev...
Loads custom severity levels for packages or classes from configuration .
126
12
40,034
public static List < String > getTags ( ) { List < String > tags = new ArrayList < String > ( ) ; for ( String writerProperty : Configuration . getSiblings ( "writer" ) . keySet ( ) ) { String tag = Configuration . get ( writerProperty + ".tag" ) ; if ( tag != null && ! tag . isEmpty ( ) && ! tag . equals ( "-" ) && ! ...
Loads all tags from writers in configuration .
109
9
40,035
private static void addWriter ( final Writer writer , final Collection < Writer > [ ] [ ] matrix , final int tagIndex , final Level level ) { for ( int levelIndex = level . ordinal ( ) ; levelIndex < Level . OFF . ordinal ( ) ; ++ levelIndex ) { Collection < Writer > collection = matrix [ tagIndex ] [ levelIndex ] ; if...
Adds a writer to a well - defined matrix . The given writer will be added only at the given tag index for severity levels equal or above the given severity level .
117
33
40,036
private static Level parse ( final String property , final Level defaultValue ) { if ( property == null ) { return defaultValue ; } else { try { return Level . valueOf ( property . toUpperCase ( Locale . ROOT ) ) ; } catch ( IllegalArgumentException ex ) { InternalLogger . log ( Level . ERROR , "Illegal severity level:...
Reads a severity level from configuration .
90
8
40,037
private static Level calculateMinimumLevel ( final Level globalLevel , final Map < String , Level > customLevels ) { Level minimumLevel = globalLevel ; for ( Level level : customLevels . values ( ) ) { if ( level . ordinal ( ) < minimumLevel . ordinal ( ) ) { minimumLevel = level ; } } return minimumLevel ; }
Calculates the minimum severity level that can output any log entries .
75
14
40,038
@ SuppressWarnings ( "unchecked" ) private static Collection < LogEntryValue > [ ] [ ] calculateRequiredLogEntryValues ( final Collection < Writer > [ ] [ ] writers ) { Collection < LogEntryValue > [ ] [ ] logEntryValues = new Collection [ writers . length ] [ Level . values ( ) . length - 1 ] ; for ( int tagIndex = 0 ...
Creates a matrix with all required log entry values for each tag and severity level .
197
17
40,039
private static BitSet calculateFullStackTraceRequirements ( final Collection < LogEntryValue > [ ] [ ] logEntryValues ) { BitSet result = new BitSet ( logEntryValues . length ) ; for ( int i = 0 ; i < logEntryValues . length ; ++ i ) { Collection < LogEntryValue > values = logEntryValues [ i ] [ Level . ERROR . ordinal...
Calculates for which tag a full stack trace element with method name file name and line number is required .
136
22
40,040
private static WritingThread createWritingThread ( final Collection < Writer > [ ] [ ] matrix ) { Collection < Writer > writers = getAllWriters ( matrix ) ; WritingThread thread = new WritingThread ( writers ) ; thread . start ( ) ; return thread ; }
Creates a writing thread for a matrix of writers .
55
11
40,041
private static Collection < Writer > getAllWriters ( final Collection < Writer > [ ] [ ] matrix ) { Collection < Writer > writers = Collections . newSetFromMap ( new IdentityHashMap < Writer , Boolean > ( ) ) ; for ( int i = 0 ; i < matrix . length ; ++ i ) { for ( int j = 0 ; j < matrix [ i ] . length ; ++ j ) { write...
Collects all writer instances from a matrix of writers .
106
11
40,042
private int getTagIndex ( final String tag ) { if ( tag == null ) { return 0 ; } else { int index = knownTags . indexOf ( tag ) ; return index == - 1 ? knownTags . size ( ) + 1 : index + 1 ; } }
Gets the index of a tag .
57
8
40,043
private void output ( final LogEntry logEntry , final Iterable < Writer > writers ) { if ( writingThread == null ) { for ( Writer writer : writers ) { try { writer . write ( logEntry ) ; } catch ( Exception ex ) { InternalLogger . log ( Level . ERROR , ex , "Failed to write log entry '" + logEntry . getMessage ( ) + "'...
Outputs a log entry to all passed writers .
113
10
40,044
public List < File > getAllFiles ( ) { List < File > files = new ArrayList < File > ( ) ; collectFiles ( folder , files ) ; Collections . sort ( files , LastModifiedFileComparator . INSTANCE ) ; return files ; }
Gets all files that are compatible with the dynamic path . The returned files are sorted by the last modification date . The most recently modified files are at the top the oldest at the bottom of the list .
55
41
40,045
private void collectFiles ( final File folder , final List < File > found ) { File [ ] files = folder . listFiles ( ) ; if ( files != null ) { for ( File file : files ) { if ( file . isDirectory ( ) ) { collectFiles ( file , found ) ; } else if ( file . isFile ( ) && file . getPath ( ) . endsWith ( suffix ) ) { int ind...
Collects files from a folder and all nested sub folders .
161
12
40,046
private boolean isValid ( final String path , final int pathPosition , final int segmentIndex ) { Segment segment = segments . get ( segmentIndex ) ; String expectedValue = segment . getStaticText ( ) ; if ( expectedValue == null ) { if ( segmentIndex == segments . size ( ) - 1 ) { return segment . validateToken ( path...
Checks if a partial path to a file is compatible with this dynamic path .
266
16
40,047
private static Segment parseSegment ( final String path , final String token ) { int separator = token . indexOf ( ' ' ) ; String name ; String parameter ; if ( separator == - 1 ) { name = token . trim ( ) ; parameter = null ; } else { name = token . substring ( 0 , separator ) . trim ( ) ; parameter = token . substrin...
Parses a token from a pattern as a segment .
217
12
40,048
@ Override public void run ( ) { Collection < Writer > writers = new ArrayList < Writer > ( 1 ) ; while ( true ) { for ( Task task : receiveTasks ( ) ) { if ( task == Task . POISON ) { close ( ) ; return ; } else { write ( writers , task ) ; } } flush ( writers ) ; writers . clear ( ) ; try { sleep ( MILLISECONDS_TO_SL...
Fetches log entries and writes them until receiving a poison task .
114
14
40,049
void add ( final Writer writer , final LogEntry logEntry ) { Task task = new Task ( writer , logEntry ) ; synchronized ( mutex ) { tasks . add ( task ) ; } }
Adds a log entry for writing .
41
7
40,050
private List < Task > receiveTasks ( ) { synchronized ( mutex ) { if ( tasks . isEmpty ( ) ) { return Collections . emptyList ( ) ; } else { List < Task > currentTasks = tasks ; tasks = new ArrayList < Task > ( ) ; return currentTasks ; } } }
Receives all added log entries .
67
8
40,051
private void write ( final Collection < Writer > writers , final Task task ) { try { Writer writer = task . writer ; writer . write ( task . logEntry ) ; if ( ! writers . contains ( writer ) ) { writers . add ( writer ) ; } } catch ( Exception ex ) { InternalLogger . log ( Level . ERROR , ex , "Failed to write log entr...
Writes a log entry .
99
6
40,052
private void flush ( final Collection < Writer > writers ) { for ( Writer writer : writers ) { try { writer . flush ( ) ; } catch ( Exception ex ) { InternalLogger . log ( Level . ERROR , ex , "Failed to flush writer" ) ; } } }
Flushes a collection of writers .
59
7
40,053
private void close ( ) { for ( Writer writer : writers ) { try { writer . close ( ) ; } catch ( Exception ex ) { InternalLogger . log ( Level . ERROR , ex , "Failed to close writer" ) ; } } }
Closes all writers .
53
5
40,054
public void output ( final Map < String , Map < String , List < BigDecimal > > > benchmarks ) { for ( Entry < String , Map < String , List < BigDecimal > > > benchmark : benchmarks . entrySet ( ) ) { BigDecimal max = benchmark . getValue ( ) . values ( ) . stream ( ) . flatMap ( list -> list . stream ( ) ) . max ( Comp...
Creates and outputs HTML diagrams .
671
7
40,055
@ SuppressWarnings ( "rawtypes" ) public static Enumeration getCurrentLoggers ( ) { ArrayList < Logger > copy ; synchronized ( mutex ) { copy = new ArrayList < Logger > ( loggers . values ( ) ) ; } copy . remove ( root ) ; return Collections . enumeration ( copy ) ; }
Retrieves all existing loggers .
74
8
40,056
private static Logger getOrCreateLogger ( final String name ) { if ( name == null || name . length ( ) == 0 ) { return root ; } else { Logger logger = loggers . get ( name ) ; if ( logger == null ) { Logger parent = getOrCreateLogger ( reduce ( name ) ) ; logger = new Logger ( parent , name ) ; loggers . put ( name , l...
Retrieves a logger by name .
98
8
40,057
private static String reduce ( final String name ) { int index = name . lastIndexOf ( ' ' ) ; return index == - 1 ? null : name . substring ( 0 , index ) ; }
Gets the parent s logger name for a given logger name .
42
13
40,058
public boolean isTraceEnabled ( ) { return MINIMUM_LEVEL_COVERS_TRACE && provider . isEnabled ( STACKTRACE_DEPTH , null , org . tinylog . Level . TRACE ) ; }
Check whether this category is enabled for the TRACE Level .
50
12
40,059
public T create ( final String name , final Object ... arguments ) { if ( name . indexOf ( ' ' ) == - 1 ) { String expectingClassName = toSimpleClassName ( name ) ; for ( String className : classes ) { int split = className . lastIndexOf ( ' ' ) ; String simpleClassName = split == - 1 ? className : className . substrin...
Creates a defined service implementation . The name can be either the fully - qualified class name or the simplified acronym . The acronym is the class name without package and service suffix .
156
35
40,060
public Collection < T > createAll ( final Object ... arguments ) { Collection < T > instances = new ArrayList < T > ( classes . size ( ) ) ; for ( String className : classes ) { T instance = createInstance ( className , arguments ) ; if ( instance != null ) { instances . add ( instance ) ; } } return instances ; }
Creates all registered service implementations .
75
7
40,061
private static < T > Collection < String > loadClasses ( final ClassLoader classLoader , final Class < ? extends T > service ) { String name = SERVICE_PREFIX + service . getName ( ) ; Enumeration < URL > urls ; try { urls = classLoader . getResources ( name ) ; } catch ( IOException ex ) { InternalLogger . log ( Level ...
Loads all registered service class names .
327
8
40,062
private String toSimpleClassName ( final String name ) { StringBuilder builder = new StringBuilder ( name . length ( ) ) ; for ( String token : SPLIT_PATTERN . split ( name ) ) { if ( ! token . isEmpty ( ) ) { builder . append ( Character . toUpperCase ( token . charAt ( 0 ) ) ) ; builder . append ( token . substring (...
Generates the simple class name from an acronym . A simple class name is the class name without package .
125
21
40,063
@ SuppressWarnings ( "unchecked" ) private T createInstance ( final String className , final Object ... arguments ) { try { Class < ? > implementation = Class . forName ( className , false , classLoader ) ; if ( service . isAssignableFrom ( implementation ) ) { return ( T ) implementation . getDeclaredConstructor ( arg...
Creates a new instance of a class .
359
9
40,064
private static String getVersion ( final Class < ? > clazz ) { CodeSource source = clazz . getProtectionDomain ( ) . getCodeSource ( ) ; URL location = source . getLocation ( ) ; try { Path path = Paths . get ( location . toURI ( ) ) ; return Files . isRegularFile ( path ) ? getVersionFromJar ( path ) : getVersionFromP...
Gets the version for a class .
126
8
40,065
private static String getVersionFromJar ( final Path path ) { Matcher matcher = JAR_VERSION . matcher ( path . toString ( ) ) ; if ( matcher . matches ( ) ) { return matcher . group ( 1 ) ; } else { Logger . error ( "JAR file \"{}\" does not contain a version" , path ) ; return null ; } }
Gets the version for a JAR file .
84
10
40,066
private static String getVersionFromPom ( final Path path ) { Path folder = path ; Path file ; while ( true ) { file = folder . resolve ( "pom.xml" ) ; if ( Files . exists ( file ) ) { break ; } folder = folder . getParent ( ) ; if ( folder == null ) { Logger . error ( "pom.xml is missing for \"{}\"" , path ) ; return ...
Gets the version for a folder by searching for a pom . xml in the folder and its folders .
223
22
40,067
private static StackTraceElement findStackTraceElement ( final String loggerClassName , final StackTraceElement [ ] trace ) { int index = 0 ; while ( index < trace . length && ! loggerClassName . equals ( trace [ index ] . getClassName ( ) ) ) { index = index + 1 ; } while ( index < trace . length && loggerClassName . ...
Gets the stack trace element that appears before the passed logger class name .
125
15
40,068
private StackTraceElement [ ] extractCallerStackTraceElements ( final int count ) { if ( stackTraceElementsFiller != null ) { try { StackTraceElement [ ] trace = new StackTraceElement [ count + 1 ] ; stackTraceElementsFiller . invoke ( null , Thread . currentThread ( ) , trace ) ; return trace ; } catch ( IllegalAccess...
Extracts a defined number of elements from stack trace .
173
12
40,069
public static TaggedLogger tag ( final String tag ) { if ( tag == null || tag . isEmpty ( ) ) { return instance ; } else { TaggedLogger logger = loggers . get ( tag ) ; if ( logger == null ) { logger = new TaggedLogger ( tag ) ; TaggedLogger existing = loggers . putIfAbsent ( tag , logger ) ; return existing == null ? ...
Gets a tagged logger instance . Tags are case - sensitive .
102
13
40,070
private static ProcessHandle getCurrentProcess ( ) { try { return ( ProcessHandle ) ProcessHandle . class . getDeclaredMethod ( "current" ) . invoke ( null ) ; } catch ( ReflectiveOperationException ex ) { InternalLogger . log ( Level . ERROR , ex , "Failed to receive the handle of the current process" ) ; return null ...
Gets the process handle of the current process .
78
10
40,071
private static void render ( final Throwable throwable , final StringBuilder builder ) { builder . append ( throwable . getClass ( ) . getName ( ) ) ; String message = throwable . getMessage ( ) ; if ( message != null ) { builder . append ( ": " ) ; builder . append ( message ) ; } StackTraceElement [ ] stackTrace = th...
Renders a throwable including stack trace and cause throwables .
190
13
40,072
public static void main ( final String [ ] args ) { BenchmarkOutputParser parser = new BenchmarkOutputParser ( FRAMEWORKS . keySet ( ) ) ; HtmlDiagramRenderer renderer = new HtmlDiagramRenderer ( FRAMEWORKS ) ; renderer . output ( parser . parse ( OUTPUT_FILE ) ) ; }
Main method for executing the converter .
79
7
40,073
protected static String getFileName ( final Map < String , String > properties ) { String fileName = properties . get ( "file" ) ; if ( fileName == null ) { throw new IllegalArgumentException ( "File name is missing for file writer" ) ; } else { return fileName ; } }
Extracts the log file name from configuration .
65
10
40,074
protected static Charset getCharset ( final Map < String , String > properties ) { String charsetName = properties . get ( "charset" ) ; try { return charsetName == null ? Charset . defaultCharset ( ) : Charset . forName ( charsetName ) ; } catch ( IllegalArgumentException ex ) { InternalLogger . log ( Level . ERROR , ...
Extracts the charset from configuration . The default charset will be returned if no charset is defined or the defined charset doesn t exist .
114
31
40,075
protected final String render ( final LogEntry logEntry ) { if ( builder == null ) { StringBuilder builder = new StringBuilder ( BUILDER_CAPACITY ) ; token . render ( logEntry , builder ) ; return builder . toString ( ) ; } else { builder . setLength ( 0 ) ; token . render ( logEntry , builder ) ; return builder . toSt...
Renders a log entry as string .
85
8
40,076
private void internalWrite ( final byte [ ] data ) throws IOException { if ( ! canBeContinued ( data , policies ) ) { writer . close ( ) ; String fileName = path . resolve ( ) ; deleteBackups ( path . getAllFiles ( ) , backups ) ; writer = createByteArrayWriter ( fileName , false , buffered , false , false ) ; for ( Po...
Outputs a passed byte array unsynchronized .
108
11
40,077
private static List < Policy > createPolicies ( final String property ) { if ( property == null || property . isEmpty ( ) ) { return Collections . < Policy > singletonList ( new StartupPolicy ( null ) ) ; } else { ServiceLoader < Policy > loader = new ServiceLoader < Policy > ( Policy . class , String . class ) ; List ...
Creates policies from a nullable string .
202
9
40,078
private static boolean canBeContinued ( final String fileName , final List < Policy > policies ) { boolean result = true ; for ( Policy policy : policies ) { result &= policy . continueExistingFile ( fileName ) ; } return result ; }
Checks if an already existing log file can be continued .
53
12
40,079
private static boolean canBeContinued ( final byte [ ] data , final List < Policy > policies ) { boolean result = true ; for ( Policy policy : policies ) { result &= policy . continueCurrentFile ( data ) ; } return result ; }
Checks if a new log entry can be still written to the current log file .
52
17
40,080
private static void deleteBackups ( final List < File > files , final int count ) { if ( count >= 0 ) { for ( int i = files . size ( ) - Math . max ( 0 , files . size ( ) - count ) ; i < files . size ( ) ; ++ i ) { if ( ! files . get ( i ) . delete ( ) ) { InternalLogger . log ( Level . WARN , "Failed to delete log fil...
Deletes old log files .
121
6
40,081
private static long parse ( final String argument ) throws NumberFormatException { if ( argument . endsWith ( "gb" ) ) { return Long . parseLong ( argument . substring ( 0 , argument . length ( ) - "gb" . length ( ) ) . trim ( ) ) * GB ; } else if ( argument . endsWith ( "mb" ) ) { return Long . parseLong ( argument . ...
Parses file size from a string . The units GB MB KB and bytes are supported .
228
19
40,082
public static void push ( final String message ) { InternalLogger . log ( org . tinylog . Level . WARN , "tinylog does not support NDC, \"" + message + "\" will be discarded" ) ; }
Push new diagnostic context information for the current thread .
50
10
40,083
private String format ( final String pattern , final Object argument ) { try { return getFormatter ( pattern , argument ) . format ( argument ) ; } catch ( IllegalArgumentException ex ) { InternalLogger . log ( Level . WARN , "Illegal argument '" + String . valueOf ( argument ) + "' for pattern '" + pattern + "'" ) ; r...
Formats a pattern of a placeholder .
88
8
40,084
private static String getSimpleClassName ( final String fullyQualifiedClassName ) { int dotIndex = fullyQualifiedClassName . lastIndexOf ( ' ' ) ; if ( dotIndex < 0 ) { return fullyQualifiedClassName ; } else { return fullyQualifiedClassName . substring ( dotIndex + 1 ) ; } }
Gets the simple class name from a fully qualified class name .
71
13
40,085
private static org . tinylog . Level translateLevel ( final Level level ) { switch ( level ) { case TRACE : return org . tinylog . Level . TRACE ; case DEBUG : return org . tinylog . Level . DEBUG ; case INFO : return org . tinylog . Level . INFO ; case WARN : return org . tinylog . Level . WARN ; case ERROR : case FAT...
Translate JBoss Logging severity levels .
127
9
40,086
public static Map < String , String > getSiblings ( final String prefix ) { Map < String , String > map = new HashMap < String , String > ( ) ; for ( Enumeration < Object > enumeration = properties . keys ( ) ; enumeration . hasMoreElements ( ) ; ) { String key = ( String ) enumeration . nextElement ( ) ; if ( key . st...
Gets all siblings with a defined prefix . Child properties will be not returned .
142
16
40,087
public static Map < String , String > getChildren ( final String key ) { String prefix = key + "." ; Map < String , String > map = new HashMap < String , String > ( ) ; for ( Enumeration < Object > enumeration = properties . keys ( ) ; enumeration . hasMoreElements ( ) ; ) { String property = ( String ) enumeration . n...
Gets all child properties for a parent property . The parent property itself will be not returned . Children keys will be returned without parent key prefix .
130
29
40,088
public static void replace ( final Map < String , String > configuration ) { synchronized ( properties ) { properties . clear ( ) ; properties . putAll ( configuration ) ; } }
Replaces the current configuration by a new one . Already existing properties will be dropped .
36
17
40,089
private static Properties load ( ) { Properties properties = new Properties ( ) ; String file = System . getProperty ( CONFIGURATION_PROPERTY ) ; try { if ( file != null ) { InputStream stream ; if ( URL_DETECTION_PATTERN . matcher ( file ) . matches ( ) ) { stream = new URL ( file ) . openStream ( ) ; } else { stream ...
Loads all configuration properties .
404
6
40,090
private static void load ( final Properties properties , final InputStream stream ) throws IOException { try { properties . load ( stream ) ; } finally { stream . close ( ) ; } }
Puts all properties from a stream to an existing properties object . Already existing properties will be overridden .
38
21
40,091
private static String resolve ( final String value , final Resolver resolver ) { StringBuilder builder = new StringBuilder ( ) ; int position = 0 ; String prefix = resolver . getPrefix ( ) + "{" ; String postfix = "}" ; for ( int index = value . indexOf ( prefix ) ; index != - 1 ; index = value . indexOf ( prefix , pos...
Resolves placeholders with passed resolver .
301
9
40,092
void activate ( ) { LogManager . getLogManager ( ) . reset ( ) ; Logger logger = Logger . getLogger ( "" ) ; logger . setLevel ( translateLevel ( provider . getMinimumLevel ( null ) ) ) ; logger . addHandler ( this ) ; }
Activates this handler .
60
5
40,093
public static void log ( final Level level , final String message ) { System . err . println ( "LOGGER " + level + ": " + message ) ; }
Logs a plain text message .
35
7
40,094
public static void log ( final Level level , final Throwable exception ) { String nameOfException = exception . getClass ( ) . getName ( ) ; String messageOfException = exception . getMessage ( ) ; if ( messageOfException == null || messageOfException . isEmpty ( ) ) { System . err . println ( "LOGGER " + level + ": " ...
Logs a caught exception .
121
6
40,095
public static void log ( final Level level , final Throwable exception , final String message ) { String nameOfException = exception . getClass ( ) . getName ( ) ; String messageOfException = exception . getMessage ( ) ; StringBuilder builder = new StringBuilder ( BUFFER_SIZE ) ; builder . append ( level ) ; builder . ...
Logs a caught exception with a custom text message .
158
11
40,096
private void doWrite ( final LogEntry logEntry ) throws SQLException { if ( checkConnection ( ) ) { if ( batch ) { batchCount += 1 ; } try { for ( int i = 0 ; i < tokens . size ( ) ; ++ i ) { tokens . get ( i ) . apply ( logEntry , statement , i + 1 ) ; } } catch ( SQLException ex ) { resetConnection ( ) ; throw ex ; }...
Unsynchronized method for inserting a log entry .
178
11
40,097
private void doFlush ( ) throws SQLException { if ( batchCount > 0 ) { try { statement . executeBatch ( ) ; batchCount = 0 ; } catch ( SQLException ex ) { resetConnection ( ) ; throw ex ; } } }
Unsynchronized method for flushing all cached batch insert statements .
57
14
40,098
private void doClose ( ) throws SQLException { try { if ( batch ) { doFlush ( ) ; } } finally { if ( lostCount > 0 ) { InternalLogger . log ( Level . ERROR , "Lost log entries due to broken database connection: " + lostCount ) ; } if ( connection != null ) { connection . close ( ) ; } } }
Unsynchronized method for closing database connection .
80
10
40,099
private boolean checkConnection ( ) { if ( connection == null ) { if ( System . currentTimeMillis ( ) >= reconnectTimestamp ) { long start = System . currentTimeMillis ( ) ; try { connection = connect ( url , user , password ) ; statement = connection . prepareStatement ( sql ) ; InternalLogger . log ( Level . ERROR , ...
Checks if database connection is opened . Regular attempts are made to reestablish a broken database connection .
232
20