This is an automated email from the ASF dual-hosted git repository.
pkarwasz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/main by this push:
new 5bf7f3a8f8 Convert CRLF to LF
5bf7f3a8f8 is described below
commit 5bf7f3a8f8763fa1017bfce14594ee01b9cc68b6
Author: Piotr P. Karwasz <[email protected]>
AuthorDate: Thu Mar 23 09:49:13 2023 +0100
Convert CRLF to LF
---
.../log4j/core/filter/CompositeFilterTest.java | 97 ++++---
.../pattern/SimpleLiteralPatternConverterTest.java | 93 ++++---
.../logging/log4j/core/appender/WriterManager.java | 298 ++++++++++-----------
.../appender/rolling/action/DeletingVisitor.java | 219 ++++++++-------
.../core/appender/rolling/action/PathSorter.java | 53 ++--
.../rolling/action/PathWithAttributes.java | 117 ++++----
.../appender/rolling/action/SortingVisitor.java | 149 +++++------
.../core/async/AsyncLoggerConfigDelegate.java | 131 +++++----
.../async/BasicAsyncLoggerContextSelector.java | 88 +++---
.../log4j/core/config/ReliabilityStrategy.java | 189 +++++++------
.../DefaultComponentAndConfigurationBuilder.java | 94 +++----
.../log4j/core/selector/CoreContextSelectors.java | 62 ++---
.../log4j/core/util/CloseShieldOutputStream.java | 118 ++++----
.../logging/log4j/core/util/CloseShieldWriter.java | 92 +++----
.../apache/logging/log4j/core/util/IOUtils.java | 260 +++++++++---------
15 files changed, 1026 insertions(+), 1034 deletions(-)
diff --git
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/filter/CompositeFilterTest.java
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/filter/CompositeFilterTest.java
index 0a5698b607..14d7f16d76 100644
---
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/filter/CompositeFilterTest.java
+++
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/filter/CompositeFilterTest.java
@@ -1,49 +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.filter;
-
-import static org.junit.jupiter.api.Assertions.assertArrayEquals;
-import static org.junit.jupiter.api.Assertions.assertNotEquals;
-
-import org.apache.logging.log4j.core.Filter;
-import org.apache.logging.log4j.core.Filter.Result;
-import org.junit.jupiter.api.Test;
-
-public class CompositeFilterTest {
-
- @Test
- public void testConcatenation() {
- final Filter a =
DenyAllFilter.newBuilder().setOnMatch(Result.ACCEPT).build();
- final Filter b =
DenyAllFilter.newBuilder().setOnMatch(Result.NEUTRAL).build();
- final Filter c =
DenyAllFilter.newBuilder().setOnMatch(Result.DENY).build();
- // The three values need to be distinguishable
- assertNotEquals(a, b);
- assertNotEquals(a, c);
- assertNotEquals(b, c);
- final Filter[] expected = new Filter[] {a, b, c};
- final CompositeFilter singleA = CompositeFilter.createFilters(new
Filter[] {a});
- final CompositeFilter singleB = CompositeFilter.createFilters(new
Filter[] {b});
- final CompositeFilter singleC = CompositeFilter.createFilters(new
Filter[] {c});
- // Concatenating one at a time
- final CompositeFilter concat1 = singleA.addFilter(b).addFilter(c);
- assertArrayEquals(expected, concat1.getFiltersArray());
- // In reverse order
- final CompositeFilter concat2 =
singleA.addFilter(singleB.addFilter(singleC));
- assertArrayEquals(expected, concat2.getFiltersArray());
- }
-}
+/*
+ * 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.filter;
+
+import org.apache.logging.log4j.core.Filter;
+import org.apache.logging.log4j.core.Filter.Result;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+public class CompositeFilterTest {
+
+ @Test
+ public void testConcatenation() {
+ final Filter a =
DenyAllFilter.newBuilder().setOnMatch(Result.ACCEPT).build();
+ final Filter b =
DenyAllFilter.newBuilder().setOnMatch(Result.NEUTRAL).build();
+ final Filter c =
DenyAllFilter.newBuilder().setOnMatch(Result.DENY).build();
+ // The three values need to be distinguishable
+ assertNotEquals(a, b);
+ assertNotEquals(a, c);
+ assertNotEquals(b, c);
+ final Filter[] expected = new Filter[] {a, b, c};
+ final CompositeFilter singleA = CompositeFilter.createFilters(new
Filter[] {a});
+ final CompositeFilter singleB = CompositeFilter.createFilters(new
Filter[] {b});
+ final CompositeFilter singleC = CompositeFilter.createFilters(new
Filter[] {c});
+ // Concatenating one at a time
+ final CompositeFilter concat1 = singleA.addFilter(b).addFilter(c);
+ assertArrayEquals(expected, concat1.getFiltersArray());
+ // In reverse order
+ final CompositeFilter concat2 =
singleA.addFilter(singleB.addFilter(singleC));
+ assertArrayEquals(expected, concat2.getFiltersArray());
+ }
+}
diff --git
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/SimpleLiteralPatternConverterTest.java
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/SimpleLiteralPatternConverterTest.java
index ba6b402447..4b46e42b32 100644
---
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/SimpleLiteralPatternConverterTest.java
+++
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/SimpleLiteralPatternConverterTest.java
@@ -1,47 +1,46 @@
-/*
- * 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.pattern;
-
-import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-public class SimpleLiteralPatternConverterTest {
-
- @Test
- public void testConvertBackslashes() {
- String literal = "ABC\\tDEF\\nGHI\\rJKL\\'MNO\\f \\b \\\\DROPPED:\\x";
- LogEventPatternConverter converter =
SimpleLiteralPatternConverter.of(literal, true);
- String actual = literal(converter);
- assertEquals("ABC\tDEF\nGHI\rJKL\'MNO\f \b \\DROPPED:x", actual);
- }
-
- @Test
- public void testDontConvertBackslashes() {
- String literal = "ABC\\tDEF\\nGHI\\rJKL\\'MNO\\f \\b \\\\DROPPED:\\x";
- LogEventPatternConverter converter =
SimpleLiteralPatternConverter.of(literal, false);
- String actual = literal(converter);
- assertEquals(literal, actual);
- }
-
- private static String literal(LogEventPatternConverter converter) {
- StringBuilder buffer = new StringBuilder();
- converter.format(null, buffer);
- return buffer.toString();
- }
-}
+/*
+ * 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.pattern;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class SimpleLiteralPatternConverterTest {
+
+ @Test
+ public void testConvertBackslashes() {
+ String literal = "ABC\\tDEF\\nGHI\\rJKL\\'MNO\\f \\b \\\\DROPPED:\\x";
+ LogEventPatternConverter converter =
SimpleLiteralPatternConverter.of(literal, true);
+ String actual = literal(converter);
+ assertEquals("ABC\tDEF\nGHI\rJKL\'MNO\f \b \\DROPPED:x", actual);
+ }
+
+ @Test
+ public void testDontConvertBackslashes() {
+ String literal = "ABC\\tDEF\\nGHI\\rJKL\\'MNO\\f \\b \\\\DROPPED:\\x";
+ LogEventPatternConverter converter =
SimpleLiteralPatternConverter.of(literal, false);
+ String actual = literal(converter);
+ assertEquals(literal, actual);
+ }
+
+ private static String literal(LogEventPatternConverter converter) {
+ StringBuilder buffer = new StringBuilder();
+ converter.format(null, buffer);
+ return buffer.toString();
+ }
+}
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/WriterManager.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/WriterManager.java
index bf76e47b25..32c024fb0f 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/WriterManager.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/WriterManager.java
@@ -1,149 +1,149 @@
-/*
- * 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.appender;
-
-import java.io.IOException;
-import java.io.Writer;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.logging.log4j.core.StringLayout;
-
-/**
- * Manages a Writer so that it can be shared by multiple Appenders and will
- * allow appenders to reconfigure without requiring a new writer.
- */
-public class WriterManager extends AbstractManager {
-
- /**
- * Creates a Manager.
- *
- * @param name The name of the stream to manage.
- * @param data The data to pass to the Manager.
- * @param factory The factory to use to create the Manager.
- * @param <T> The type of the WriterManager.
- * @return A WriterManager.
- */
- public static <T> WriterManager getManager(final String name, final T data,
- final ManagerFactory<?
extends WriterManager, T> factory) {
- return AbstractManager.getManager(name, factory, data);
- }
- protected final StringLayout layout;
-
- private volatile Writer writer;
-
- public WriterManager(final Writer writer, final String streamName, final
StringLayout layout,
- final boolean writeHeader) {
- super(null, streamName);
- this.writer = writer;
- this.layout = layout;
- if (writeHeader && layout != null) {
- final byte[] header = layout.getHeader();
- if (header != null) {
- try {
- this.writer.write(new String(header, layout.getCharset()));
- } catch (final IOException e) {
- logError("Unable to write header", e);
- }
- }
- }
- }
-
- protected synchronized void closeWriter() {
- final Writer w = writer; // access volatile field only once per method
- try {
- w.close();
- } catch (final IOException ex) {
- logError("Unable to close stream", ex);
- }
- }
-
- /**
- * Flushes any buffers.
- */
- public synchronized void flush() {
- try {
- writer.flush();
- } catch (final IOException ex) {
- final String msg = "Error flushing stream " + getName();
- throw new AppenderLoggingException(msg, ex);
- }
- }
-
- protected Writer getWriter() {
- return writer;
- }
-
- /**
- * Returns the status of the stream.
- * @return true if the stream is open, false if it is not.
- */
- public boolean isOpen() {
- return getCount() > 0;
- }
-
- /**
- * Default hook to write footer during close.
- */
- @Override
- public boolean releaseSub(final long timeout, final TimeUnit timeUnit) {
- writeFooter();
- closeWriter();
- return true;
- }
-
- protected void setWriter(final Writer writer) {
- final byte[] header = layout.getHeader();
- if (header != null) {
- try {
- writer.write(new String(header, layout.getCharset()));
- this.writer = writer; // only update field if writer.write()
succeeded
- } catch (final IOException ioe) {
- logError("Unable to write header", ioe);
- }
- } else {
- this.writer = writer;
- }
- }
-
- /**
- * Some output streams synchronize writes while others do not.
Synchronizing here insures that
- * log events won't be intertwined.
- * @param str the string to write
- * @throws AppenderLoggingException if an error occurs.
- */
- protected synchronized void write(final String str) {
- try {
- writer.write(str);
- } catch (final IOException ex) {
- final String msg = "Error writing to stream " + getName();
- throw new AppenderLoggingException(msg, ex);
- }
- }
-
- /**
- * Writes the footer.
- */
- protected void writeFooter() {
- if (layout == null) {
- return;
- }
- final byte[] footer = layout.getFooter();
- if (footer != null && footer.length > 0) {
- write(new String(footer, layout.getCharset()));
- }
- }
-}
+/*
+ * 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.appender;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.logging.log4j.core.StringLayout;
+
+/**
+ * Manages a Writer so that it can be shared by multiple Appenders and will
+ * allow appenders to reconfigure without requiring a new writer.
+ */
+public class WriterManager extends AbstractManager {
+
+ /**
+ * Creates a Manager.
+ *
+ * @param name The name of the stream to manage.
+ * @param data The data to pass to the Manager.
+ * @param factory The factory to use to create the Manager.
+ * @param <T> The type of the WriterManager.
+ * @return A WriterManager.
+ */
+ public static <T> WriterManager getManager(final String name, final T data,
+ final ManagerFactory<?
extends WriterManager, T> factory) {
+ return AbstractManager.getManager(name, factory, data);
+ }
+ protected final StringLayout layout;
+
+ private volatile Writer writer;
+
+ public WriterManager(final Writer writer, final String streamName, final
StringLayout layout,
+ final boolean writeHeader) {
+ super(null, streamName);
+ this.writer = writer;
+ this.layout = layout;
+ if (writeHeader && layout != null) {
+ final byte[] header = layout.getHeader();
+ if (header != null) {
+ try {
+ this.writer.write(new String(header, layout.getCharset()));
+ } catch (final IOException e) {
+ logError("Unable to write header", e);
+ }
+ }
+ }
+ }
+
+ protected synchronized void closeWriter() {
+ final Writer w = writer; // access volatile field only once per method
+ try {
+ w.close();
+ } catch (final IOException ex) {
+ logError("Unable to close stream", ex);
+ }
+ }
+
+ /**
+ * Flushes any buffers.
+ */
+ public synchronized void flush() {
+ try {
+ writer.flush();
+ } catch (final IOException ex) {
+ final String msg = "Error flushing stream " + getName();
+ throw new AppenderLoggingException(msg, ex);
+ }
+ }
+
+ protected Writer getWriter() {
+ return writer;
+ }
+
+ /**
+ * Returns the status of the stream.
+ * @return true if the stream is open, false if it is not.
+ */
+ public boolean isOpen() {
+ return getCount() > 0;
+ }
+
+ /**
+ * Default hook to write footer during close.
+ */
+ @Override
+ public boolean releaseSub(final long timeout, final TimeUnit timeUnit) {
+ writeFooter();
+ closeWriter();
+ return true;
+ }
+
+ protected void setWriter(final Writer writer) {
+ final byte[] header = layout.getHeader();
+ if (header != null) {
+ try {
+ writer.write(new String(header, layout.getCharset()));
+ this.writer = writer; // only update field if writer.write()
succeeded
+ } catch (final IOException ioe) {
+ logError("Unable to write header", ioe);
+ }
+ } else {
+ this.writer = writer;
+ }
+ }
+
+ /**
+ * Some output streams synchronize writes while others do not.
Synchronizing here insures that
+ * log events won't be intertwined.
+ * @param str the string to write
+ * @throws AppenderLoggingException if an error occurs.
+ */
+ protected synchronized void write(final String str) {
+ try {
+ writer.write(str);
+ } catch (final IOException ex) {
+ final String msg = "Error writing to stream " + getName();
+ throw new AppenderLoggingException(msg, ex);
+ }
+ }
+
+ /**
+ * Writes the footer.
+ */
+ protected void writeFooter() {
+ if (layout == null) {
+ return;
+ }
+ final byte[] footer = layout.getFooter();
+ if (footer != null && footer.length > 0) {
+ write(new String(footer, layout.getCharset()));
+ }
+ }
+}
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/DeletingVisitor.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/DeletingVisitor.java
index 69a59a7d8c..e433731cf2 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/DeletingVisitor.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/DeletingVisitor.java
@@ -1,110 +1,109 @@
-/*
- * 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.appender.rolling.action;
-
-import java.io.IOException;
-import java.nio.file.FileVisitResult;
-import java.nio.file.Files;
-import java.nio.file.NoSuchFileException;
-import java.nio.file.Path;
-import java.nio.file.SimpleFileVisitor;
-import java.nio.file.attribute.BasicFileAttributes;
-import java.util.List;
-import java.util.Objects;
-
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.status.StatusLogger;
-
-/**
- * FileVisitor that deletes files that are accepted by all PathFilters.
Directories are ignored.
- */
-public class DeletingVisitor extends SimpleFileVisitor<Path> {
- private static final Logger LOGGER = StatusLogger.getLogger();
-
- private final Path basePath;
- private final boolean testMode;
- private final List<? extends PathCondition> pathConditions;
-
- /**
- * Constructs a new DeletingVisitor.
- *
- * @param basePath used to relativize paths
- * @param pathConditions objects that need to confirm whether a file can
be deleted
- * @param testMode if true, files are not deleted but instead a message is
printed to the <a
- *
href="http://logging.apache.org/log4j/2.x/manual/configuration.html#StatusMessages">status
logger</a>
- * at INFO level. Users can use this to do a dry run to test if
their configuration works as expected.
- */
- public DeletingVisitor(final Path basePath, final List<? extends
PathCondition> pathConditions,
- final boolean testMode) {
- this.testMode = testMode;
- this.basePath = Objects.requireNonNull(basePath, "basePath");
- this.pathConditions = Objects.requireNonNull(pathConditions,
"pathConditions");
- for (final PathCondition condition : pathConditions) {
- condition.beforeFileTreeWalk();
- }
- }
-
- @Override
- public FileVisitResult visitFile(final Path file, final
BasicFileAttributes attrs) throws IOException {
- for (final PathCondition pathFilter : pathConditions) {
- final Path relative = basePath.relativize(file);
- if (!pathFilter.accept(basePath, relative, attrs)) {
- LOGGER.trace("Not deleting base={}, relative={}", basePath,
relative);
- return FileVisitResult.CONTINUE;
- }
- }
- if (isTestMode()) {
- LOGGER.info("Deleting {} (TEST MODE: file not actually deleted)",
file);
- } else {
- delete(file);
- }
- return FileVisitResult.CONTINUE;
- }
-
- @Override
- public FileVisitResult visitFileFailed(final Path file, final IOException
ioException) throws IOException {
- // LOG4J2-2677: Appenders may rollover and purge in parallel.
SimpleVisitor rethrows exceptions from
- // failed attempts to load file attributes.
- if (ioException instanceof NoSuchFileException) {
- LOGGER.info("File {} could not be accessed, it has likely already
been deleted", file, ioException);
- return FileVisitResult.CONTINUE;
- } else {
- return super.visitFileFailed(file, ioException);
- }
- }
-
- /**
- * Deletes the specified file.
- *
- * @param file the file to delete
- * @throws IOException if a problem occurred deleting the file
- */
- protected void delete(final Path file) throws IOException {
- LOGGER.trace("Deleting {}", file);
- Files.deleteIfExists(file);
- }
-
- /**
- * Returns {@code true} if files are not deleted even when all conditions
accept a path, {@code false} otherwise.
- *
- * @return {@code true} if files are not deleted even when all conditions
accept a path, {@code false} otherwise
- */
- public boolean isTestMode() {
- return testMode;
- }
-}
+/*
+ * 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.appender.rolling.action;
+
+import java.io.IOException;
+import java.nio.file.FileVisitResult;
+import java.nio.file.Files;
+import java.nio.file.NoSuchFileException;
+import java.nio.file.Path;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.util.List;
+import java.util.Objects;
+
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.status.StatusLogger;
+
+/**
+ * FileVisitor that deletes files that are accepted by all PathFilters.
Directories are ignored.
+ */
+public class DeletingVisitor extends SimpleFileVisitor<Path> {
+ private static final Logger LOGGER = StatusLogger.getLogger();
+
+ private final Path basePath;
+ private final boolean testMode;
+ private final List<? extends PathCondition> pathConditions;
+
+ /**
+ * Constructs a new DeletingVisitor.
+ *
+ * @param basePath used to relativize paths
+ * @param pathConditions objects that need to confirm whether a file can
be deleted
+ * @param testMode if true, files are not deleted but instead a message is
printed to the <a
+ *
href="http://logging.apache.org/log4j/2.x/manual/configuration.html#StatusMessages">status
logger</a>
+ * at INFO level. Users can use this to do a dry run to test if
their configuration works as expected.
+ */
+ public DeletingVisitor(final Path basePath, final List<? extends
PathCondition> pathConditions,
+ final boolean testMode) {
+ this.testMode = testMode;
+ this.basePath = Objects.requireNonNull(basePath, "basePath");
+ this.pathConditions = Objects.requireNonNull(pathConditions,
"pathConditions");
+ for (final PathCondition condition : pathConditions) {
+ condition.beforeFileTreeWalk();
+ }
+ }
+
+ @Override
+ public FileVisitResult visitFile(final Path file, final
BasicFileAttributes attrs) throws IOException {
+ for (final PathCondition pathFilter : pathConditions) {
+ final Path relative = basePath.relativize(file);
+ if (!pathFilter.accept(basePath, relative, attrs)) {
+ LOGGER.trace("Not deleting base={}, relative={}", basePath,
relative);
+ return FileVisitResult.CONTINUE;
+ }
+ }
+ if (isTestMode()) {
+ LOGGER.info("Deleting {} (TEST MODE: file not actually deleted)",
file);
+ } else {
+ delete(file);
+ }
+ return FileVisitResult.CONTINUE;
+ }
+
+ @Override
+ public FileVisitResult visitFileFailed(final Path file, final IOException
ioException) throws IOException {
+ // LOG4J2-2677: Appenders may rollover and purge in parallel.
SimpleVisitor rethrows exceptions from
+ // failed attempts to load file attributes.
+ if (ioException instanceof NoSuchFileException) {
+ LOGGER.info("File {} could not be accessed, it has likely already
been deleted", file, ioException);
+ return FileVisitResult.CONTINUE;
+ } else {
+ return super.visitFileFailed(file, ioException);
+ }
+ }
+
+ /**
+ * Deletes the specified file.
+ *
+ * @param file the file to delete
+ * @throws IOException if a problem occurred deleting the file
+ */
+ protected void delete(final Path file) throws IOException {
+ LOGGER.trace("Deleting {}", file);
+ Files.deleteIfExists(file);
+ }
+
+ /**
+ * Returns {@code true} if files are not deleted even when all conditions
accept a path, {@code false} otherwise.
+ *
+ * @return {@code true} if files are not deleted even when all conditions
accept a path, {@code false} otherwise
+ */
+ public boolean isTestMode() {
+ return testMode;
+ }
+}
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/PathSorter.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/PathSorter.java
index 2e765ab0b8..d8ea3c2d22 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/PathSorter.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/PathSorter.java
@@ -1,27 +1,26 @@
-/*
- * 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.appender.rolling.action;
-
-import java.util.Comparator;
-
-/**
- * Defines the interface of classes that can sort Paths.
- */
-public interface PathSorter extends Comparator<PathWithAttributes>{
-
-}
+/*
+ * 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.appender.rolling.action;
+
+import java.util.Comparator;
+
+/**
+ * Defines the interface of classes that can sort Paths.
+ */
+public interface PathSorter extends Comparator<PathWithAttributes>{
+
+}
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/PathWithAttributes.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/PathWithAttributes.java
index d69835427b..674e784269 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/PathWithAttributes.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/PathWithAttributes.java
@@ -1,59 +1,58 @@
-/*
- * 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.appender.rolling.action;
-
-import java.nio.file.Path;
-import java.nio.file.attribute.BasicFileAttributes;
-import java.util.Objects;
-
-/**
- * Tuple of a {@code Path} and {@code BasicFileAttributes}, used for sorting.
- */
-public class PathWithAttributes {
-
- private final Path path;
- private final BasicFileAttributes attributes;
-
- public PathWithAttributes(final Path path, final BasicFileAttributes
attributes) {
- this.path = Objects.requireNonNull(path, "path");
- this.attributes = Objects.requireNonNull(attributes, "attributes");
- }
-
- @Override
- public String toString() {
- return path + " (modified: " + attributes.lastModifiedTime() + ")";
- }
-
- /**
- * Returns the path.
- *
- * @return the path
- */
- public Path getPath() {
- return path;
- }
-
- /**
- * Returns the attributes.
- *
- * @return the attributes
- */
- public BasicFileAttributes getAttributes() {
- return attributes;
- }
-}
+/*
+ * 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.appender.rolling.action;
+
+import java.nio.file.Path;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.util.Objects;
+
+/**
+ * Tuple of a {@code Path} and {@code BasicFileAttributes}, used for sorting.
+ */
+public class PathWithAttributes {
+
+ private final Path path;
+ private final BasicFileAttributes attributes;
+
+ public PathWithAttributes(final Path path, final BasicFileAttributes
attributes) {
+ this.path = Objects.requireNonNull(path, "path");
+ this.attributes = Objects.requireNonNull(attributes, "attributes");
+ }
+
+ @Override
+ public String toString() {
+ return path + " (modified: " + attributes.lastModifiedTime() + ")";
+ }
+
+ /**
+ * Returns the path.
+ *
+ * @return the path
+ */
+ public Path getPath() {
+ return path;
+ }
+
+ /**
+ * Returns the attributes.
+ *
+ * @return the attributes
+ */
+ public BasicFileAttributes getAttributes() {
+ return attributes;
+ }
+}
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/SortingVisitor.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/SortingVisitor.java
index ba7e00b601..c7ba94ec61 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/SortingVisitor.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/SortingVisitor.java
@@ -1,75 +1,74 @@
-/*
- * 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.appender.rolling.action;
-
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.status.StatusLogger;
-
-import java.io.IOException;
-import java.nio.file.FileVisitResult;
-import java.nio.file.NoSuchFileException;
-import java.nio.file.Path;
-import java.nio.file.SimpleFileVisitor;
-import java.nio.file.attribute.BasicFileAttributes;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Objects;
-
-/**
- * FileVisitor that sorts files.
- */
-public class SortingVisitor extends SimpleFileVisitor<Path> {
-
- private static final Logger LOGGER = StatusLogger.getLogger();
- private final PathSorter sorter;
- private final List<PathWithAttributes> collected = new ArrayList<>();
-
- /**
- * Constructs a new DeletingVisitor.
- *
- * @param basePath used to relativize paths
- * @param pathFilters objects that need to confirm whether a file can be
deleted
- */
- public SortingVisitor(final PathSorter sorter) {
- this.sorter = Objects.requireNonNull(sorter, "sorter");
- }
-
- @Override
- public FileVisitResult visitFile(final Path path, final
BasicFileAttributes attrs) throws IOException {
- collected.add(new PathWithAttributes(path, attrs));
- return FileVisitResult.CONTINUE;
- }
-
- @Override
- public FileVisitResult visitFileFailed(final Path file, final IOException
ioException) throws IOException {
- // LOG4J2-2677: Appenders may rollover and purge in parallel.
SimpleVisitor rethrows exceptions from
- // failed attempts to load file attributes.
- if (ioException instanceof NoSuchFileException) {
- LOGGER.info("File {} could not be accessed, it has likely already
been deleted", file, ioException);
- return FileVisitResult.CONTINUE;
- } else {
- return super.visitFileFailed(file, ioException);
- }
- }
-
- public List<PathWithAttributes> getSortedPaths() {
- Collections.sort(collected, sorter);
- return collected;
- }
-}
+/*
+ * 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.appender.rolling.action;
+
+import java.io.IOException;
+import java.nio.file.FileVisitResult;
+import java.nio.file.NoSuchFileException;
+import java.nio.file.Path;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.status.StatusLogger;
+
+/**
+ * FileVisitor that sorts files.
+ */
+public class SortingVisitor extends SimpleFileVisitor<Path> {
+
+ private static final Logger LOGGER = StatusLogger.getLogger();
+ private final PathSorter sorter;
+ private final List<PathWithAttributes> collected = new ArrayList<>();
+
+ /**
+ * Constructs a new DeletingVisitor.
+ *
+ * @param basePath used to relativize paths
+ * @param pathFilters objects that need to confirm whether a file can be
deleted
+ */
+ public SortingVisitor(final PathSorter sorter) {
+ this.sorter = Objects.requireNonNull(sorter, "sorter");
+ }
+
+ @Override
+ public FileVisitResult visitFile(final Path path, final
BasicFileAttributes attrs) throws IOException {
+ collected.add(new PathWithAttributes(path, attrs));
+ return FileVisitResult.CONTINUE;
+ }
+
+ @Override
+ public FileVisitResult visitFileFailed(final Path file, final IOException
ioException) throws IOException {
+ // LOG4J2-2677: Appenders may rollover and purge in parallel.
SimpleVisitor rethrows exceptions from
+ // failed attempts to load file attributes.
+ if (ioException instanceof NoSuchFileException) {
+ LOGGER.info("File {} could not be accessed, it has likely already
been deleted", file, ioException);
+ return FileVisitResult.CONTINUE;
+ } else {
+ return super.visitFileFailed(file, ioException);
+ }
+ }
+
+ public List<PathWithAttributes> getSortedPaths() {
+ Collections.sort(collected, sorter);
+ return collected;
+ }
+}
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDelegate.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDelegate.java
index b791f0afe4..1cf0c8e66f 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDelegate.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDelegate.java
@@ -1,66 +1,65 @@
-/*
- * 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.async;
-
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.impl.LogEventFactory;
-import org.apache.logging.log4j.core.jmx.RingBufferAdmin;
-
-/**
- * Encapsulates the mechanism used to log asynchronously. There is one
delegate per configuration, which is shared by
- * all AsyncLoggerConfig objects in the configuration.
- */
-public interface AsyncLoggerConfigDelegate {
-
- /**
- * Creates and returns a new {@code RingBufferAdmin} that instruments the
ringbuffer of this
- * {@code AsyncLoggerConfig}.
- *
- * @param contextName name of the {@code LoggerContext}
- * @param loggerConfigName name of the logger config
- * @return the RingBufferAdmin that instruments the ringbuffer
- */
- RingBufferAdmin createRingBufferAdmin(final String contextName, final
String loggerConfigName);
-
- /**
- * Returns the {@code EventRoute} for the event with the specified level.
- *
- * @param level the level of the event to log
- * @return the {@code EventRoute}
- */
- EventRoute getEventRoute(final Level level);
-
- /**
- * Enqueues the {@link LogEvent} on the mixed configuration ringbuffer.
- * This method must only be used after {@link #tryEnqueue(LogEvent,
AsyncLoggerConfig)} returns <code>false</code>
- * indicating that the ringbuffer is full, otherwise it may incur
unnecessary synchronization.
- */
- void enqueueEvent(LogEvent event, AsyncLoggerConfig asyncLoggerConfig);
-
- boolean tryEnqueue(LogEvent event, AsyncLoggerConfig asyncLoggerConfig);
-
- /**
- * Notifies the delegate what LogEventFactory an AsyncLoggerConfig is
using, so the delegate can determine
- * whether to populate the ring buffer with mutable log events or not.
This method may be invoked multiple times
- * for all AsyncLoggerConfigs that use this delegate.
- *
- * @param logEventFactory the factory used
- */
- void setLogEventFactory(LogEventFactory logEventFactory);
-}
+/*
+ * 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.async;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.impl.LogEventFactory;
+import org.apache.logging.log4j.core.jmx.RingBufferAdmin;
+
+/**
+ * Encapsulates the mechanism used to log asynchronously. There is one
delegate per configuration, which is shared by
+ * all AsyncLoggerConfig objects in the configuration.
+ */
+public interface AsyncLoggerConfigDelegate {
+
+ /**
+ * Creates and returns a new {@code RingBufferAdmin} that instruments the
ringbuffer of this
+ * {@code AsyncLoggerConfig}.
+ *
+ * @param contextName name of the {@code LoggerContext}
+ * @param loggerConfigName name of the logger config
+ * @return the RingBufferAdmin that instruments the ringbuffer
+ */
+ RingBufferAdmin createRingBufferAdmin(final String contextName, final
String loggerConfigName);
+
+ /**
+ * Returns the {@code EventRoute} for the event with the specified level.
+ *
+ * @param level the level of the event to log
+ * @return the {@code EventRoute}
+ */
+ EventRoute getEventRoute(final Level level);
+
+ /**
+ * Enqueues the {@link LogEvent} on the mixed configuration ringbuffer.
+ * This method must only be used after {@link #tryEnqueue(LogEvent,
AsyncLoggerConfig)} returns <code>false</code>
+ * indicating that the ringbuffer is full, otherwise it may incur
unnecessary synchronization.
+ */
+ void enqueueEvent(LogEvent event, AsyncLoggerConfig asyncLoggerConfig);
+
+ boolean tryEnqueue(LogEvent event, AsyncLoggerConfig asyncLoggerConfig);
+
+ /**
+ * Notifies the delegate what LogEventFactory an AsyncLoggerConfig is
using, so the delegate can determine
+ * whether to populate the ring buffer with mutable log events or not.
This method may be invoked multiple times
+ * for all AsyncLoggerConfigs that use this delegate.
+ *
+ * @param logEventFactory the factory used
+ */
+ void setLogEventFactory(LogEventFactory logEventFactory);
+}
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/BasicAsyncLoggerContextSelector.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/BasicAsyncLoggerContextSelector.java
index 9658f0302f..70f90ca3b6 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/BasicAsyncLoggerContextSelector.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/BasicAsyncLoggerContextSelector.java
@@ -1,44 +1,44 @@
-/*
- * 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.async;
-
-import java.net.URI;
-
-import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.selector.BasicContextSelector;
-import org.apache.logging.log4j.plugins.Inject;
-import org.apache.logging.log4j.plugins.Singleton;
-import org.apache.logging.log4j.plugins.di.Injector;
-
-/**
- * Returns either this Thread's context or the default {@link
AsyncLoggerContext}.
- * Single-application instances should prefer this implementation over the
{@link AsyncLoggerContextSelector}
- * due to the reduced overhead avoiding classloader lookups.
- */
-@Singleton
-public class BasicAsyncLoggerContextSelector extends BasicContextSelector {
-
- @Inject
- public BasicAsyncLoggerContextSelector(Injector injector) {
- super(injector);
- }
-
- @Override
- protected LoggerContext createContext() {
- return new AsyncLoggerContext("AsyncDefault", null, (URI) null,
injector);
- }
-}
+/*
+ * 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.async;
+
+import java.net.URI;
+
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.selector.BasicContextSelector;
+import org.apache.logging.log4j.plugins.Inject;
+import org.apache.logging.log4j.plugins.Singleton;
+import org.apache.logging.log4j.plugins.di.Injector;
+
+/**
+ * Returns either this Thread's context or the default {@link
AsyncLoggerContext}.
+ * Single-application instances should prefer this implementation over the
{@link AsyncLoggerContextSelector}
+ * due to the reduced overhead avoiding classloader lookups.
+ */
+@Singleton
+public class BasicAsyncLoggerContextSelector extends BasicContextSelector {
+
+ @Inject
+ public BasicAsyncLoggerContextSelector(Injector injector) {
+ super(injector);
+ }
+
+ @Override
+ protected LoggerContext createContext() {
+ return new AsyncLoggerContext("AsyncDefault", null, (URI) null,
injector);
+ }
+}
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ReliabilityStrategy.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ReliabilityStrategy.java
index 1ccb74a6b1..b469a73b1d 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ReliabilityStrategy.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ReliabilityStrategy.java
@@ -1,95 +1,94 @@
-/*
- * 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.config;
-
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.Marker;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.message.Message;
-import org.apache.logging.log4j.util.Supplier;
-
-/**
- * Interface for objects that know how to ensure delivery of log events to the
appropriate appenders, even during and
- * after the configuration has been modified while the system is actively used.
- */
-public interface ReliabilityStrategy {
-
- /**
- * Logs an event.
- *
- * @param reconfigured supplies the next LoggerConfig if the strategy's
LoggerConfig is no longer active
- * @param loggerName The name of the Logger.
- * @param fqcn The fully qualified class name of the caller.
- * @param marker A Marker or null if none is present.
- * @param level The event Level.
- * @param data The Message.
- * @param t A Throwable or null.
- */
- void log(Supplier<LoggerConfig> reconfigured, String loggerName, String
fqcn, Marker marker, Level level,
- Message data, Throwable t);
- /**
- * Logs an event.
- *
- * @param reconfigured supplies the next LoggerConfig if the strategy's
LoggerConfig is no longer active
- * @param loggerName The name of the Logger.
- * @param fqcn The fully qualified class name of the caller.
- * @param location The location of the caller or null.
- * @param marker A Marker or null if none is present.
- * @param level The event Level.
- * @param data The Message.
- * @param t A Throwable or null.
- * @since 3.0
- */
- default void log(final Supplier<LoggerConfig> reconfigured, final String
loggerName, final String fqcn, final StackTraceElement location,
- final Marker marker, final Level level, final Message
data, final Throwable t) {
- }
-
- /**
- * Logs an event.
- *
- * @param reconfigured supplies the next LoggerConfig if the strategy's
LoggerConfig is no longer active
- * @param event The log event.
- */
- void log(Supplier<LoggerConfig> reconfigured, LogEvent event);
-
- /**
- * For internal use by the ReliabilityStrategy; returns the LoggerConfig
to use.
- *
- * @param next supplies the next LoggerConfig if the strategy's
LoggerConfig is no longer active
- * @return the currently active LoggerConfig
- */
- LoggerConfig getActiveLoggerConfig(Supplier<LoggerConfig> next);
-
- /**
- * Called after a log event was logged.
- */
- void afterLogEvent();
-
- /**
- * Called before all appenders are stopped.
- */
- void beforeStopAppenders();
-
- /**
- * Called before the configuration is stopped.
- *
- * @param configuration the configuration that will be stopped
- */
- void beforeStopConfiguration(Configuration configuration);
-
-}
+/*
+ * 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.config;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.Marker;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.message.Message;
+import org.apache.logging.log4j.util.Supplier;
+
+/**
+ * Interface for objects that know how to ensure delivery of log events to the
appropriate appenders, even during and
+ * after the configuration has been modified while the system is actively used.
+ */
+public interface ReliabilityStrategy {
+
+ /**
+ * Logs an event.
+ *
+ * @param reconfigured supplies the next LoggerConfig if the strategy's
LoggerConfig is no longer active
+ * @param loggerName The name of the Logger.
+ * @param fqcn The fully qualified class name of the caller.
+ * @param marker A Marker or null if none is present.
+ * @param level The event Level.
+ * @param data The Message.
+ * @param t A Throwable or null.
+ */
+ void log(Supplier<LoggerConfig> reconfigured, String loggerName, String
fqcn, Marker marker, Level level,
+ Message data, Throwable t);
+ /**
+ * Logs an event.
+ *
+ * @param reconfigured supplies the next LoggerConfig if the strategy's
LoggerConfig is no longer active
+ * @param loggerName The name of the Logger.
+ * @param fqcn The fully qualified class name of the caller.
+ * @param location The location of the caller or null.
+ * @param marker A Marker or null if none is present.
+ * @param level The event Level.
+ * @param data The Message.
+ * @param t A Throwable or null.
+ * @since 3.0
+ */
+ default void log(final Supplier<LoggerConfig> reconfigured, final String
loggerName, final String fqcn, final StackTraceElement location,
+ final Marker marker, final Level level, final Message
data, final Throwable t) {
+ }
+
+ /**
+ * Logs an event.
+ *
+ * @param reconfigured supplies the next LoggerConfig if the strategy's
LoggerConfig is no longer active
+ * @param event The log event.
+ */
+ void log(Supplier<LoggerConfig> reconfigured, LogEvent event);
+
+ /**
+ * For internal use by the ReliabilityStrategy; returns the LoggerConfig
to use.
+ *
+ * @param next supplies the next LoggerConfig if the strategy's
LoggerConfig is no longer active
+ * @return the currently active LoggerConfig
+ */
+ LoggerConfig getActiveLoggerConfig(Supplier<LoggerConfig> next);
+
+ /**
+ * Called after a log event was logged.
+ */
+ void afterLogEvent();
+
+ /**
+ * Called before all appenders are stopped.
+ */
+ void beforeStopAppenders();
+
+ /**
+ * Called before the configuration is stopped.
+ *
+ * @param configuration the configuration that will be stopped
+ */
+ void beforeStopConfiguration(Configuration configuration);
+
+}
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultComponentAndConfigurationBuilder.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultComponentAndConfigurationBuilder.java
index f6e7e1e6bb..2ca603dabe 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultComponentAndConfigurationBuilder.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultComponentAndConfigurationBuilder.java
@@ -1,47 +1,47 @@
-/*
- * 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.config.builder.impl;
-
-import org.apache.logging.log4j.core.config.Configuration;
-import org.apache.logging.log4j.core.config.builder.api.ComponentBuilder;
-
-/**
- * Extends {@code DefaultComponentBuilder} to specify
- * {@code DefaultConfigurationBuilder<? extends Configuration>} as the
- * {@code ConfigurationBuilder} type.
- *
- * @since 2.4
- */
-class DefaultComponentAndConfigurationBuilder<T extends ComponentBuilder<T>>
- extends DefaultComponentBuilder<T, DefaultConfigurationBuilder<?
extends Configuration>> {
-
- DefaultComponentAndConfigurationBuilder(final
DefaultConfigurationBuilder<? extends Configuration> builder, final String name,
- final String type, final String value) {
- super(builder, name, type, value);
- }
-
- DefaultComponentAndConfigurationBuilder(final
DefaultConfigurationBuilder<? extends Configuration> builder, final String name,
- final String type) {
- super(builder, name, type);
- }
-
- public DefaultComponentAndConfigurationBuilder(final
DefaultConfigurationBuilder<? extends Configuration> builder,
- final String type) {
- super(builder, type);
- }
-
-}
+/*
+ * 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.config.builder.impl;
+
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.builder.api.ComponentBuilder;
+
+/**
+ * Extends {@code DefaultComponentBuilder} to specify
+ * {@code DefaultConfigurationBuilder<? extends Configuration>} as the
+ * {@code ConfigurationBuilder} type.
+ *
+ * @since 2.4
+ */
+class DefaultComponentAndConfigurationBuilder<T extends ComponentBuilder<T>>
+ extends DefaultComponentBuilder<T, DefaultConfigurationBuilder<?
extends Configuration>> {
+
+ DefaultComponentAndConfigurationBuilder(final
DefaultConfigurationBuilder<? extends Configuration> builder, final String name,
+ final String type, final String value) {
+ super(builder, name, type, value);
+ }
+
+ DefaultComponentAndConfigurationBuilder(final
DefaultConfigurationBuilder<? extends Configuration> builder, final String name,
+ final String type) {
+ super(builder, name, type);
+ }
+
+ public DefaultComponentAndConfigurationBuilder(final
DefaultConfigurationBuilder<? extends Configuration> builder,
+ final String type) {
+ super(builder, type);
+ }
+
+}
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/selector/CoreContextSelectors.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/selector/CoreContextSelectors.java
index 2ee6b0d4f6..1588d2999d 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/selector/CoreContextSelectors.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/selector/CoreContextSelectors.java
@@ -1,31 +1,31 @@
-/*
- * 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.selector;
-
-import org.apache.logging.log4j.core.async.AsyncLoggerContextSelector;
-import org.apache.logging.log4j.core.async.BasicAsyncLoggerContextSelector;
-
-public class CoreContextSelectors {
-
- public static final Class<?>[] CLASSES = new Class<?>[] {
- ClassLoaderContextSelector.class,
- BasicContextSelector.class,
- AsyncLoggerContextSelector.class,
- BasicAsyncLoggerContextSelector.class
- };
-
-}
+/*
+ * 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.selector;
+
+import org.apache.logging.log4j.core.async.AsyncLoggerContextSelector;
+import org.apache.logging.log4j.core.async.BasicAsyncLoggerContextSelector;
+
+public class CoreContextSelectors {
+
+ public static final Class<?>[] CLASSES = new Class<?>[] {
+ ClassLoaderContextSelector.class,
+ BasicContextSelector.class,
+ AsyncLoggerContextSelector.class,
+ BasicAsyncLoggerContextSelector.class
+ };
+
+}
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/CloseShieldOutputStream.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/CloseShieldOutputStream.java
index 1139bd20f9..946e0c29b4 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/CloseShieldOutputStream.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/CloseShieldOutputStream.java
@@ -1,60 +1,60 @@
-/*
- * 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.io.IOException;
-import java.io.OutputStream;
-
-/**
- * A delegating OutputStream that does not close its delegate.
- */
-public class CloseShieldOutputStream extends OutputStream {
-
- private final OutputStream delegate;
-
- public CloseShieldOutputStream(final OutputStream delegate) {
- this.delegate = delegate;
- }
-
- /**
- * Does nothing.
- */
- @Override
- public void close() {
- // do not close delegate
- }
-
- @Override
- public void flush() throws IOException {
- delegate.flush();
- }
-
- @Override
- public void write(final byte[] b) throws IOException {
- delegate.write(b);
- }
-
- @Override
- public void write(final byte[] b, final int off, final int len) throws
IOException {
- delegate.write(b, off, len);
- }
-
- @Override
- public void write(final int b) throws IOException {
- delegate.write(b);
- }
+/*
+ * 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.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * A delegating OutputStream that does not close its delegate.
+ */
+public class CloseShieldOutputStream extends OutputStream {
+
+ private final OutputStream delegate;
+
+ public CloseShieldOutputStream(final OutputStream delegate) {
+ this.delegate = delegate;
+ }
+
+ /**
+ * Does nothing.
+ */
+ @Override
+ public void close() {
+ // do not close delegate
+ }
+
+ @Override
+ public void flush() throws IOException {
+ delegate.flush();
+ }
+
+ @Override
+ public void write(final byte[] b) throws IOException {
+ delegate.write(b);
+ }
+
+ @Override
+ public void write(final byte[] b, final int off, final int len) throws
IOException {
+ delegate.write(b, off, len);
+ }
+
+ @Override
+ public void write(final int b) throws IOException {
+ delegate.write(b);
+ }
}
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/CloseShieldWriter.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/CloseShieldWriter.java
index c29cdf624e..b2f6fdcd9d 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/CloseShieldWriter.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/CloseShieldWriter.java
@@ -1,46 +1,46 @@
-/*
- * 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.io.IOException;
-import java.io.Writer;
-
-public class CloseShieldWriter extends Writer {
-
- private final Writer delegate;
-
- public CloseShieldWriter(final Writer delegate) {
- this.delegate = delegate;
- }
-
- @Override
- public void close() throws IOException {
- // do not close delegate
- }
-
- @Override
- public void flush() throws IOException {
- delegate.flush();
-
- }
-
- @Override
- public void write(final char[] cbuf, final int off, final int len) throws
IOException {
- delegate.write(cbuf, off, len);
- }
-
-}
+/*
+ * 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.io.IOException;
+import java.io.Writer;
+
+public class CloseShieldWriter extends Writer {
+
+ private final Writer delegate;
+
+ public CloseShieldWriter(final Writer delegate) {
+ this.delegate = delegate;
+ }
+
+ @Override
+ public void close() throws IOException {
+ // do not close delegate
+ }
+
+ @Override
+ public void flush() throws IOException {
+ delegate.flush();
+
+ }
+
+ @Override
+ public void write(final char[] cbuf, final int off, final int len) throws
IOException {
+ delegate.write(cbuf, off, len);
+ }
+
+}
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/IOUtils.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/IOUtils.java
index ffb8615cd3..07e5c79316 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/IOUtils.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/IOUtils.java
@@ -1,130 +1,130 @@
-/*
- * 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.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.Writer;
-
-/**
- * Copied from Apache Commons IO revision 1686747.
- */
-public class IOUtils {
-
- /**
- * The default buffer size ({@value}) to use for
- * {@link #copyLarge(InputStream, OutputStream)}
- * and
- * {@link #copyLarge(Reader, Writer)}
- */
- private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
-
- /**
- * Represents the end-of-file (or stream).
- */
- public static final int EOF = -1;
-
- /**
- * Copies chars from a <code>Reader</code> to a <code>Writer</code>.
- * <p/>
- * This method buffers the input internally, so there is no need to use a
- * <code>BufferedReader</code>.
- * <p/>
- * Large streams (over 2GB) will return a chars copied value of
- * <code>-1</code> after the copy has completed since the correct
- * number of chars cannot be returned as an int. For large streams
- * use the <code>copyLarge(Reader, Writer)</code> method.
- *
- * @param input the <code>Reader</code> to read from
- * @param output the <code>Writer</code> to write to
- * @return the number of characters copied, or -1 if > Integer.MAX_VALUE
- * @throws NullPointerException if the input or output is null
- * @throws IOException if an I/O error occurs
- * @since 1.1
- */
- public static int copy(final Reader input, final Writer output) throws
IOException {
- final long count = copyLarge(input, output);
- if (count > Integer.MAX_VALUE) {
- return -1;
- }
- return (int) count;
- }
-
- /**
- * Copies chars from a large (over 2GB) <code>Reader</code> to a
<code>Writer</code>.
- * <p/>
- * This method buffers the input internally, so there is no need to use a
- * <code>BufferedReader</code>.
- * <p/>
- * The buffer size is given by {@link #DEFAULT_BUFFER_SIZE}.
- *
- * @param input the <code>Reader</code> to read from
- * @param output the <code>Writer</code> to write to
- * @return the number of characters copied
- * @throws NullPointerException if the input or output is null
- * @throws IOException if an I/O error occurs
- * @since 1.3
- */
- public static long copyLarge(final Reader input, final Writer output)
throws IOException {
- return copyLarge(input, output, new char[DEFAULT_BUFFER_SIZE]);
- }
-
- /**
- * Copies chars from a large (over 2GB) <code>Reader</code> to a
<code>Writer</code>.
- * <p/>
- * This method uses the provided buffer, so there is no need to use a
- * <code>BufferedReader</code>.
- * <p/>
- *
- * @param input the <code>Reader</code> to read from
- * @param output the <code>Writer</code> to write to
- * @param buffer the buffer to be used for the copy
- * @return the number of characters copied
- * @throws NullPointerException if the input or output is null
- * @throws IOException if an I/O error occurs
- * @since 2.2
- */
- public static long copyLarge(final Reader input, final Writer output,
final char[] buffer) throws IOException {
- long count = 0;
- int n;
- while (EOF != (n = input.read(buffer))) {
- output.write(buffer, 0, n);
- count += n;
- }
- return count;
- }
-
- /**
- * Gets the contents of a <code>Reader</code> as a String.
- * <p/>
- * This method buffers the input internally, so there is no need to use a
- * <code>BufferedReader</code>.
- *
- * @param input the <code>Reader</code> to read from
- * @return the requested String
- * @throws NullPointerException if the input is null
- * @throws IOException if an I/O error occurs
- */
- public static String toString(final Reader input) throws IOException {
- final StringBuilderWriter sw = new StringBuilderWriter();
- copy(input, sw);
- return sw.toString();
- }
-
-}
+/*
+ * 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.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.Writer;
+
+/**
+ * Copied from Apache Commons IO revision 1686747.
+ */
+public class IOUtils {
+
+ /**
+ * The default buffer size ({@value}) to use for
+ * {@link #copyLarge(InputStream, OutputStream)}
+ * and
+ * {@link #copyLarge(Reader, Writer)}
+ */
+ private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
+
+ /**
+ * Represents the end-of-file (or stream).
+ */
+ public static final int EOF = -1;
+
+ /**
+ * Copies chars from a <code>Reader</code> to a <code>Writer</code>.
+ * <p/>
+ * This method buffers the input internally, so there is no need to use a
+ * <code>BufferedReader</code>.
+ * <p/>
+ * Large streams (over 2GB) will return a chars copied value of
+ * <code>-1</code> after the copy has completed since the correct
+ * number of chars cannot be returned as an int. For large streams
+ * use the <code>copyLarge(Reader, Writer)</code> method.
+ *
+ * @param input the <code>Reader</code> to read from
+ * @param output the <code>Writer</code> to write to
+ * @return the number of characters copied, or -1 if > Integer.MAX_VALUE
+ * @throws NullPointerException if the input or output is null
+ * @throws IOException if an I/O error occurs
+ * @since 1.1
+ */
+ public static int copy(final Reader input, final Writer output) throws
IOException {
+ final long count = copyLarge(input, output);
+ if (count > Integer.MAX_VALUE) {
+ return -1;
+ }
+ return (int) count;
+ }
+
+ /**
+ * Copies chars from a large (over 2GB) <code>Reader</code> to a
<code>Writer</code>.
+ * <p/>
+ * This method buffers the input internally, so there is no need to use a
+ * <code>BufferedReader</code>.
+ * <p/>
+ * The buffer size is given by {@link #DEFAULT_BUFFER_SIZE}.
+ *
+ * @param input the <code>Reader</code> to read from
+ * @param output the <code>Writer</code> to write to
+ * @return the number of characters copied
+ * @throws NullPointerException if the input or output is null
+ * @throws IOException if an I/O error occurs
+ * @since 1.3
+ */
+ public static long copyLarge(final Reader input, final Writer output)
throws IOException {
+ return copyLarge(input, output, new char[DEFAULT_BUFFER_SIZE]);
+ }
+
+ /**
+ * Copies chars from a large (over 2GB) <code>Reader</code> to a
<code>Writer</code>.
+ * <p/>
+ * This method uses the provided buffer, so there is no need to use a
+ * <code>BufferedReader</code>.
+ * <p/>
+ *
+ * @param input the <code>Reader</code> to read from
+ * @param output the <code>Writer</code> to write to
+ * @param buffer the buffer to be used for the copy
+ * @return the number of characters copied
+ * @throws NullPointerException if the input or output is null
+ * @throws IOException if an I/O error occurs
+ * @since 2.2
+ */
+ public static long copyLarge(final Reader input, final Writer output,
final char[] buffer) throws IOException {
+ long count = 0;
+ int n;
+ while (EOF != (n = input.read(buffer))) {
+ output.write(buffer, 0, n);
+ count += n;
+ }
+ return count;
+ }
+
+ /**
+ * Gets the contents of a <code>Reader</code> as a String.
+ * <p/>
+ * This method buffers the input internally, so there is no need to use a
+ * <code>BufferedReader</code>.
+ *
+ * @param input the <code>Reader</code> to read from
+ * @return the requested String
+ * @throws NullPointerException if the input is null
+ * @throws IOException if an I/O error occurs
+ */
+ public static String toString(final Reader input) throws IOException {
+ final StringBuilderWriter sw = new StringBuilderWriter();
+ copy(input, sw);
+ return sw.toString();
+ }
+
+}