You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2016/06/03 18:10:55 UTC
[07/10] logging-log4j2 git commit: Add final modifier to method
parameters.
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultScriptFileComponentBuilder.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultScriptFileComponentBuilder.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultScriptFileComponentBuilder.java
index 85fbbe4..c9d50ef 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultScriptFileComponentBuilder.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultScriptFileComponentBuilder.java
@@ -34,25 +34,25 @@ class DefaultScriptFileComponentBuilder extends DefaultComponentAndConfiguration
}
@Override
- public DefaultScriptFileComponentBuilder addLanguage(String language) {
+ public DefaultScriptFileComponentBuilder addLanguage(final String language) {
addAttribute("language", language);
return this;
}
@Override
- public DefaultScriptFileComponentBuilder addIsWatched(boolean isWatched) {
+ public DefaultScriptFileComponentBuilder addIsWatched(final boolean isWatched) {
addAttribute("isWatched", Boolean.toString(isWatched));
return this;
}
@Override
- public DefaultScriptFileComponentBuilder addIsWatched(String isWatched) {
+ public DefaultScriptFileComponentBuilder addIsWatched(final String isWatched) {
addAttribute("isWatched", isWatched);
return this;
}
@Override
- public DefaultScriptFileComponentBuilder addCharset(String charset) {
+ public DefaultScriptFileComponentBuilder addCharset(final String charset) {
addAttribute("charset", charset);
return this;
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/config/composite/CompositeConfiguration.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/composite/CompositeConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/composite/CompositeConfiguration.java
index 60d98f0..b29e60b 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/composite/CompositeConfiguration.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/composite/CompositeConfiguration.java
@@ -61,7 +61,7 @@ public class CompositeConfiguration extends AbstractConfiguration implements Rec
*
* @param configurations The List of Configurations to merge.
*/
- public CompositeConfiguration(List<? extends AbstractConfiguration> configurations) {
+ public CompositeConfiguration(final List<? extends AbstractConfiguration> configurations) {
super(ConfigurationSource.NULL_SOURCE);
rootNode = configurations.get(0).getRootNode();
this.configurations = configurations;
@@ -167,13 +167,13 @@ public class CompositeConfiguration extends AbstractConfiguration implements Rec
return new CompositeConfiguration(configs);
}
- private void staffChildConfiguration(AbstractConfiguration childConfiguration) {
+ private void staffChildConfiguration(final AbstractConfiguration childConfiguration) {
childConfiguration.setPluginManager(pluginManager);
childConfiguration.setScriptManager(scriptManager);
childConfiguration.setup();
}
- private void printNodes(String indent, Node node, StringBuilder sb) {
+ private void printNodes(final String indent, final Node node, final StringBuilder sb) {
sb.append(indent).append(node.getName()).append(" type: ").append(node.getType()).append("\n");
sb.append(indent).append(node.getAttributes().toString()).append("\n");
for (Node child : node.getChildren()) {
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/config/composite/DefaultMergeStrategy.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/composite/DefaultMergeStrategy.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/composite/DefaultMergeStrategy.java
index ce38e82..e188efa 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/composite/DefaultMergeStrategy.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/composite/DefaultMergeStrategy.java
@@ -68,7 +68,7 @@ public class DefaultMergeStrategy implements MergeStrategy {
* @param configuration The configuration to merge.
*/
@Override
- public void mergeRootProperties(Node rootNode, AbstractConfiguration configuration) {
+ public void mergeRootProperties(final Node rootNode, final AbstractConfiguration configuration) {
for (Map.Entry<String, String> attribute : configuration.getRootNode().getAttributes().entrySet()) {
boolean isFound = false;
for (Map.Entry<String, String> targetAttribute : rootNode.getAttributes().entrySet()) {
@@ -112,7 +112,7 @@ public class DefaultMergeStrategy implements MergeStrategy {
* @param pluginManager The PluginManager.
*/
@Override
- public void mergConfigurations(Node target, Node source, PluginManager pluginManager) {
+ public void mergConfigurations(final Node target, final Node source, final PluginManager pluginManager) {
for (Node sourceChildNode : source.getChildren()) {
boolean isFilter = isFilterNode(sourceChildNode);
boolean isMerged = false;
@@ -222,7 +222,7 @@ public class DefaultMergeStrategy implements MergeStrategy {
}
}
- private Node getLoggerNode(Node parentNode, String name) {
+ private Node getLoggerNode(final Node parentNode, final String name) {
for (Node node : parentNode.getChildren()) {
String nodeName = node.getAttributes().get(NAME);
if (name == null && nodeName == null) {
@@ -235,8 +235,8 @@ public class DefaultMergeStrategy implements MergeStrategy {
return null;
}
- private void updateFilterNode(Node target, Node targetChildNode, Node sourceChildNode,
- PluginManager pluginManager) {
+ private void updateFilterNode(final Node target, final Node targetChildNode, final Node sourceChildNode,
+ final PluginManager pluginManager) {
if (CompositeFilter.class.isAssignableFrom(targetChildNode.getType().getPluginClass())) {
Node node = new Node(targetChildNode, sourceChildNode.getName(), sourceChildNode.getType());
node.getChildren().addAll(sourceChildNode.getChildren());
@@ -256,15 +256,15 @@ public class DefaultMergeStrategy implements MergeStrategy {
}
}
- private boolean isFilterNode(Node node) {
+ private boolean isFilterNode(final Node node) {
return Filter.class.isAssignableFrom(node.getType().getPluginClass());
}
- private boolean isSameName(Node node1, Node node2) {
+ private boolean isSameName(final Node node1, final Node node2) {
return node1.getAttributes().get(NAME).toLowerCase().equals(node2.getAttributes().get(NAME).toLowerCase());
}
- private boolean isSameReference(Node node1, Node node2) {
+ private boolean isSameReference(final Node node1, final Node node2) {
return node1.getAttributes().get(REF).toLowerCase().equals(node2.getAttributes().get(REF).toLowerCase());
}
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfiguration.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfiguration.java
index 90abf56..a5eaae9 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfiguration.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfiguration.java
@@ -30,7 +30,7 @@ import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;
*/
public class PropertiesConfiguration extends BuiltConfiguration implements Reconfigurable {
- public PropertiesConfiguration(ConfigurationSource source, Component root) {
+ public PropertiesConfiguration(final ConfigurationSource source, final Component root) {
super(source, root);
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java
index 2c70234..66f9bba 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java
@@ -71,7 +71,7 @@ public class PropertiesConfigurationBuilder extends ConfigurationBuilderFactory
return this;
}
- public PropertiesConfigurationBuilder setConfigurationSource(ConfigurationSource source) {
+ public PropertiesConfigurationBuilder setConfigurationSource(final ConfigurationSource source) {
builder.setConfigurationSource(source);
return this;
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java
index ca2c0a0..ea1c12b 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java
@@ -187,7 +187,7 @@ public class XmlConfiguration extends AbstractConfiguration implements Reconfigu
* @return a new DocumentBuilder
* @throws ParserConfigurationException
*/
- static DocumentBuilder newDocumentBuilder(boolean xIncludeAware) throws ParserConfigurationException {
+ static DocumentBuilder newDocumentBuilder(final boolean xIncludeAware) throws ParserConfigurationException {
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
if (xIncludeAware) {
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/DynamicThresholdFilter.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/DynamicThresholdFilter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/DynamicThresholdFilter.java
index 65d8ffa..e68c3d1 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/DynamicThresholdFilter.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/DynamicThresholdFilter.java
@@ -113,7 +113,7 @@ public final class DynamicThresholdFilter extends AbstractFilter {
return true;
}
- private Result filter(final Level level, Map<String, String> contextMap) {
+ private Result filter(final Level level, final Map<String, String> contextMap) {
final Object value = contextMap.get(key);
if (value != null) {
Level ctxLevel = levelMap.get(value);
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
index 69a8a22..d7588a6 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
@@ -95,7 +95,7 @@ public class Log4jLogEvent implements LogEvent {
public Builder() {
}
- public Builder(LogEvent other) {
+ public Builder(final LogEvent other) {
Objects.requireNonNull(other);
if (other instanceof RingBufferLogEvent) {
((RingBufferLogEvent) other).initializeBuilder(this);
@@ -165,52 +165,52 @@ public class Log4jLogEvent implements LogEvent {
return this;
}
- public Builder setTimeMillis(long timeMillis) {
+ public Builder setTimeMillis(final long timeMillis) {
this.timeMillis = timeMillis;
return this;
}
- public Builder setThrownProxy(ThrowableProxy thrownProxy) {
+ public Builder setThrownProxy(final ThrowableProxy thrownProxy) {
this.thrownProxy = thrownProxy;
return this;
}
- public Builder setContextMap(Map<String, String> contextMap) {
+ public Builder setContextMap(final Map<String, String> contextMap) {
this.contextMap = contextMap;
return this;
}
- public Builder setContextStack(ThreadContext.ContextStack contextStack) {
+ public Builder setContextStack(final ThreadContext.ContextStack contextStack) {
this.contextStack = contextStack;
return this;
}
- public Builder setThreadId(long threadId) {
+ public Builder setThreadId(final long threadId) {
this.threadId = threadId;
return this;
}
- public Builder setThreadName(String threadName) {
+ public Builder setThreadName(final String threadName) {
this.threadName = threadName;
return this;
}
- public Builder setThreadPriority(int threadPriority) {
+ public Builder setThreadPriority(final int threadPriority) {
this.threadPriority = threadPriority;
return this;
}
- public Builder setSource(StackTraceElement source) {
+ public Builder setSource(final StackTraceElement source) {
this.source = source;
return this;
}
- public Builder setIncludeLocation(boolean includeLocation) {
+ public Builder setIncludeLocation(final boolean includeLocation) {
this.includeLocation = includeLocation;
return this;
}
- public Builder setEndOfBatch(boolean endOfBatch) {
+ public Builder setEndOfBatch(final boolean endOfBatch) {
this.endOfBatch = endOfBatch;
return this;
}
@@ -221,7 +221,7 @@ public class Log4jLogEvent implements LogEvent {
* was created.
* @return this builder
*/
- public Builder setNanoTime(long nanoTime) {
+ public Builder setNanoTime(final long nanoTime) {
this.nanoTime = nanoTime;
return this;
}
@@ -374,8 +374,8 @@ public Log4jLogEvent(final String loggerName, final Marker marker, final String
*/
private Log4jLogEvent(final String loggerName, final Marker marker, final String loggerFQCN, final Level level,
final Message message, final Throwable thrown, final ThrowableProxy thrownProxy,
- final Map<String, String> contextMap, final ThreadContext.ContextStack contextStack, long threadId,
- final String threadName, int threadPriority, final StackTraceElement source, final long timestampMillis,
+ final Map<String, String> contextMap, final ThreadContext.ContextStack contextStack, final long threadId,
+ final String threadName, final int threadPriority, final StackTraceElement source, final long timestampMillis,
final long nanoTime) {
this.loggerName = loggerName;
this.marker = marker;
@@ -430,7 +430,7 @@ public Log4jLogEvent(final String loggerName, final Marker marker, final String
*
* @param nanoClock the {@code NanoClock} to use for creating the nanoTime timestamp of log events
*/
- public static void setNanoClock(NanoClock nanoClock) {
+ public static void setNanoClock(final NanoClock nanoClock) {
Log4jLogEvent.nanoClock = Objects.requireNonNull(nanoClock, "NanoClock must be non-null");
StatusLogger.getLogger().trace("Using {} for nanosecond timestamps.", nanoClock.getClass().getSimpleName());
}
@@ -696,7 +696,7 @@ public Log4jLogEvent(final String loggerName, final Marker marker, final String
*
* @return a new immutable copy of the data in this {@code Log4jLogEvent}
*/
- public static Log4jLogEvent createMemento(LogEvent event, final boolean includeLocation) {
+ public static Log4jLogEvent createMemento(final LogEvent event, final boolean includeLocation) {
// TODO implement Log4jLogEvent.createMemento()
return deserialize(serialize(event, includeLocation));
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
index 6e806af..b89dc04 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
@@ -147,7 +147,7 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
return loggerFqcn;
}
- public void setLoggerFqcn(String loggerFqcn) {
+ public void setLoggerFqcn(final String loggerFqcn) {
this.loggerFqcn = loggerFqcn;
}
@@ -156,7 +156,7 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
return marker;
}
- public void setMarker(Marker marker) {
+ public void setMarker(final Marker marker) {
this.marker = marker;
}
@@ -168,7 +168,7 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
return level;
}
- public void setLevel(Level level) {
+ public void setLevel(final Level level) {
this.level = level;
}
@@ -177,7 +177,7 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
return loggerName;
}
- public void setLoggerName(String loggerName) {
+ public void setLoggerName(final String loggerName) {
this.loggerName = loggerName;
}
@@ -291,7 +291,7 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
return thrown;
}
- public void setThrown(Throwable thrown) {
+ public void setThrown(final Throwable thrown) {
this.thrown = thrown;
}
@@ -300,7 +300,7 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
return timeMillis;
}
- public void setTimeMillis(long timeMillis) {
+ public void setTimeMillis(final long timeMillis) {
this.timeMillis = timeMillis;
}
@@ -338,7 +338,7 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
return contextMap;
}
- public void setContextMap(Map<String, String> contextMap) {
+ public void setContextMap(final Map<String, String> contextMap) {
this.contextMap = contextMap;
}
@@ -347,7 +347,7 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
return contextStack;
}
- public void setContextStack(ThreadContext.ContextStack contextStack) {
+ public void setContextStack(final ThreadContext.ContextStack contextStack) {
this.contextStack = contextStack;
}
@@ -356,7 +356,7 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
return threadId;
}
- public void setThreadId(long threadId) {
+ public void setThreadId(final long threadId) {
this.threadId = threadId;
}
@@ -365,7 +365,7 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
return threadName;
}
- public void setThreadName(String threadName) {
+ public void setThreadName(final String threadName) {
this.threadName = threadName;
}
@@ -374,7 +374,7 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
return threadPriority;
}
- public void setThreadPriority(int threadPriority) {
+ public void setThreadPriority(final int threadPriority) {
this.threadPriority = threadPriority;
}
@@ -384,7 +384,7 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
}
@Override
- public void setIncludeLocation(boolean includeLocation) {
+ public void setIncludeLocation(final boolean includeLocation) {
this.includeLocation = includeLocation;
}
@@ -394,7 +394,7 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
}
@Override
- public void setEndOfBatch(boolean endOfBatch) {
+ public void setEndOfBatch(final boolean endOfBatch) {
this.endOfBatch = endOfBatch;
}
@@ -403,7 +403,7 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
return nanoTime;
}
- public void setNanoTime(long nanoTime) {
+ public void setNanoTime(final long nanoTime) {
this.nanoTime = nanoTime;
}
@@ -433,7 +433,7 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
* Initializes the specified {@code Log4jLogEvent.Builder} from this {@code MutableLogEvent}.
* @param builder the builder whose fields to populate
*/
- public void initializeBuilder(Log4jLogEvent.Builder builder) {
+ public void initializeBuilder(final Log4jLogEvent.Builder builder) {
builder.setContextMap(contextMap) //
.setContextStack(contextStack) //
.setEndOfBatch(endOfBatch) //
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java
index 6694943..4d4e761 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java
@@ -207,7 +207,7 @@ public abstract class AbstractStringLayout extends AbstractLayout<String> implem
return headerSerializer;
}
- protected byte[] serializeToBytes(final Serializer serializer, byte[] defaultValue) {
+ protected byte[] serializeToBytes(final Serializer serializer, final byte[] defaultValue) {
final String serializable = serializeToString(serializer);
if (serializer == null) {
return defaultValue;
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java
index 7db739e..b679fcd 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java
@@ -107,7 +107,7 @@ public final class GelfLayout extends AbstractStringLayout {
private final boolean includeStacktrace;
public GelfLayout(final String host, final KeyValuePair[] additionalFields, final CompressionType compressionType,
- final int compressionThreshold, boolean includeStacktrace) {
+ final int compressionThreshold, final boolean includeStacktrace) {
super(StandardCharsets.UTF_8);
this.host = host;
this.additionalFields = additionalFields;
@@ -182,7 +182,7 @@ public final class GelfLayout extends AbstractStringLayout {
return text.toString();
}
- private StringBuilder toText(LogEvent event, StringBuilder builder, boolean gcFree) {
+ private StringBuilder toText(final LogEvent event, final StringBuilder builder, final boolean gcFree) {
builder.append('{');
builder.append("\"version\":\"1.1\",");
builder.append("\"host\":\"");
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JacksonFactory.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JacksonFactory.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JacksonFactory.java
index 5869435..e230119 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JacksonFactory.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JacksonFactory.java
@@ -163,12 +163,12 @@ abstract class JacksonFactory {
private static final long serialVersionUID = 1L;
- Log4jXmlPrettyPrinter(int nesting) {
+ Log4jXmlPrettyPrinter(final int nesting) {
_nesting = nesting;
}
@Override
- public void writePrologLinefeed(XMLStreamWriter2 sw) throws XMLStreamException {
+ public void writePrologLinefeed(final XMLStreamWriter2 sw) throws XMLStreamException {
// nothing
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/MarkerPatternSelector.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/MarkerPatternSelector.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/MarkerPatternSelector.java
index 383f0ed..1a98313 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/MarkerPatternSelector.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/MarkerPatternSelector.java
@@ -74,7 +74,7 @@ public class MarkerPatternSelector implements PatternSelector {
}
@Override
- public PatternFormatter[] getFormatters(LogEvent event) {
+ public PatternFormatter[] getFormatters(final LogEvent event) {
Marker marker = event.getMarker();
if (marker == null) {
return defaultFormatters;
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/ScriptPatternSelector.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/ScriptPatternSelector.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/ScriptPatternSelector.java
index 6a02c46..01ade28 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/ScriptPatternSelector.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/ScriptPatternSelector.java
@@ -83,7 +83,7 @@ public class ScriptPatternSelector implements PatternSelector {
}
@Override
- public PatternFormatter[] getFormatters(LogEvent event) {
+ public PatternFormatter[] getFormatters(final LogEvent event) {
SimpleBindings bindings = new SimpleBindings();
bindings.putAll(configuration.getProperties());
bindings.put("substitutor", configuration.getStrSubstitutor());
@@ -99,7 +99,7 @@ public class ScriptPatternSelector implements PatternSelector {
@PluginFactory
- public static ScriptPatternSelector createSelector(@PluginElement("Script") AbstractScript script,
+ public static ScriptPatternSelector createSelector(@PluginElement("Script") final AbstractScript script,
@PluginElement("PatternMatch") final PatternMatch[] properties,
@PluginAttribute("defaultPattern") String defaultPattern,
@PluginAttribute(value = "alwaysWriteExceptions", defaultBoolean = true) final boolean alwaysWriteExceptions,
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/TextEncoderHelper.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/TextEncoderHelper.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/TextEncoderHelper.java
index 7d27830..8778acb 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/TextEncoderHelper.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/TextEncoderHelper.java
@@ -130,7 +130,7 @@ public class TextEncoderHelper {
return temp;
}
- private static ByteBuffer drainIfByteBufferFull(ByteBufferDestination destination, ByteBuffer temp, CoderResult result) {
+ private static ByteBuffer drainIfByteBufferFull(final ByteBufferDestination destination, ByteBuffer temp, final CoderResult result) {
if (result.isOverflow()) { // byte buffer full
// SHOULD NOT HAPPEN:
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SmtpManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SmtpManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SmtpManager.java
index 6683f1d..a6bbad8 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SmtpManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SmtpManager.java
@@ -67,7 +67,7 @@ public class SmtpManager extends AbstractManager {
private final FactoryData data;
- private static MimeMessage createMimeMessage(final FactoryData data, final Session session, LogEvent appendEvent)
+ private static MimeMessage createMimeMessage(final FactoryData data, final Session session, final LogEvent appendEvent)
throws MessagingException {
return new MimeMessageBuilder(session).setFrom(data.from).setReplyTo(data.replyto)
.setRecipients(Message.RecipientType.TO, data.to).setRecipients(Message.RecipientType.CC, data.cc)
@@ -295,7 +295,7 @@ public class SmtpManager extends AbstractManager {
}
}
- private synchronized void connect(LogEvent appendEvent) {
+ private synchronized void connect(final LogEvent appendEvent) {
if (message != null) {
return;
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/net/TcpSocketManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/TcpSocketManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/TcpSocketManager.java
index d518aee..4d83d97 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/TcpSocketManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/TcpSocketManager.java
@@ -116,7 +116,7 @@ public class TcpSocketManager extends AbstractSocketManager {
}
@Override
- protected void write(final byte[] bytes, final int offset, final int length, boolean immediateFlush) {
+ protected void write(final byte[] bytes, final int offset, final int length, final boolean immediateFlush) {
if (socket == null) {
if (connector != null && !immediateFail) {
connector.latch();
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/EqualsReplacementConverter.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/EqualsReplacementConverter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/EqualsReplacementConverter.java
index bb8464c..d4a2310 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/EqualsReplacementConverter.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/EqualsReplacementConverter.java
@@ -77,7 +77,7 @@ public final class EqualsReplacementConverter extends LogEventPatternConverter {
* @param parser The PatternParser.
*/
private EqualsReplacementConverter(final List<PatternFormatter> formatters, final String testString,
- final String substitution, PatternParser parser) {
+ final String substitution, final PatternParser parser) {
super("equals", "equals");
this.testString = testString;
this.substitution = substitution;
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/NameAbbreviator.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/NameAbbreviator.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/NameAbbreviator.java
index a59cc5f..bc114f1 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/NameAbbreviator.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/NameAbbreviator.java
@@ -226,7 +226,7 @@ public abstract class NameAbbreviator {
}
}
- private void abbreviateForDrop(String original, StringBuilder destination) {
+ private void abbreviateForDrop(final String original, final StringBuilder destination) {
// If a path does not contain enough path elements to drop, none will be dropped.
int start = 0;
int nextStart = 0;
@@ -242,7 +242,7 @@ public abstract class NameAbbreviator {
destination.append(original, start, original.length());
}
- private void abbreviateForRetain(String original, StringBuilder destination) {
+ private void abbreviateForRetain(final String original, final StringBuilder destination) {
// We subtract 1 from 'len' when assigning to 'end' to avoid out of
// bounds exception in return r.substring(end+1, len). This can happen if
// precision is 1 and the category name ends with a dot.
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/script/Script.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/script/Script.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/script/Script.java
index 3f0c1da..0eff8df 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/script/Script.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/script/Script.java
@@ -32,7 +32,7 @@ public class Script extends AbstractScript {
private static final Logger logger = StatusLogger.getLogger();
- public Script(String name, String language, String scriptText) {
+ public Script(final String name, final String language, final String scriptText) {
super(name, language, scriptText);
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/script/ScriptFile.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/script/ScriptFile.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/script/ScriptFile.java
index f2fe085..31f11d9 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/script/ScriptFile.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/script/ScriptFile.java
@@ -48,7 +48,7 @@ public class ScriptFile extends AbstractScript {
private final boolean isWatched;
- public ScriptFile(String name, Path filePath, String language, boolean isWatched, String scriptText) {
+ public ScriptFile(final String name, final Path filePath, final String language, final boolean isWatched, final String scriptText) {
super(name, language, scriptText);
this.filePath = filePath;
this.isWatched = isWatched;
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/script/ScriptManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/script/ScriptManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/script/ScriptManager.java
index ff73662..1cad47c 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/script/ScriptManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/script/ScriptManager.java
@@ -52,7 +52,7 @@ public class ScriptManager implements FileWatcher, Serializable {
private final WatchManager watchManager;
private static final SecurityManager SECURITY_MANAGER = System.getSecurityManager();
- public ScriptManager(WatchManager watchManager) {
+ public ScriptManager(final WatchManager watchManager) {
this.watchManager = watchManager;
final List<ScriptEngineFactory> factories = manager.getEngineFactories();
if (logger.isDebugEnabled()) {
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/script/ScriptRef.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/script/ScriptRef.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/script/ScriptRef.java
index 0ace830..d70da09 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/script/ScriptRef.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/script/ScriptRef.java
@@ -34,7 +34,7 @@ public class ScriptRef extends AbstractScript {
private static final Logger logger = StatusLogger.getLogger();
private final ScriptManager scriptManager;
- public ScriptRef(String name, ScriptManager scriptManager) {
+ public ScriptRef(final String name, final ScriptManager scriptManager) {
super(name, null, null);
this.scriptManager = scriptManager;
}
@@ -56,7 +56,7 @@ public class ScriptRef extends AbstractScript {
public static ScriptRef createReference(
// @formatter:off
@PluginAttribute("ref") final String name,
- @PluginConfiguration Configuration configuration) {
+ @PluginConfiguration final Configuration configuration) {
// @formatter:on
if (name == null) {
logger.error("No script name provided");
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/util/CronExpression.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/CronExpression.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/CronExpression.java
index dbb5a9d..2c0bfe4 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/CronExpression.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/CronExpression.java
@@ -262,7 +262,7 @@ public final class CronExpression {
* @throws java.text.ParseException if the string expression cannot be parsed into a valid
* <CODE>CronExpression</CODE>
*/
- public CronExpression(String cronExpression) throws ParseException {
+ public CronExpression(final String cronExpression) throws ParseException {
if (cronExpression == null) {
throw new IllegalArgumentException("cronExpression cannot be null");
}
@@ -281,7 +281,7 @@ public final class CronExpression {
* @return a boolean indicating whether the given date satisfies the cron
* expression
*/
- public boolean isSatisfiedBy(Date date) {
+ public boolean isSatisfiedBy(final Date date) {
Calendar testDateCal = Calendar.getInstance(getTimeZone());
testDateCal.setTime(date);
testDateCal.set(Calendar.MILLISECOND, 0);
@@ -302,7 +302,7 @@ public final class CronExpression {
* date/time
* @return the next valid date/time
*/
- public Date getNextValidTimeAfter(Date date) {
+ public Date getNextValidTimeAfter(final Date date) {
return getTimeAfter(date);
}
@@ -314,7 +314,7 @@ public final class CronExpression {
* invalid date/time
* @return the next valid date/time
*/
- public Date getNextInvalidTimeAfter(Date date) {
+ public Date getNextInvalidTimeAfter(final Date date) {
long difference = 1000;
//move back to the nearest second so differences will be accurate
@@ -362,7 +362,7 @@ public final class CronExpression {
* Sets the time zone for which this <code>CronExpression</code>
* will be resolved.
*/
- public void setTimeZone(TimeZone timeZone) {
+ public void setTimeZone(final TimeZone timeZone) {
this.timeZone = timeZone;
}
@@ -384,7 +384,7 @@ public final class CronExpression {
* @return a boolean indicating whether the given expression is a valid cron
* expression
*/
- public static boolean isValidExpression(String cronExpression) {
+ public static boolean isValidExpression(final String cronExpression) {
try {
new CronExpression(cronExpression);
@@ -395,7 +395,7 @@ public final class CronExpression {
return true;
}
- public static void validateExpression(String cronExpression) throws ParseException {
+ public static void validateExpression(final String cronExpression) throws ParseException {
new CronExpression(cronExpression);
}
@@ -407,7 +407,7 @@ public final class CronExpression {
//
////////////////////////////////////////////////////////////////////////////
- protected void buildExpression(String expression) throws ParseException {
+ protected void buildExpression(final String expression) throws ParseException {
expressionParsed = true;
try {
@@ -493,7 +493,7 @@ public final class CronExpression {
}
}
- protected int storeExpressionVals(int pos, String s, int type)
+ protected int storeExpressionVals(final int pos, final String s, final int type)
throws ParseException {
int incr = 0;
@@ -684,7 +684,7 @@ public final class CronExpression {
return i;
}
- protected int checkNext(int pos, String s, int val, int type)
+ protected int checkNext(final int pos, final String s, final int val, final int type)
throws ParseException {
int end = -1;
@@ -861,7 +861,7 @@ public final class CronExpression {
return buf.toString();
}
- protected String getExpressionSetSummary(java.util.Set<Integer> set) {
+ protected String getExpressionSetSummary(final java.util.Set<Integer> set) {
if (set.contains(NO_SPEC)) {
return "?";
@@ -887,7 +887,7 @@ public final class CronExpression {
return buf.toString();
}
- protected String getExpressionSetSummary(java.util.ArrayList<Integer> list) {
+ protected String getExpressionSetSummary(final java.util.ArrayList<Integer> list) {
if (list.contains(NO_SPEC)) {
return "?";
@@ -913,7 +913,7 @@ public final class CronExpression {
return buf.toString();
}
- protected int skipWhiteSpace(int i, String s) {
+ protected int skipWhiteSpace(int i, final String s) {
for (; i < s.length() && (s.charAt(i) == ' ' || s.charAt(i) == '\t'); i++) {
;
}
@@ -921,7 +921,7 @@ public final class CronExpression {
return i;
}
- protected int findNextWhiteSpace(int i, String s) {
+ protected int findNextWhiteSpace(int i, final String s) {
for (; i < s.length() && (s.charAt(i) != ' ' || s.charAt(i) != '\t'); i++) {
;
}
@@ -929,7 +929,7 @@ public final class CronExpression {
return i;
}
- protected void addToSet(int val, int end, int incr, int type)
+ protected void addToSet(final int val, final int end, int incr, final int type)
throws ParseException {
TreeSet<Integer> set = getSet(type);
@@ -1076,7 +1076,7 @@ public final class CronExpression {
}
}
- TreeSet<Integer> getSet(int type) {
+ TreeSet<Integer> getSet(final int type) {
switch (type) {
case SECOND:
return seconds;
@@ -1097,7 +1097,7 @@ public final class CronExpression {
}
}
- protected ValueSet getValue(int v, String s, int i) {
+ protected ValueSet getValue(final int v, final String s, int i) {
char c = s.charAt(i);
StringBuilder s1 = new StringBuilder(String.valueOf(v));
while (c >= '0' && c <= '9') {
@@ -1115,13 +1115,13 @@ public final class CronExpression {
return val;
}
- protected int getNumericValue(String s, int i) {
+ protected int getNumericValue(final String s, final int i) {
int endOfVal = findNextWhiteSpace(i, s);
String val = s.substring(i, endOfVal);
return Integer.parseInt(val);
}
- protected int getMonthNumber(String s) {
+ protected int getMonthNumber(final String s) {
Integer integer = monthMap.get(s);
if (integer == null) {
@@ -1131,7 +1131,7 @@ public final class CronExpression {
return integer;
}
- protected int getDayOfWeekNumber(String s) {
+ protected int getDayOfWeekNumber(final String s) {
Integer integer = dayMap.get(s);
if (integer == null) {
@@ -1558,7 +1558,7 @@ public final class CronExpression {
* @param cal the calendar to operate on
* @param hour the hour to set
*/
- protected void setCalendarHour(Calendar cal, int hour) {
+ protected void setCalendarHour(final Calendar cal, final int hour) {
cal.set(java.util.Calendar.HOUR_OF_DAY, hour);
if (cal.get(java.util.Calendar.HOUR_OF_DAY) != hour && hour != 24) {
cal.set(java.util.Calendar.HOUR_OF_DAY, hour + 1);
@@ -1569,7 +1569,7 @@ public final class CronExpression {
* NOT YET IMPLEMENTED: Returns the time before the given time
* that the <code>CronExpression</code> matches.
*/
- public Date getTimeBefore(Date endTime) {
+ public Date getTimeBefore(final Date endTime) {
// FUTURE_TODO: implement QUARTZ-423
return null;
}
@@ -1583,11 +1583,11 @@ public final class CronExpression {
return null;
}
- protected boolean isLeapYear(int year) {
+ protected boolean isLeapYear(final int year) {
return ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0));
}
- protected int getLastDayOfMonth(int monthNum, int year) {
+ protected int getLastDayOfMonth(final int monthNum, final int year) {
switch (monthNum) {
case 1:
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/util/DummyNanoClock.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/DummyNanoClock.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/DummyNanoClock.java
index 8200c38..e3d6c2b 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/DummyNanoClock.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/DummyNanoClock.java
@@ -1,48 +1,48 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-package org.apache.logging.log4j.core.util;
-
-/**
- * Implementation of the {@code NanoClock} interface that always returns a fixed value.
- */
-public final class DummyNanoClock implements NanoClock {
-
- private final long fixedNanoTime;
-
- public DummyNanoClock() {
- this(0L);
- }
-
- /**
- * Constructs a new DummyNanoClock with the specified value to return.
- * @param fixedNanoTime the value to return from {@link #nanoTime()}.
- */
- public DummyNanoClock(long fixedNanoTime) {
- this.fixedNanoTime = fixedNanoTime;
- }
-
- /**
- * Returns the constructor value.
- *
- * @return the constructor value
- */
- @Override
- public long nanoTime() {
- return fixedNanoTime;
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.core.util;
+
+/**
+ * Implementation of the {@code NanoClock} interface that always returns a fixed value.
+ */
+public final class DummyNanoClock implements NanoClock {
+
+ private final long fixedNanoTime;
+
+ public DummyNanoClock() {
+ this(0L);
+ }
+
+ /**
+ * Constructs a new DummyNanoClock with the specified value to return.
+ * @param fixedNanoTime the value to return from {@link #nanoTime()}.
+ */
+ public DummyNanoClock(final long fixedNanoTime) {
+ this.fixedNanoTime = fixedNanoTime;
+ }
+
+ /**
+ * Returns the constructor value.
+ *
+ * @return the constructor value
+ */
+ @Override
+ public long nanoTime() {
+ return fixedNanoTime;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/util/ExtensionLanguageMapping.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/ExtensionLanguageMapping.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/ExtensionLanguageMapping.java
index c3442ee..22c005b 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/ExtensionLanguageMapping.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/ExtensionLanguageMapping.java
@@ -36,7 +36,7 @@ public enum ExtensionLanguageMapping {
private final String extension;
private final String language;
- ExtensionLanguageMapping(String extension, String language) {
+ ExtensionLanguageMapping(final String extension, final String language) {
this.extension = extension;
this.language = language;
}
@@ -49,7 +49,7 @@ public enum ExtensionLanguageMapping {
return this.language;
}
- public static ExtensionLanguageMapping getByExtension(String extension) {
+ public static ExtensionLanguageMapping getByExtension(final String extension) {
for (final ExtensionLanguageMapping mapping : values()) {
if (mapping.extension.equals(extension)) {
return mapping;
@@ -58,7 +58,7 @@ public enum ExtensionLanguageMapping {
return null;
}
- public static List<ExtensionLanguageMapping> getByLanguage(String language) {
+ public static List<ExtensionLanguageMapping> getByLanguage(final String language) {
final List<ExtensionLanguageMapping> list = new ArrayList<>();
for (final ExtensionLanguageMapping mapping : values()) {
if (mapping.language.equals(language)) {
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/util/FileUtils.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/FileUtils.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/FileUtils.java
index ad675ed..258773f 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/FileUtils.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/FileUtils.java
@@ -93,7 +93,7 @@ public final class FileUtils {
return url != null && (url.getProtocol().equals(PROTOCOL_FILE) || url.getProtocol().equals(JBOSS_FILE));
}
- public static String getFileExtension(File file) {
+ public static String getFileExtension(final File file) {
String fileName = file.getName();
if (fileName.lastIndexOf(".") != -1 && fileName.lastIndexOf(".") != 0) {
return fileName.substring(fileName.lastIndexOf(".") + 1);
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/util/JsonUtils.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/JsonUtils.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/JsonUtils.java
index bca5417..685d12f 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/JsonUtils.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/JsonUtils.java
@@ -46,7 +46,7 @@ public final class JsonUtils {
/**
* Quote text contents using JSON standard quoting, and append results to a supplied {@link StringBuilder}.
*/
- public static void quoteAsString(CharSequence input, StringBuilder output) {
+ public static void quoteAsString(final CharSequence input, final StringBuilder output) {
final char[] qbuf = getQBuf();
final int[] escCodes = CharTypes.get7BitOutputEscapes();
final int escCodeCount = escCodes.length;
@@ -77,7 +77,7 @@ public final class JsonUtils {
}
}
- private static int _appendNumeric(int value, char[] qbuf) {
+ private static int _appendNumeric(final int value, final char[] qbuf) {
qbuf[1] = 'u';
// We know it's a control char, so only the last 2 chars are non-0
qbuf[4] = HC[value >> 4];
@@ -85,7 +85,7 @@ public final class JsonUtils {
return 6;
}
- private static int _appendNamed(int esc, char[] qbuf) {
+ private static int _appendNamed(final int esc, final char[] qbuf) {
qbuf[1] = (char) esc;
return 2;
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/util/StringEncoder.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/StringEncoder.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/StringEncoder.java
index a2011cb..a9c3548 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/StringEncoder.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/StringEncoder.java
@@ -59,7 +59,7 @@ public final class StringEncoder {
* @return the encoded String
* @see <a href="https://issues.apache.org/jira/browse/LOG4J2-1151">LOG4J2-1151</a>
*/
- public static byte[] encodeSingleByteChars(CharSequence s) {
+ public static byte[] encodeSingleByteChars(final CharSequence s) {
final int length = s.length();
final byte[] result = new byte[length];
encodeString(s, 0, length, result);
@@ -71,7 +71,7 @@ public final class StringEncoder {
* Implementation note: this is the fast path. If the char array contains only ISO-8859-1 characters, all the work
* will be done here.
*/
- public static int encodeIsoChars(CharSequence charArray, int charIndex, byte[] byteArray, int byteIndex, int length) {
+ public static int encodeIsoChars(final CharSequence charArray, int charIndex, final byte[] byteArray, int byteIndex, final int length) {
int i = 0;
for (; i < length; i++) {
char c = charArray.charAt(charIndex++);
@@ -84,7 +84,7 @@ public final class StringEncoder {
}
// LOG4J2-1151
- public static int encodeString(CharSequence charArray, int charOffset, int charLength, byte[] byteArray) {
+ public static int encodeString(final CharSequence charArray, int charOffset, int charLength, final byte[] byteArray) {
int byteOffset = 0;
int length = Math.min(charLength, byteArray.length);
int charDoneIndex = charOffset + length;
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/util/WatchManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/WatchManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/WatchManager.java
index 146bff7..746c2d5 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/WatchManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/WatchManager.java
@@ -40,11 +40,11 @@ public class WatchManager extends AbstractLifeCycle {
private ScheduledFuture<?> future;
private final ConfigurationScheduler scheduler;
- public WatchManager(ConfigurationScheduler scheduler) {
+ public WatchManager(final ConfigurationScheduler scheduler) {
this.scheduler = scheduler;
}
- public void setIntervalSeconds(int intervalSeconds) {
+ public void setIntervalSeconds(final int intervalSeconds) {
if (!isStarted()) {
if (this.intervalSeconds > 0 && intervalSeconds == 0) {
scheduler.decrementScheduledItems();
@@ -74,7 +74,7 @@ public class WatchManager extends AbstractLifeCycle {
super.stop();
}
- public void watchFile(File file, FileWatcher watcher) {
+ public void watchFile(final File file, final FileWatcher watcher) {
watchers.put(file, new FileMonitor(file.lastModified(), watcher));
}
@@ -103,7 +103,7 @@ public class WatchManager extends AbstractLifeCycle {
}
}
- private boolean fileModified(FileMonitor fileMonitor, long lastModfied) {
+ private boolean fileModified(final FileMonitor fileMonitor, final long lastModfied) {
return lastModfied != fileMonitor.lastModified;
}
}
@@ -112,7 +112,7 @@ public class WatchManager extends AbstractLifeCycle {
private final FileWatcher fileWatcher;
private long lastModified;
- public FileMonitor(long lastModified, FileWatcher fileWatcher) {
+ public FileMonitor(final long lastModified, final FileWatcher fileWatcher) {
this.fileWatcher = fileWatcher;
this.lastModified = lastModified;
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/util/datetime/FixedDateFormat.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/datetime/FixedDateFormat.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/datetime/FixedDateFormat.java
index 631d334..e36bba1 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/datetime/FixedDateFormat.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/datetime/FixedDateFormat.java
@@ -1,343 +1,343 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.core.util.datetime;
-
-import java.util.Calendar;
-import java.util.Objects;
-
-/**
- * Custom time formatter that trades flexibility for performance. This formatter only supports the date patterns defined
- * in {@link FixedFormat}. For any other date patterns use {@link FastDateFormat}.
- * <p>
- * Related benchmarks: /log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/TimeFormatBenchmark.java and
- * /log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ThreadsafeDateFormatBenchmark.java
- */
-public class FixedDateFormat {
- /**
- * Enumeration over the supported date/time format patterns.
- * <p>
- * Package protected for unit tests.
- */
- public enum FixedFormat {
- /**
- * ABSOLUTE time format: {@code "HH:mm:ss,SSS"}.
- */
- ABSOLUTE("HH:mm:ss,SSS", null, 0, ':', 1, ',', 1),
-
- /**
- * ABSOLUTE time format variation with period separator: {@code "HH:mm:ss.SSS"}.
- */
- ABSOLUTE_PERIOD("HH:mm:ss.SSS", null, 0, ':', 1, '.', 1),
-
- /**
- * COMPACT time format: {@code "yyyyMMddHHmmssSSS"}.
- */
- COMPACT("yyyyMMddHHmmssSSS", "yyyyMMdd", 0, ' ', 0, ' ', 0),
-
- /**
- * DATE_AND_TIME time format: {@code "dd MMM yyyy HH:mm:ss,SSS"}.
- */
- DATE("dd MMM yyyy HH:mm:ss,SSS", "dd MMM yyyy ", 0, ':', 1, ',', 1),
-
- /**
- * DATE_AND_TIME time format variation with period separator: {@code "dd MMM yyyy HH:mm:ss.SSS"}.
- */
- DATE_PERIOD("dd MMM yyyy HH:mm:ss.SSS", "dd MMM yyyy ", 0, ':', 1, '.', 1),
-
- /**
- * DEFAULT time format: {@code "yyyy-MM-dd HH:mm:ss,SSS"}.
- */
- DEFAULT("yyyy-MM-dd HH:mm:ss,SSS", "yyyy-MM-dd ", 0, ':', 1, ',', 1),
-
- /**
- * DEFAULT time format variation with period separator: {@code "yyyy-MM-dd HH:mm:ss.SSS"}.
- */
- DEFAULT_PERIOD("yyyy-MM-dd HH:mm:ss.SSS", "yyyy-MM-dd ", 0, ':', 1, '.', 1),
-
- /**
- * ISO8601_BASIC time format: {@code "yyyyMMdd'T'HHmmss,SSS"}.
- */
- ISO8601_BASIC("yyyyMMdd'T'HHmmss,SSS", "yyyyMMdd'T'", 2, ' ', 0, ',', 1),
-
- /**
- * ISO8601 time format: {@code "yyyy-MM-dd'T'HH:mm:ss,SSS"}.
- */
- ISO8601("yyyy-MM-dd'T'HH:mm:ss,SSS", "yyyy-MM-dd'T'", 2, ':', 1, ',', 1);
-
- private final String pattern;
- private final String datePattern;
- private final int escapeCount;
- private final char timeSeparatorChar;
- private final int timeSeparatorLength;
- private final char millisSeparatorChar;
- private final int millisSeparatorLength;
-
- FixedFormat(final String pattern, final String datePattern, final int escapeCount, final char timeSeparator,
- final int timeSepLength, final char millisSeparator, final int millisSepLength) {
- this.timeSeparatorChar = timeSeparator;
- this.timeSeparatorLength = timeSepLength;
- this.millisSeparatorChar = millisSeparator;
- this.millisSeparatorLength = millisSepLength;
- this.pattern = Objects.requireNonNull(pattern);
- this.datePattern = datePattern; // may be null
- this.escapeCount = escapeCount;
- }
-
- /**
- * Returns the full pattern.
- *
- * @return the full pattern
- */
- public String getPattern() {
- return pattern;
- }
-
- /**
- * Returns the date part of the pattern.
- *
- * @return the date part of the pattern
- */
- public String getDatePattern() {
- return datePattern;
- }
-
- /**
- * Returns the FixedFormat with the name or pattern matching the specified string or {@code null} if not found.
- *
- * @param nameOrPattern the name or pattern to find a FixedFormat for
- * @return the FixedFormat with the name or pattern matching the specified string
- */
- public static FixedFormat lookup(final String nameOrPattern) {
- for (final FixedFormat type : FixedFormat.values()) {
- if (type.name().equals(nameOrPattern) || type.getPattern().equals(nameOrPattern)) {
- return type;
- }
- }
- return null;
- }
-
- /**
- * Returns the length of the resulting formatted date and time strings.
- *
- * @return the length of the resulting formatted date and time strings
- */
- public int getLength() {
- return pattern.length() - escapeCount;
- }
-
- /**
- * Returns the length of the date part of the resulting formatted string.
- *
- * @return the length of the date part of the resulting formatted string
- */
- public int getDatePatternLength() {
- return getDatePattern() == null ? 0 : getDatePattern().length() - escapeCount;
- }
-
- /**
- * Returns the {@code FastDateFormat} object for formatting the date part of the pattern or {@code null} if the
- * pattern does not have a date part.
- *
- * @return the {@code FastDateFormat} object for formatting the date part of the pattern or {@code null}
- */
- public FastDateFormat getFastDateFormat() {
- return getDatePattern() == null ? null : FastDateFormat.getInstance(getDatePattern());
- }
- }
-
- private final FixedFormat fixedFormat;
- private final int length;
- private final FastDateFormat fastDateFormat; // may be null
- private final char timeSeparatorChar;
- private final char millisSeparatorChar;
- private final int timeSeparatorLength;
- private final int millisSeparatorLength;
-
- private volatile long midnightToday = 0;
- private volatile long midnightTomorrow = 0;
- // cachedDate does not need to be volatile because
- // there is a write to a volatile field *after* cachedDate is modified,
- // and there is a read from a volatile field *before* cachedDate is read.
- // The Java memory model guarantees that because of the above,
- // changes to cachedDate in one thread are visible to other threads.
- // See http://g.oswego.edu/dl/jmm/cookbook.html
- private char[] cachedDate; // may be null
- private int dateLength;
-
- /**
- * Constructs a FixedDateFormat for the specified fixed format.
- * <p>
- * Package protected for unit tests.
- *
- * @param fixedFormat the fixed format
- */
- FixedDateFormat(final FixedFormat fixedFormat) {
- this.fixedFormat = Objects.requireNonNull(fixedFormat);
- this.timeSeparatorChar = fixedFormat.timeSeparatorChar;
- this.timeSeparatorLength = fixedFormat.timeSeparatorLength;
- this.millisSeparatorChar = fixedFormat.millisSeparatorChar;
- this.millisSeparatorLength = fixedFormat.millisSeparatorLength;
- this.length = fixedFormat.getLength();
- this.fastDateFormat = fixedFormat.getFastDateFormat();
- }
-
- public static FixedDateFormat createIfSupported(final String... options) {
- if (options == null || options.length == 0 || options[0] == null) {
- return new FixedDateFormat(FixedFormat.DEFAULT);
- }
- if (options.length > 1) {
- return null; // time zone not supported
- }
- final FixedFormat type = FixedFormat.lookup(options[0]);
- return type == null ? null : new FixedDateFormat(type);
- }
-
- /**
- * Returns a new {@code FixedDateFormat} object for the specified {@code FixedFormat} and a {@code null} TimeZone.
- *
- * @param format the format to use
- * @return a new {@code FixedDateFormat} object
- */
- public static FixedDateFormat create(FixedFormat format) {
- return new FixedDateFormat(format);
- }
-
- /**
- * Returns the full pattern of the selected fixed format.
- *
- * @return the full date-time pattern
- */
- public String getFormat() {
- return fixedFormat.getPattern();
- }
-
- // Profiling showed this method is important to log4j performance. Modify with care!
- // 30 bytes (allows immediate JVM inlining: <= -XX:MaxInlineSize=35 bytes)
- private long millisSinceMidnight(final long now) {
- if (now >= midnightTomorrow || now < midnightToday) {
- updateMidnightMillis(now);
- }
- return now - midnightToday;
- }
-
- private void updateMidnightMillis(final long now) {
-
- updateCachedDate(now);
-
- midnightToday = calcMidnightMillis(now, 0);
- midnightTomorrow = calcMidnightMillis(now, 1);
- }
-
- static long calcMidnightMillis(final long time, final int addDays) {
- final Calendar cal = Calendar.getInstance();
- cal.setTimeInMillis(time);
- cal.set(Calendar.HOUR_OF_DAY, 0);
- cal.set(Calendar.MINUTE, 0);
- cal.set(Calendar.SECOND, 0);
- cal.set(Calendar.MILLISECOND, 0);
- cal.add(Calendar.DATE, addDays);
- return cal.getTimeInMillis();
- }
-
- private void updateCachedDate(final long now) {
- if (fastDateFormat != null) {
- final StringBuilder result = fastDateFormat.format(now, new StringBuilder());
- cachedDate = result.toString().toCharArray();
- dateLength = result.length();
- }
- }
-
- // Profiling showed this method is important to log4j performance. Modify with care!
- // 28 bytes (allows immediate JVM inlining: <= -XX:MaxInlineSize=35 bytes)
- public String format(final long time) {
- final char[] result = new char[length << 1]; // double size for locales with lengthy DateFormatSymbols
- int written = format(time, result, 0);
- return new String(result, 0, written);
- }
-
- // Profiling showed this method is important to log4j performance. Modify with care!
- // 31 bytes (allows immediate JVM inlining: <= -XX:MaxInlineSize=35 bytes)
- public int format(final long time, final char[] buffer, final int startPos) {
- // Calculate values by getting the ms values first and do then
- // calculate the hour minute and second values divisions.
-
- // Get daytime in ms: this does fit into an int
- // int ms = (int) (time % 86400000);
- final int ms = (int) (millisSinceMidnight(time));
- writeDate(buffer, startPos);
- return writeTime(ms, buffer, startPos + dateLength) - startPos;
- }
-
- // Profiling showed this method is important to log4j performance. Modify with care!
- // 22 bytes (allows immediate JVM inlining: <= -XX:MaxInlineSize=35 bytes)
- private void writeDate(final char[] buffer, final int startPos) {
- if (cachedDate != null) {
- System.arraycopy(cachedDate, 0, buffer, startPos, dateLength);
- }
- }
-
- // Profiling showed this method is important to log4j performance. Modify with care!
- // 262 bytes (will be inlined when hot enough: <= -XX:FreqInlineSize=325 bytes on Linux)
- private int writeTime(int ms, final char[] buffer, int pos) {
- final int hours = ms / 3600000;
- ms -= 3600000 * hours;
-
- final int minutes = ms / 60000;
- ms -= 60000 * minutes;
-
- final int seconds = ms / 1000;
- ms -= 1000 * seconds;
-
- // Hour
- int temp = hours / 10;
- buffer[pos++] = ((char) (temp + '0'));
-
- // Do subtract to get remainder instead of doing % 10
- buffer[pos++] = ((char) (hours - 10 * temp + '0'));
- buffer[pos] = timeSeparatorChar;
- pos += timeSeparatorLength;
-
- // Minute
- temp = minutes / 10;
- buffer[pos++] = ((char) (temp + '0'));
-
- // Do subtract to get remainder instead of doing % 10
- buffer[pos++] = ((char) (minutes - 10 * temp + '0'));
- buffer[pos] = timeSeparatorChar;
- pos += timeSeparatorLength;
-
- // Second
- temp = seconds / 10;
- buffer[pos++] = ((char) (temp + '0'));
- buffer[pos++] = ((char) (seconds - 10 * temp + '0'));
- buffer[pos] = millisSeparatorChar;
- pos += millisSeparatorLength;
-
- // Millisecond
- temp = ms / 100;
- buffer[pos++] = ((char) (temp + '0'));
-
- ms -= 100 * temp;
- temp = ms / 10;
- buffer[pos++] = ((char) (temp + '0'));
-
- ms -= 10 * temp;
- buffer[pos++] = ((char) (ms + '0'));
- return pos;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+
+package org.apache.logging.log4j.core.util.datetime;
+
+import java.util.Calendar;
+import java.util.Objects;
+
+/**
+ * Custom time formatter that trades flexibility for performance. This formatter only supports the date patterns defined
+ * in {@link FixedFormat}. For any other date patterns use {@link FastDateFormat}.
+ * <p>
+ * Related benchmarks: /log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/TimeFormatBenchmark.java and
+ * /log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ThreadsafeDateFormatBenchmark.java
+ */
+public class FixedDateFormat {
+ /**
+ * Enumeration over the supported date/time format patterns.
+ * <p>
+ * Package protected for unit tests.
+ */
+ public enum FixedFormat {
+ /**
+ * ABSOLUTE time format: {@code "HH:mm:ss,SSS"}.
+ */
+ ABSOLUTE("HH:mm:ss,SSS", null, 0, ':', 1, ',', 1),
+
+ /**
+ * ABSOLUTE time format variation with period separator: {@code "HH:mm:ss.SSS"}.
+ */
+ ABSOLUTE_PERIOD("HH:mm:ss.SSS", null, 0, ':', 1, '.', 1),
+
+ /**
+ * COMPACT time format: {@code "yyyyMMddHHmmssSSS"}.
+ */
+ COMPACT("yyyyMMddHHmmssSSS", "yyyyMMdd", 0, ' ', 0, ' ', 0),
+
+ /**
+ * DATE_AND_TIME time format: {@code "dd MMM yyyy HH:mm:ss,SSS"}.
+ */
+ DATE("dd MMM yyyy HH:mm:ss,SSS", "dd MMM yyyy ", 0, ':', 1, ',', 1),
+
+ /**
+ * DATE_AND_TIME time format variation with period separator: {@code "dd MMM yyyy HH:mm:ss.SSS"}.
+ */
+ DATE_PERIOD("dd MMM yyyy HH:mm:ss.SSS", "dd MMM yyyy ", 0, ':', 1, '.', 1),
+
+ /**
+ * DEFAULT time format: {@code "yyyy-MM-dd HH:mm:ss,SSS"}.
+ */
+ DEFAULT("yyyy-MM-dd HH:mm:ss,SSS", "yyyy-MM-dd ", 0, ':', 1, ',', 1),
+
+ /**
+ * DEFAULT time format variation with period separator: {@code "yyyy-MM-dd HH:mm:ss.SSS"}.
+ */
+ DEFAULT_PERIOD("yyyy-MM-dd HH:mm:ss.SSS", "yyyy-MM-dd ", 0, ':', 1, '.', 1),
+
+ /**
+ * ISO8601_BASIC time format: {@code "yyyyMMdd'T'HHmmss,SSS"}.
+ */
+ ISO8601_BASIC("yyyyMMdd'T'HHmmss,SSS", "yyyyMMdd'T'", 2, ' ', 0, ',', 1),
+
+ /**
+ * ISO8601 time format: {@code "yyyy-MM-dd'T'HH:mm:ss,SSS"}.
+ */
+ ISO8601("yyyy-MM-dd'T'HH:mm:ss,SSS", "yyyy-MM-dd'T'", 2, ':', 1, ',', 1);
+
+ private final String pattern;
+ private final String datePattern;
+ private final int escapeCount;
+ private final char timeSeparatorChar;
+ private final int timeSeparatorLength;
+ private final char millisSeparatorChar;
+ private final int millisSeparatorLength;
+
+ FixedFormat(final String pattern, final String datePattern, final int escapeCount, final char timeSeparator,
+ final int timeSepLength, final char millisSeparator, final int millisSepLength) {
+ this.timeSeparatorChar = timeSeparator;
+ this.timeSeparatorLength = timeSepLength;
+ this.millisSeparatorChar = millisSeparator;
+ this.millisSeparatorLength = millisSepLength;
+ this.pattern = Objects.requireNonNull(pattern);
+ this.datePattern = datePattern; // may be null
+ this.escapeCount = escapeCount;
+ }
+
+ /**
+ * Returns the full pattern.
+ *
+ * @return the full pattern
+ */
+ public String getPattern() {
+ return pattern;
+ }
+
+ /**
+ * Returns the date part of the pattern.
+ *
+ * @return the date part of the pattern
+ */
+ public String getDatePattern() {
+ return datePattern;
+ }
+
+ /**
+ * Returns the FixedFormat with the name or pattern matching the specified string or {@code null} if not found.
+ *
+ * @param nameOrPattern the name or pattern to find a FixedFormat for
+ * @return the FixedFormat with the name or pattern matching the specified string
+ */
+ public static FixedFormat lookup(final String nameOrPattern) {
+ for (final FixedFormat type : FixedFormat.values()) {
+ if (type.name().equals(nameOrPattern) || type.getPattern().equals(nameOrPattern)) {
+ return type;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns the length of the resulting formatted date and time strings.
+ *
+ * @return the length of the resulting formatted date and time strings
+ */
+ public int getLength() {
+ return pattern.length() - escapeCount;
+ }
+
+ /**
+ * Returns the length of the date part of the resulting formatted string.
+ *
+ * @return the length of the date part of the resulting formatted string
+ */
+ public int getDatePatternLength() {
+ return getDatePattern() == null ? 0 : getDatePattern().length() - escapeCount;
+ }
+
+ /**
+ * Returns the {@code FastDateFormat} object for formatting the date part of the pattern or {@code null} if the
+ * pattern does not have a date part.
+ *
+ * @return the {@code FastDateFormat} object for formatting the date part of the pattern or {@code null}
+ */
+ public FastDateFormat getFastDateFormat() {
+ return getDatePattern() == null ? null : FastDateFormat.getInstance(getDatePattern());
+ }
+ }
+
+ private final FixedFormat fixedFormat;
+ private final int length;
+ private final FastDateFormat fastDateFormat; // may be null
+ private final char timeSeparatorChar;
+ private final char millisSeparatorChar;
+ private final int timeSeparatorLength;
+ private final int millisSeparatorLength;
+
+ private volatile long midnightToday = 0;
+ private volatile long midnightTomorrow = 0;
+ // cachedDate does not need to be volatile because
+ // there is a write to a volatile field *after* cachedDate is modified,
+ // and there is a read from a volatile field *before* cachedDate is read.
+ // The Java memory model guarantees that because of the above,
+ // changes to cachedDate in one thread are visible to other threads.
+ // See http://g.oswego.edu/dl/jmm/cookbook.html
+ private char[] cachedDate; // may be null
+ private int dateLength;
+
+ /**
+ * Constructs a FixedDateFormat for the specified fixed format.
+ * <p>
+ * Package protected for unit tests.
+ *
+ * @param fixedFormat the fixed format
+ */
+ FixedDateFormat(final FixedFormat fixedFormat) {
+ this.fixedFormat = Objects.requireNonNull(fixedFormat);
+ this.timeSeparatorChar = fixedFormat.timeSeparatorChar;
+ this.timeSeparatorLength = fixedFormat.timeSeparatorLength;
+ this.millisSeparatorChar = fixedFormat.millisSeparatorChar;
+ this.millisSeparatorLength = fixedFormat.millisSeparatorLength;
+ this.length = fixedFormat.getLength();
+ this.fastDateFormat = fixedFormat.getFastDateFormat();
+ }
+
+ public static FixedDateFormat createIfSupported(final String... options) {
+ if (options == null || options.length == 0 || options[0] == null) {
+ return new FixedDateFormat(FixedFormat.DEFAULT);
+ }
+ if (options.length > 1) {
+ return null; // time zone not supported
+ }
+ final FixedFormat type = FixedFormat.lookup(options[0]);
+ return type == null ? null : new FixedDateFormat(type);
+ }
+
+ /**
+ * Returns a new {@code FixedDateFormat} object for the specified {@code FixedFormat} and a {@code null} TimeZone.
+ *
+ * @param format the format to use
+ * @return a new {@code FixedDateFormat} object
+ */
+ public static FixedDateFormat create(final FixedFormat format) {
+ return new FixedDateFormat(format);
+ }
+
+ /**
+ * Returns the full pattern of the selected fixed format.
+ *
+ * @return the full date-time pattern
+ */
+ public String getFormat() {
+ return fixedFormat.getPattern();
+ }
+
+ // Profiling showed this method is important to log4j performance. Modify with care!
+ // 30 bytes (allows immediate JVM inlining: <= -XX:MaxInlineSize=35 bytes)
+ private long millisSinceMidnight(final long now) {
+ if (now >= midnightTomorrow || now < midnightToday) {
+ updateMidnightMillis(now);
+ }
+ return now - midnightToday;
+ }
+
+ private void updateMidnightMillis(final long now) {
+
+ updateCachedDate(now);
+
+ midnightToday = calcMidnightMillis(now, 0);
+ midnightTomorrow = calcMidnightMillis(now, 1);
+ }
+
+ static long calcMidnightMillis(final long time, final int addDays) {
+ final Calendar cal = Calendar.getInstance();
+ cal.setTimeInMillis(time);
+ cal.set(Calendar.HOUR_OF_DAY, 0);
+ cal.set(Calendar.MINUTE, 0);
+ cal.set(Calendar.SECOND, 0);
+ cal.set(Calendar.MILLISECOND, 0);
+ cal.add(Calendar.DATE, addDays);
+ return cal.getTimeInMillis();
+ }
+
+ private void updateCachedDate(final long now) {
+ if (fastDateFormat != null) {
+ final StringBuilder result = fastDateFormat.format(now, new StringBuilder());
+ cachedDate = result.toString().toCharArray();
+ dateLength = result.length();
+ }
+ }
+
+ // Profiling showed this method is important to log4j performance. Modify with care!
+ // 28 bytes (allows immediate JVM inlining: <= -XX:MaxInlineSize=35 bytes)
+ public String format(final long time) {
+ final char[] result = new char[length << 1]; // double size for locales with lengthy DateFormatSymbols
+ int written = format(time, result, 0);
+ return new String(result, 0, written);
+ }
+
+ // Profiling showed this method is important to log4j performance. Modify with care!
+ // 31 bytes (allows immediate JVM inlining: <= -XX:MaxInlineSize=35 bytes)
+ public int format(final long time, final char[] buffer, final int startPos) {
+ // Calculate values by getting the ms values first and do then
+ // calculate the hour minute and second values divisions.
+
+ // Get daytime in ms: this does fit into an int
+ // int ms = (int) (time % 86400000);
+ final int ms = (int) (millisSinceMidnight(time));
+ writeDate(buffer, startPos);
+ return writeTime(ms, buffer, startPos + dateLength) - startPos;
+ }
+
+ // Profiling showed this method is important to log4j performance. Modify with care!
+ // 22 bytes (allows immediate JVM inlining: <= -XX:MaxInlineSize=35 bytes)
+ private void writeDate(final char[] buffer, final int startPos) {
+ if (cachedDate != null) {
+ System.arraycopy(cachedDate, 0, buffer, startPos, dateLength);
+ }
+ }
+
+ // Profiling showed this method is important to log4j performance. Modify with care!
+ // 262 bytes (will be inlined when hot enough: <= -XX:FreqInlineSize=325 bytes on Linux)
+ private int writeTime(int ms, final char[] buffer, int pos) {
+ final int hours = ms / 3600000;
+ ms -= 3600000 * hours;
+
+ final int minutes = ms / 60000;
+ ms -= 60000 * minutes;
+
+ final int seconds = ms / 1000;
+ ms -= 1000 * seconds;
+
+ // Hour
+ int temp = hours / 10;
+ buffer[pos++] = ((char) (temp + '0'));
+
+ // Do subtract to get remainder instead of doing % 10
+ buffer[pos++] = ((char) (hours - 10 * temp + '0'));
+ buffer[pos] = timeSeparatorChar;
+ pos += timeSeparatorLength;
+
+ // Minute
+ temp = minutes / 10;
+ buffer[pos++] = ((char) (temp + '0'));
+
+ // Do subtract to get remainder instead of doing % 10
+ buffer[pos++] = ((char) (minutes - 10 * temp + '0'));
+ buffer[pos] = timeSeparatorChar;
+ pos += timeSeparatorLength;
+
+ // Second
+ temp = seconds / 10;
+ buffer[pos++] = ((char) (temp + '0'));
+ buffer[pos++] = ((char) (seconds - 10 * temp + '0'));
+ buffer[pos] = millisSeparatorChar;
+ pos += millisSeparatorLength;
+
+ // Millisecond
+ temp = ms / 100;
+ buffer[pos++] = ((char) (temp + '0'));
+
+ ms -= 100 * temp;
+ temp = ms / 10;
+ buffer[pos++] = ((char) (temp + '0'));
+
+ ms -= 10 * temp;
+ buffer[pos++] = ((char) (ms + '0'));
+ return pos;
+ }
+}