You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rg...@apache.org on 2015/04/14 03:21:46 UTC
logging-log4j2 git commit: LOG4J2-995 - Move UTF-8 Charset constant
to Constants class
Repository: logging-log4j2
Updated Branches:
refs/heads/master 044470e92 -> 23dee1b89
LOG4J2-995 - Move UTF-8 Charset constant to Constants class
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/23dee1b8
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/23dee1b8
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/23dee1b8
Branch: refs/heads/master
Commit: 23dee1b895a8deaec6dac9067d6e46e3932cd003
Parents: 044470e
Author: Ralph Goers <rg...@nextiva.com>
Authored: Mon Apr 13 18:21:24 2015 -0700
Committer: Ralph Goers <rg...@nextiva.com>
Committed: Mon Apr 13 18:21:24 2015 -0700
----------------------------------------------------------------------
.../core/config/plugins/util/ResolverUtil.java | 4 +-
.../log4j/core/jmx/LoggerContextAdmin.java | 4 +-
.../log4j/core/layout/AbstractStringLayout.java | 4 +-
.../logging/log4j/core/layout/GelfLayout.java | 4 +-
.../logging/log4j/core/layout/HtmlLayout.java | 3 +-
.../logging/log4j/core/layout/JsonLayout.java | 4 +-
.../log4j/core/layout/Rfc5424Layout.java | 5 +-
.../logging/log4j/core/layout/XmlLayout.java | 4 +-
.../log4j/core/net/MimeMessageBuilder.java | 4 +-
.../logging/log4j/core/util/Charsets.java | 101 -------------------
.../logging/log4j/core/util/Constants.java | 8 ++
.../logging/log4j/core/util/FileUtils.java | 2 +-
.../plugins/convert/TypeConvertersTest.java | 8 +-
.../log4j/core/layout/HtmlLayoutTest.java | 4 +-
.../log4j/core/layout/JsonLayoutTest.java | 8 +-
.../log4j/core/layout/PatternLayoutTest.java | 6 +-
.../log4j/core/layout/XmlLayoutTest.java | 6 +-
.../logging/log4j/core/util/CharsetsTest.java | 65 ------------
.../log4j/core/util/StandardCharsetsTest.java | 71 -------------
.../logging/log4j/test/layout/BasicLayout.java | 3 +-
.../log4j/perf/jmh/TimeFormatBenchmark.java | 8 +-
src/changes/changes.xml | 3 +
22 files changed, 50 insertions(+), 279 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/23dee1b8/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtil.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtil.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtil.java
index 5d69704..475ef9c 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtil.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtil.java
@@ -34,7 +34,7 @@ import java.util.jar.JarEntry;
import java.util.jar.JarInputStream;
import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.util.Charsets;
+import org.apache.logging.log4j.core.util.Constants;
import org.apache.logging.log4j.core.util.Loader;
import org.apache.logging.log4j.status.StatusLogger;
import org.osgi.framework.FrameworkUtil;
@@ -230,7 +230,7 @@ public class ResolverUtil {
// if URL-encoded file exists, don't decode it
return urlPath;
}
- urlPath = URLDecoder.decode(urlPath, Charsets.UTF_8.name());
+ urlPath = URLDecoder.decode(urlPath, Constants.UTF_8.name());
return urlPath;
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/23dee1b8/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/LoggerContextAdmin.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/LoggerContextAdmin.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/LoggerContextAdmin.java
index 088008a..bb1cc3b 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/LoggerContextAdmin.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/LoggerContextAdmin.java
@@ -44,8 +44,8 @@ import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.ConfigurationFactory;
import org.apache.logging.log4j.core.config.ConfigurationSource;
import org.apache.logging.log4j.core.util.Assert;
-import org.apache.logging.log4j.core.util.Charsets;
import org.apache.logging.log4j.core.util.Closer;
+import org.apache.logging.log4j.core.util.Constants;
import org.apache.logging.log4j.status.StatusLogger;
import org.apache.logging.log4j.util.Strings;
@@ -148,7 +148,7 @@ public class LoggerContextAdmin extends NotificationBroadcasterSupport implement
@Override
public String getConfigText() throws IOException {
- return getConfigText(Charsets.UTF_8.name());
+ return getConfigText(Constants.UTF_8.name());
}
@Override
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/23dee1b8/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 89d0604..d42301a 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
@@ -19,7 +19,7 @@ package org.apache.logging.log4j.core.layout;
import java.nio.charset.Charset;
import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.util.Charsets;
+import org.apache.logging.log4j.core.util.Constants;
/**
* Abstract base class for Layouts that result in a String.
@@ -40,7 +40,7 @@ public abstract class AbstractStringLayout extends AbstractLayout<String> {
protected AbstractStringLayout(final Charset charset, final byte[] header, final byte[] footer) {
super(header, footer);
- this.charset = charset == null ? Charsets.UTF_8 : charset;
+ this.charset = charset == null ? Constants.UTF_8 : charset;
}
protected byte[] getBytes(String s) {
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/23dee1b8/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 8ead1c7..229e350 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
@@ -36,7 +36,7 @@ import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
import org.apache.logging.log4j.core.config.plugins.PluginElement;
import org.apache.logging.log4j.core.config.plugins.PluginFactory;
import org.apache.logging.log4j.core.net.Severity;
-import org.apache.logging.log4j.core.util.Charsets;
+import org.apache.logging.log4j.core.util.Constants;
import org.apache.logging.log4j.core.util.KeyValuePair;
import org.apache.logging.log4j.status.StatusLogger;
@@ -145,7 +145,7 @@ public final class GelfLayout extends AbstractStringLayout {
public GelfLayout(final String host, final KeyValuePair[] additionalFields, final CompressionType compressionType,
final int compressionThreshold) {
- super(Charsets.UTF_8);
+ super(Constants.UTF_8);
this.host = host;
this.additionalFields = additionalFields;
this.compressionType = compressionType;
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/23dee1b8/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/HtmlLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/HtmlLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/HtmlLayout.java
index d899ee3..d4e87d4 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/HtmlLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/HtmlLayout.java
@@ -34,7 +34,6 @@ import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute;
import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
import org.apache.logging.log4j.core.config.plugins.PluginFactory;
-import org.apache.logging.log4j.core.util.Charsets;
import org.apache.logging.log4j.core.util.Constants;
import org.apache.logging.log4j.core.util.Transform;
@@ -357,7 +356,7 @@ public final class HtmlLayout extends AbstractStringLayout {
private String contentType = null; // defer default value in order to use specified charset
@PluginBuilderAttribute
- private Charset charset = Charsets.UTF_8;
+ private Charset charset = Constants.UTF_8;
@PluginBuilderAttribute
private FontSize fontSize = FontSize.SMALL;
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/23dee1b8/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JsonLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JsonLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JsonLayout.java
index be0d96d..4a79cb3 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JsonLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JsonLayout.java
@@ -25,7 +25,7 @@ import org.apache.logging.log4j.core.config.Node;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
import org.apache.logging.log4j.core.config.plugins.PluginFactory;
-import org.apache.logging.log4j.core.util.Charsets;
+import org.apache.logging.log4j.core.util.Constants;
/**
* Appends a series of JSON events as strings serialized as bytes.
@@ -885,6 +885,6 @@ public final class JsonLayout extends AbstractJacksonLayout {
* @return A JSON Layout.
*/
public static AbstractJacksonLayout createDefaultLayout() {
- return new JsonLayout(false, false, false, false, false, Charsets.UTF_8);
+ return new JsonLayout(false, false, false, false, false, Constants.UTF_8);
}
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/23dee1b8/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/Rfc5424Layout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/Rfc5424Layout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/Rfc5424Layout.java
index 18ea7ae..5d31de9 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/Rfc5424Layout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/Rfc5424Layout.java
@@ -47,13 +47,12 @@ import org.apache.logging.log4j.core.pattern.PatternConverter;
import org.apache.logging.log4j.core.pattern.PatternFormatter;
import org.apache.logging.log4j.core.pattern.PatternParser;
import org.apache.logging.log4j.core.pattern.ThrowablePatternConverter;
-import org.apache.logging.log4j.core.util.Charsets;
+import org.apache.logging.log4j.core.util.Constants;
import org.apache.logging.log4j.core.util.NetUtils;
import org.apache.logging.log4j.core.util.Patterns;
import org.apache.logging.log4j.message.Message;
import org.apache.logging.log4j.message.StructuredDataId;
import org.apache.logging.log4j.message.StructuredDataMessage;
-import org.apache.logging.log4j.util.Chars;
import org.apache.logging.log4j.util.StringBuilders;
import org.apache.logging.log4j.util.Strings;
@@ -647,7 +646,7 @@ public final class Rfc5424Layout extends AbstractStringLayout {
@PluginAttribute(value = "useTlsMessageFormat", defaultBoolean = false) final boolean useTlsMessageFormat, // RFC 5425
@PluginElement("LoggerFields") final LoggerFields[] loggerFields,
@PluginConfiguration final Configuration config) {
- final Charset charset = Charsets.UTF_8;
+ final Charset charset = Constants.UTF_8;
if (includes != null && excludes != null) {
LOGGER.error("mdcIncludes and mdcExcludes are mutually exclusive. Includes wil be ignored");
includes = null;
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/23dee1b8/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/XmlLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/XmlLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/XmlLayout.java
index e0c64a4..b3afe38 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/XmlLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/XmlLayout.java
@@ -26,7 +26,7 @@ import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
import org.apache.logging.log4j.core.config.plugins.PluginFactory;
import org.apache.logging.log4j.core.jackson.XmlConstants;
-import org.apache.logging.log4j.core.util.Charsets;
+import org.apache.logging.log4j.core.util.Constants;
/**
* Appends a series of {@code event} elements as defined in the <a href="log4j.dtd">log4j.dtd</a>.
@@ -292,6 +292,6 @@ public final class XmlLayout extends AbstractJacksonLayout {
* @return an XML Layout.
*/
public static XmlLayout createDefaultLayout() {
- return new XmlLayout(false, false, false, false, Charsets.UTF_8);
+ return new XmlLayout(false, false, false, false, Constants.UTF_8);
}
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/23dee1b8/log4j-core/src/main/java/org/apache/logging/log4j/core/net/MimeMessageBuilder.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/MimeMessageBuilder.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/MimeMessageBuilder.java
index 36ca2d7..4700728 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/MimeMessageBuilder.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/MimeMessageBuilder.java
@@ -23,7 +23,7 @@ import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
-import org.apache.logging.log4j.core.util.Charsets;
+import org.apache.logging.log4j.core.util.Constants;
/**
* Helper class for SmtpManager.
@@ -71,7 +71,7 @@ public class MimeMessageBuilder {
public MimeMessageBuilder setSubject(final String subject) throws MessagingException {
if (subject != null) {
- message.setSubject(subject, Charsets.UTF_8.name());
+ message.setSubject(subject, Constants.UTF_8.name());
}
return this;
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/23dee1b8/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Charsets.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Charsets.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Charsets.java
deleted file mode 100644
index 2ad66b3..0000000
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Charsets.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * 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;
-
-import java.nio.charset.Charset;
-
-import org.apache.logging.log4j.status.StatusLogger;
-
-/**
- * Charset utilities. Contains the standard character sets guaranteed to be available on all implementations of the
- * Java platform. Parts adapted from JDK 1.7 (in particular, the {@code java.nio.charset.StandardCharsets} class).
- *
- * @see java.nio.charset.Charset
- */
-public final class Charsets {
-
- /**
- * Seven-bit ASCII. ISO646-US. The Basic Latin block of the Unicode character set.
- */
- public static final Charset US_ASCII = Charset.forName("US-ASCII");
-
- /**
- * ISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1.
- */
- public static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1");
-
- /**
- * Eight-bit UCS Transformation Format.
- */
- public static final Charset UTF_8 = Charset.forName("UTF-8");
-
- /**
- * Sixteen-bit UCS Transformation Format, big-endian byte order.
- */
- public static final Charset UTF_16BE = Charset.forName("UTF-16BE");
-
- /**
- * Sixteen-bit UCS Transformation Format, little-endian byte order.
- */
- public static final Charset UTF_16LE = Charset.forName("UTF-16LE");
-
- /**
- * Sixteen-bit UCS Transformation Format, byte order identified by an optional byte-order mark.
- */
- public static final Charset UTF_16 = Charset.forName("UTF-16");
-
- /**
- * Returns a Charset, if possible the Charset for the specified {@code charsetName}, otherwise (if the specified
- * {@code charsetName} is {@code null} or not supported) this method returns the platform default Charset.
- *
- * @param charsetName
- * name of the preferred charset or {@code null}
- * @return a Charset, not null.
- */
- public static Charset getSupportedCharset(final String charsetName) {
- return getSupportedCharset(charsetName, Charset.defaultCharset());
- }
-
- /**
- * Returns a Charset, if possible the Charset for the specified {@code charsetName}, otherwise (if the specified
- * {@code charsetName} is {@code null} or not supported) this method returns the platform default Charset.
- *
- * @param charsetName
- * name of the preferred charset or {@code null}
- * @param defaultCharset
- * returned if {@code charsetName} is null or is not supported.
- * @return a Charset, never null.
- */
- public static Charset getSupportedCharset(final String charsetName, final Charset defaultCharset) {
- Charset charset = null;
- if (charsetName != null && Charset.isSupported(charsetName)) {
- charset = Charset.forName(charsetName);
- }
- if (charset == null) {
- charset = defaultCharset;
- if (charsetName != null) {
- StatusLogger.getLogger().error(
- "Charset " + charsetName + " is not supported for layout, using " + charset.displayName());
- }
- }
- return charset;
- }
-
- private Charsets() {
- }
-
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/23dee1b8/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java
index 20e47b6..562adfe 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java
@@ -18,6 +18,8 @@ package org.apache.logging.log4j.core.util;
import org.apache.logging.log4j.util.PropertiesUtil;
+import java.nio.charset.Charset;
+
/**
* Log4j Constants.
*/
@@ -49,6 +51,12 @@ public final class Constants {
* Number of milliseconds in a second.
*/
public static final int MILLIS_IN_SECONDS = 1000;
+
+ /**
+ * Equivalent to StandardCharsets.UTF_8.
+ * @ToDo - Initialize with StandardCharsets.UTF_8 when Java 7 is the minimum version.
+ */
+ public static final Charset UTF_8 = Charset.forName("UTF-8");
/**
* Prevent class instantiation.
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/23dee1b8/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 eec1fa9..b5a3af0 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
@@ -65,7 +65,7 @@ public final class FileUtils {
return null;
}
}
- final String charsetName = Charsets.UTF_8.name();
+ final String charsetName = Constants.UTF_8.name();
try {
final String fileName = uri.toURL().getFile();
if (new File(fileName).exists()) { // LOG4J2-466
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/23dee1b8/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/convert/TypeConvertersTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/convert/TypeConvertersTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/convert/TypeConvertersTest.java
index 39b0dd0..0e3f464 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/convert/TypeConvertersTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/convert/TypeConvertersTest.java
@@ -32,7 +32,7 @@ import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.Filter;
import org.apache.logging.log4j.core.layout.GelfLayout;
import org.apache.logging.log4j.core.net.Facility;
-import org.apache.logging.log4j.core.util.Charsets;
+import org.apache.logging.log4j.core.util.Constants;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -149,10 +149,10 @@ public class TypeConvertersTest {
{ "Base64:cGxlYXN1cmUu", "pleasure.".getBytes("US-ASCII"), null, byte[].class },
// JRE
// JRE Charset
- { "UTF-8", Charsets.UTF_8, null, Charset.class },
+ { "UTF-8", Constants.UTF_8, null, Charset.class },
{ "ASCII", Charset.forName("ASCII"), "UTF-8", Charset.class },
- { "Not a real charset", Charsets.UTF_8, "UTF-8", Charset.class },
- { null, Charsets.UTF_8, "UTF-8", Charset.class },
+ { "Not a real charset", Constants.UTF_8, "UTF-8", Charset.class },
+ { null, Constants.UTF_8, "UTF-8", Charset.class },
{ null, null, null, Charset.class },
// JRE File
{ "c:/temp", new File("c:/temp"), null, File.class },
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/23dee1b8/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/HtmlLayoutTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/HtmlLayoutTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/HtmlLayoutTest.java
index ab34305..f009ba2 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/HtmlLayoutTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/HtmlLayoutTest.java
@@ -27,7 +27,7 @@ import org.apache.logging.log4j.core.BasicConfigurationFactory;
import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.ConfigurationFactory;
-import org.apache.logging.log4j.core.util.Charsets;
+import org.apache.logging.log4j.core.util.Constants;
import org.apache.logging.log4j.test.appender.ListAppender;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -81,7 +81,7 @@ public class HtmlLayoutTest {
@Test
public void testDefaultCharset() {
final HtmlLayout layout = HtmlLayout.createDefaultLayout();
- assertEquals(Charsets.UTF_8, layout.getCharset());
+ assertEquals(Constants.UTF_8, layout.getCharset());
}
/**
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/23dee1b8/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/JsonLayoutTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/JsonLayoutTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/JsonLayoutTest.java
index ecc083b..3eacc13 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/JsonLayoutTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/JsonLayoutTest.java
@@ -33,7 +33,7 @@ import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.ConfigurationFactory;
import org.apache.logging.log4j.core.impl.Log4jLogEvent;
import org.apache.logging.log4j.core.jackson.Log4jJsonObjectMapper;
-import org.apache.logging.log4j.core.util.Charsets;
+import org.apache.logging.log4j.core.util.Constants;
import org.apache.logging.log4j.core.util.Throwables;
import org.apache.logging.log4j.message.SimpleMessage;
import org.apache.logging.log4j.spi.AbstractLogger;
@@ -108,7 +108,7 @@ public class JsonLayoutTest {
throws Exception {
final Log4jLogEvent expected = LogEventFixtures.createLogEvent();
final AbstractJacksonLayout layout = JsonLayout.createLayout(includeSource,
- includeContext, false, compact, eventEol, Charsets.UTF_8);
+ includeContext, false, compact, eventEol, Constants.UTF_8);
final String str = layout.toSerializable(expected);
// System.out.println(str);
final String propSep = this.toPropertySeparator(compact);
@@ -171,7 +171,7 @@ public class JsonLayoutTest {
@Test
public void testDefaultCharset() {
final AbstractJacksonLayout layout = JsonLayout.createDefaultLayout();
- assertEquals(Charsets.UTF_8, layout.getCharset());
+ assertEquals(Constants.UTF_8, layout.getCharset());
}
@Test
@@ -255,7 +255,7 @@ public class JsonLayoutTest {
@Test
public void testLayoutLoggerName() throws Exception {
- final AbstractJacksonLayout layout = JsonLayout.createLayout(false, false, false, true, false, Charsets.UTF_8);
+ final AbstractJacksonLayout layout = JsonLayout.createLayout(false, false, false, true, false, Constants.UTF_8);
final Log4jLogEvent expected = Log4jLogEvent.createEvent("a.B", null, "f.q.c.n", Level.DEBUG,
new SimpleMessage("M"), null, null, null, null, "threadName", null, 1);
final String str = layout.toSerializable(expected);
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/23dee1b8/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java
index 8e4f0b8..d3b1543 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java
@@ -31,7 +31,7 @@ import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.ConfigurationFactory;
import org.apache.logging.log4j.core.impl.Log4jLogEvent;
-import org.apache.logging.log4j.core.util.Charsets;
+import org.apache.logging.log4j.core.util.Constants;
import org.apache.logging.log4j.message.SimpleMessage;
import org.apache.logging.log4j.util.Strings;
import org.junit.After;
@@ -221,7 +221,7 @@ public class PatternLayoutTest {
@Test
public void testUseSpecifiedCharsetIfExists() throws Exception {
final PatternLayout layout = PatternLayout.newBuilder().withPattern("%m")
- .withConfiguration(ctx.getConfiguration()).withCharset(Charsets.UTF_8).build();
- assertEquals(Charsets.UTF_8, layout.getCharset());
+ .withConfiguration(ctx.getConfiguration()).withCharset(Constants.UTF_8).build();
+ assertEquals(Constants.UTF_8, layout.getCharset());
}
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/23dee1b8/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/XmlLayoutTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/XmlLayoutTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/XmlLayoutTest.java
index 08b6739..682d06d 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/XmlLayoutTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/XmlLayoutTest.java
@@ -32,7 +32,7 @@ import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.ConfigurationFactory;
import org.apache.logging.log4j.core.impl.Log4jLogEvent;
import org.apache.logging.log4j.core.jackson.Log4jXmlObjectMapper;
-import org.apache.logging.log4j.core.util.Charsets;
+import org.apache.logging.log4j.core.util.Constants;
import org.apache.logging.log4j.core.util.Throwables;
import org.apache.logging.log4j.message.SimpleMessage;
import org.apache.logging.log4j.spi.AbstractLogger;
@@ -120,7 +120,7 @@ public class XmlLayoutTest {
private void testAllFeatures(final boolean includeSource, final boolean compact, final boolean includeContext) throws IOException,
JsonParseException, JsonMappingException {
final Log4jLogEvent expected = LogEventFixtures.createLogEvent();
- final XmlLayout layout = XmlLayout.createLayout(includeSource, includeContext, false, compact, Charsets.UTF_8);
+ final XmlLayout layout = XmlLayout.createLayout(includeSource, includeContext, false, compact, Constants.UTF_8);
final String str = layout.toSerializable(expected);
// System.out.println(str);
assertEquals(str, !compact, str.contains("\n"));
@@ -193,7 +193,7 @@ public class XmlLayoutTest {
@Test
public void testDefaultCharset() {
final XmlLayout layout = XmlLayout.createDefaultLayout();
- assertEquals(Charsets.UTF_8, layout.getCharset());
+ assertEquals(Constants.UTF_8, layout.getCharset());
}
/**
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/23dee1b8/log4j-core/src/test/java/org/apache/logging/log4j/core/util/CharsetsTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/util/CharsetsTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/util/CharsetsTest.java
deleted file mode 100644
index 4500191..0000000
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/util/CharsetsTest.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * 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;
-
-import java.nio.charset.Charset;
-import java.nio.charset.IllegalCharsetNameException;
-
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-public class CharsetsTest {
-
- @Test
- public void testReturnDefaultIfNameIsNull() {
- final Charset actual = Charsets.getSupportedCharset(null);
- assertSame(Charset.defaultCharset(), actual);
- }
-
- @Test
- public void testReturnDefaultIfNameIsUnsupported() {
- final Charset actual = Charsets.getSupportedCharset("INeedMoreSupport");
- assertSame(Charset.defaultCharset(), actual);
- }
-
- @Test(expected = IllegalCharsetNameException.class)
- public void testThrowsExceptionIfNameIsIllegal() {
- final Charset actual = Charsets.getSupportedCharset("spaces not allowed");
- assertSame(Charset.defaultCharset(), actual);
- }
-
- @Test
- public void testReturnRequestedCharsetIfSupported() {
- // See http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html
- // for a list of required charsets.
- final Charset actual1 = Charsets.getSupportedCharset("UTF-8");
- assertSame(Charset.forName("UTF-8"), actual1);
-
- final Charset actual2 = Charsets.getSupportedCharset("ISO-8859-1");
- assertSame(Charset.forName("ISO-8859-1"), actual2);
-
- // This part of the test is NOT portable across all Java platforms.
- // There is no guarantee that KOI8-R is on any given platform
- if (Charset.isSupported("KOI8-R")) {
- final Charset actual3 = Charsets.getSupportedCharset("KOI8-R");
- assertSame(Charset.forName("KOI8-R"), actual3);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/23dee1b8/log4j-core/src/test/java/org/apache/logging/log4j/core/util/StandardCharsetsTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/util/StandardCharsetsTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/util/StandardCharsetsTest.java
deleted file mode 100644
index 4ed3196..0000000
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/util/StandardCharsetsTest.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * 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;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.Charset;
-import java.util.Arrays;
-import java.util.Collection;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
-import static org.junit.Assert.*;
-
-@RunWith(Parameterized.class)
-public class StandardCharsetsTest {
-
- private final String charsetName;
- private final Charset expectedCharset;
-
- public StandardCharsetsTest(final String charsetName, final Charset expectedCharset) {
- this.charsetName = charsetName;
- this.expectedCharset = expectedCharset;
- }
-
- @Parameterized.Parameters
- public static Collection<Object[]> data() {
- return Arrays.asList(
- new Object[][]{
- { "US-ASCII", Charsets.US_ASCII },
- { "ISO-8859-1", Charsets.ISO_8859_1 },
- { "UTF-8", Charsets.UTF_8 },
- { "UTF-16BE", Charsets.UTF_16BE },
- { "UTF-16LE", Charsets.UTF_16LE },
- { "UTF-16", Charsets.UTF_16 }
- }
- );
- }
-
- @Test
- public void testSupportsStandardCharset() throws Exception {
- assertTrue(Charset.isSupported(charsetName));
- assertSame(expectedCharset, Charsets.getSupportedCharset(charsetName));
- }
-
- @Test
- public void testCharsetTranslatesProperly() throws Exception {
- final String expected = "This string contains only ASCII characters to test all the standard charsets";
- final ByteBuffer encoded = expectedCharset.encode(expected);
- final CharBuffer decoded = expectedCharset.decode(encoded);
- final String actual = decoded.toString();
- assertEquals(expected, actual);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/23dee1b8/log4j-core/src/test/java/org/apache/logging/log4j/test/layout/BasicLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/test/layout/BasicLayout.java b/log4j-core/src/test/java/org/apache/logging/log4j/test/layout/BasicLayout.java
index be5ca6e..332c6ae 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/test/layout/BasicLayout.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/test/layout/BasicLayout.java
@@ -22,7 +22,6 @@ import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.config.plugins.PluginFactory;
import org.apache.logging.log4j.core.layout.AbstractStringLayout;
-import org.apache.logging.log4j.core.util.Charsets;
import org.apache.logging.log4j.core.util.Constants;
/**
@@ -51,6 +50,6 @@ public class BasicLayout extends AbstractStringLayout {
*/
@PluginFactory
public static BasicLayout createLayout() {
- return new BasicLayout(Charsets.UTF_8);
+ return new BasicLayout(Constants.UTF_8);
}
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/23dee1b8/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/TimeFormatBenchmark.java
----------------------------------------------------------------------
diff --git a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/TimeFormatBenchmark.java b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/TimeFormatBenchmark.java
index 1d1cb33..4f11705 100644
--- a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/TimeFormatBenchmark.java
+++ b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/TimeFormatBenchmark.java
@@ -23,7 +23,7 @@ import java.util.Calendar;
import java.util.Date;
import java.util.concurrent.TimeUnit;
-import org.apache.logging.log4j.core.util.Charsets;
+import org.apache.logging.log4j.core.util.Constants;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Mode;
@@ -99,7 +99,7 @@ public class TimeFormatBenchmark {
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public int simpleDateFormatBytes(final BufferState state) {
final String str = simpleDateFormat.format(new Date());
- final byte[] bytes = str.getBytes(Charsets.UTF_8);
+ final byte[] bytes = str.getBytes(Constants.UTF_8);
state.buffer.clear();
state.buffer.put(bytes);
return state.buffer.position();
@@ -111,7 +111,7 @@ public class TimeFormatBenchmark {
public String customFastFormatString(final BufferState state) {
state.buffer.clear();
fastFormat(System.currentTimeMillis(), state.buffer);
- return new String(state.buffer.array(), 0, state.buffer.position(), Charsets.UTF_8);
+ return new String(state.buffer.array(), 0, state.buffer.position(), Constants.UTF_8);
}
@Benchmark
@@ -129,7 +129,7 @@ public class TimeFormatBenchmark {
public String customFormatString(final BufferState state) {
state.buffer.clear();
format(System.currentTimeMillis(), state.buffer);
- return new String(state.buffer.array(), 0, state.buffer.position(), Charsets.UTF_8);
+ return new String(state.buffer.array(), 0, state.buffer.position(), Constants.UTF_8);
}
@Benchmark
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/23dee1b8/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 667fd93..aeda6e3 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -24,6 +24,9 @@
</properties>
<body>
<release version="2.3" date="2015-0?-??" description="GA Release 2.3">
+ <action issue="LOG4J2-995" dev="rgoers" type="update">
+ Move UTF-8 constant from Charsets to Constants class. Remove Charsets class.
+ </action>
<action issue="LOG4J2-993" dev="rgoers" type="fix">
Deadlock would occur if appender thread creates a new Logger during reconfiguration.
</action>