You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2020/04/21 02:56:49 UTC
[james-project] 13/19: [Refactoring] replace DateFormat by
thread-safe immutable DateTimeFormatter
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 4363944e67d129d12a4b8da7b90c5c4917eb7051
Author: Matthieu Baechler <ma...@apache.org>
AuthorDate: Fri Apr 3 16:01:48 2020 +0200
[Refactoring] replace DateFormat by thread-safe immutable DateTimeFormatter
---
.../james/protocols/smtp/core/ReceivedDataLineFilter.java | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/ReceivedDataLineFilter.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/ReceivedDataLineFilter.java
index fa32758..775e840 100644
--- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/ReceivedDataLineFilter.java
+++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/ReceivedDataLineFilter.java
@@ -20,12 +20,11 @@ package org.apache.james.protocols.smtp.core;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
@@ -49,11 +48,8 @@ public class ReceivedDataLineFilter extends SeparatingDataLineFilter {
private static final String SMTP = "SMTP";
private static final String ESMTPA = "ESMTPA";
private static final String ESMTP = "ESMTP";
-
- private static final ThreadLocal<DateFormat> DATEFORMAT = ThreadLocal.withInitial(() -> {
- // See RFC822 for the format
- return new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z (zzz)", Locale.US);
- });
+
+ private static DateTimeFormatter DATEFORMAT = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss Z (zzz)", Locale.US);
private static final AtomicInteger COUNTER = new AtomicInteger(0);
private final ProtocolSession.AttachmentKey<Boolean> headersPrefixAdded = ProtocolSession.AttachmentKey.of("HEADERS_PREFIX_ADDED" + COUNTER.incrementAndGet(), Boolean.class);
@@ -129,7 +125,7 @@ public class ReceivedDataLineFilter extends SeparatingDataLineFilter {
header.add(headerLineBuffer.toString());
headerLineBuffer = new StringBuilder();
- headerLineBuffer.append(DATEFORMAT.get().format(new Date()));
+ headerLineBuffer.append(DATEFORMAT.format(ZonedDateTime.now()));
header.add(headerLineBuffer.toString());
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org