You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by rc...@apache.org on 2020/12/11 10:44:19 UTC
[james-project] 15/15: [REFACTORING] Use StandardCharsets in more
places
This is an automated email from the ASF dual-hosted git repository.
rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit de85e69d2908d18bbc5680ff1af8a71742629afe
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Sun Dec 6 22:32:50 2020 +0700
[REFACTORING] Use StandardCharsets in more places
---
.../james/mailbox/store/search/SearchUtil.java | 12 ++++----
.../PartContentBuilderComplexMultipartTest.java | 3 +-
...PartContentBuilderMultipartAlternativeTest.java | 7 ++---
.../search/SearchUtilsMultipartMixedTest.java | 4 +--
.../store/search/SearchUtilsRFC822Test.java | 4 +--
.../james/mpt/helper/ByteBufferInputStream.java | 4 +--
.../james/mpt/helper/ByteBufferOutputStream.java | 8 +++---
.../org/apache/james/mpt/helper/ScriptBuilder.java | 7 ++---
.../apache/james/mpt/session/ExternalSession.java | 10 +++----
.../java/org/apache/james/mpt/DiscardProtocol.java | 8 ++----
.../james/protocols/api/ProtocolSessionImpl.java | 5 ++--
.../james/imap/decode/ImapRequestLineReader.java | 4 +--
.../imap/encode/base/ImapResponseComposerImpl.java | 8 ++----
.../imap/processor/AuthenticateProcessor.java | 4 +--
.../parser/SearchCommandParserCharsetTest.java | 33 +++++++++-------------
.../org/apache/james/CassandraNodeConfTest.java | 4 +--
.../james/JamesServerWithRetryConnectionTest.java | 4 +--
.../CassandraSchemaVersionStartUpCheckTest.java | 4 +--
.../java/org/apache/james/JamesServerContract.java | 4 +--
.../java/org/apache/james/JPAJamesServerTest.java | 4 +--
.../java/org/apache/james/JPAJamesServerTest.java | 4 +--
21 files changed, 65 insertions(+), 80 deletions(-)
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SearchUtil.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SearchUtil.java
index 4f28090..cb2fc47 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SearchUtil.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SearchUtil.java
@@ -18,7 +18,8 @@
****************************************************************/
package org.apache.james.mailbox.store.search;
-import java.nio.charset.Charset;
+import static java.nio.charset.StandardCharsets.UTF_8;
+
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
@@ -52,18 +53,15 @@ public class SearchUtil {
private static final char CLOSE_SQUARE_BRACKED = ']';
private static final char COLON = ':';
- private static final Charset UTF8 = Charset.forName("UTF8");
-
-
/**
* Return the DISPLAY ADDRESS for the given {@link Mailbox}.
*
* See rfc5957 3. DISPLAY Sort Value for an Address for the details
- *
+ *
* For the purposes of the sort criteria defined in this document, the
* sort value for an [IMAP] address structure is defined as follows:
* <p>
- * o If the address structure's [IMAP] addr-name is non-NIL, apply the
+ * o If the address structure's [IMAP] addr-name is non-NIL, apply the
* procedure from [RFC5255], Section 4.6. (That is, decode any
* RFC2047] encoded-words and convert the resulting character string
* into a charset valid for the currently active [RFC4790] collation,
@@ -234,7 +232,7 @@ public class SearchUtil {
// Convert all tabs and continuations to space. Convert all
// multiple spaces to a single space.
String decodedSubject = MimeUtil.unfold(DecoderUtil.decodeEncodedWords(subject, DecodeMonitor.SILENT));
- decodedSubject = new String(decodedSubject.getBytes(UTF8), UTF8);
+ decodedSubject = new String(decodedSubject.getBytes(UTF_8), UTF_8);
// replace all tabs with spaces and replace multiple spaces with one space
decodedSubject = decodedSubject.replaceAll("\t", " ").replaceAll("( ){2,}", " ");
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/PartContentBuilderComplexMultipartTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/PartContentBuilderComplexMultipartTest.java
index d2d34ce..88e30d3 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/PartContentBuilderComplexMultipartTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/PartContentBuilderComplexMultipartTest.java
@@ -24,7 +24,6 @@ import static org.assertj.core.api.Fail.fail;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
-import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.List;
@@ -215,7 +214,7 @@ class PartContentBuilderComplexMultipartTest {
}
private void to(int[] path) throws Exception {
- InputStream in = new ByteArrayInputStream(Charset.forName("us-ascii")
+ InputStream in = new ByteArrayInputStream(StandardCharsets.US_ASCII
.encode(MULTIPART_MIXED).array());
builder.parse(in);
for (int aPath : path) {
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/PartContentBuilderMultipartAlternativeTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/PartContentBuilderMultipartAlternativeTest.java
index 813c039..08aae12 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/PartContentBuilderMultipartAlternativeTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/PartContentBuilderMultipartAlternativeTest.java
@@ -23,7 +23,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
-import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.List;
@@ -101,7 +100,7 @@ class PartContentBuilderMultipartAlternativeTest {
}
private String fullContent(String mail, int position) throws Exception {
- InputStream in = new ByteArrayInputStream(Charset.forName("us-ascii")
+ InputStream in = new ByteArrayInputStream(StandardCharsets.US_ASCII
.encode(mail).array());
builder.parse(in);
builder.to(position);
@@ -109,7 +108,7 @@ class PartContentBuilderMultipartAlternativeTest {
}
private String bodyContent(String mail, int position) throws Exception {
- InputStream in = new ByteArrayInputStream(Charset.forName("us-ascii")
+ InputStream in = new ByteArrayInputStream(StandardCharsets.US_ASCII
.encode(mail).array());
builder.parse(in);
builder.to(position);
@@ -126,7 +125,7 @@ class PartContentBuilderMultipartAlternativeTest {
}
private List<Header> headers(String mail, int position) throws Exception {
- InputStream in = new ByteArrayInputStream(Charset.forName("us-ascii")
+ InputStream in = new ByteArrayInputStream(StandardCharsets.US_ASCII
.encode(mail).array());
builder.parse(in);
builder.to(position);
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/SearchUtilsMultipartMixedTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/SearchUtilsMultipartMixedTest.java
index c39e743..95ea0f8 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/SearchUtilsMultipartMixedTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/SearchUtilsMultipartMixedTest.java
@@ -21,7 +21,7 @@ package org.apache.james.mailbox.store.search;
import static org.assertj.core.api.Assertions.assertThat;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
@@ -123,7 +123,7 @@ class SearchUtilsMultipartMixedTest {
builder.header("Subject", "A Mixed Multipart Mail");
builder.header("Date", "Thu, 14 Feb 2008 12:00:00 +0000 (GMT)");
builder.header("Content-Type", "multipart/mixed;boundary=1729");
- builder.body(Charset.forName("us-ascii").encode(BODY).array());
+ builder.body(StandardCharsets.US_ASCII.encode(BODY).array());
row = builder.build();
recent = new ArrayList<>();
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/SearchUtilsRFC822Test.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/SearchUtilsRFC822Test.java
index 5c33cff..ab84077 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/SearchUtilsRFC822Test.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/SearchUtilsRFC822Test.java
@@ -21,7 +21,7 @@ package org.apache.james.mailbox.store.search;
import static org.assertj.core.api.Assertions.assertThat;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
@@ -64,7 +64,7 @@ class SearchUtilsRFC822Test {
builder.header("To", FROM_ADDRESS);
builder.header("Subject", "A " + SUBJECT_PART + " Multipart Mail");
builder.header("Date", "Thu, 14 Feb 2008 12:00:00 +0000 (GMT)");
- builder.body(Charset.forName("us-ascii").encode(BODY).array());
+ builder.body(StandardCharsets.US_ASCII.encode(BODY).array());
row = builder.build();
Iterator<MailboxMessage> messages = null;
diff --git a/mpt/core/src/main/java/org/apache/james/mpt/helper/ByteBufferInputStream.java b/mpt/core/src/main/java/org/apache/james/mpt/helper/ByteBufferInputStream.java
index 9658888..a50ad93 100644
--- a/mpt/core/src/main/java/org/apache/james/mpt/helper/ByteBufferInputStream.java
+++ b/mpt/core/src/main/java/org/apache/james/mpt/helper/ByteBufferInputStream.java
@@ -23,14 +23,14 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
-import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
+import java.nio.charset.StandardCharsets;
public class ByteBufferInputStream extends InputStream {
private final ByteBuffer buffer = ByteBuffer.allocate(160384);
- private final CharsetEncoder encoder = Charset.forName("ASCII").newEncoder();
+ private final CharsetEncoder encoder = StandardCharsets.US_ASCII.newEncoder();
private boolean readLast = true;
diff --git a/mpt/core/src/main/java/org/apache/james/mpt/helper/ByteBufferOutputStream.java b/mpt/core/src/main/java/org/apache/james/mpt/helper/ByteBufferOutputStream.java
index f080849..bb51dc9 100644
--- a/mpt/core/src/main/java/org/apache/james/mpt/helper/ByteBufferOutputStream.java
+++ b/mpt/core/src/main/java/org/apache/james/mpt/helper/ByteBufferOutputStream.java
@@ -19,18 +19,18 @@
package org.apache.james.mpt.helper;
+import static java.nio.charset.StandardCharsets.US_ASCII;
+
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
-import java.nio.charset.Charset;
import org.apache.james.mpt.api.Continuation;
public class ByteBufferOutputStream extends OutputStream {
private final ByteBuffer buffer = ByteBuffer.allocate(160384);
- private final Charset ascii = Charset.forName("ASCII");
private final Continuation continuation;
private boolean matchPlus = false;
private boolean matchCR = false;
@@ -41,7 +41,7 @@ public class ByteBufferOutputStream extends OutputStream {
}
public void write(String message) throws IOException {
- ascii.newEncoder().encode(CharBuffer.wrap(message), buffer, true);
+ US_ASCII.newEncoder().encode(CharBuffer.wrap(message), buffer, true);
}
@Override
@@ -85,7 +85,7 @@ public class ByteBufferOutputStream extends OutputStream {
limit = 0;
}
readOnlyBuffer.limit(limit);
- String result = ascii.decode(readOnlyBuffer).toString();
+ String result = US_ASCII.decode(readOnlyBuffer).toString();
buffer.compact();
return result;
}
diff --git a/mpt/core/src/main/java/org/apache/james/mpt/helper/ScriptBuilder.java b/mpt/core/src/main/java/org/apache/james/mpt/helper/ScriptBuilder.java
index eb3199c..57a8d15 100644
--- a/mpt/core/src/main/java/org/apache/james/mpt/helper/ScriptBuilder.java
+++ b/mpt/core/src/main/java/org/apache/james/mpt/helper/ScriptBuilder.java
@@ -19,6 +19,8 @@
package org.apache.james.mpt.helper;
+import static java.nio.charset.StandardCharsets.US_ASCII;
+
import java.io.IOException;
import java.io.InputStream;
import java.net.InetSocketAddress;
@@ -27,7 +29,6 @@ import java.nio.CharBuffer;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.SocketChannel;
import java.nio.channels.WritableByteChannel;
-import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Locale;
@@ -1098,8 +1099,6 @@ public class ScriptBuilder {
public static final class Client {
- private static final Charset ASCII = Charset.forName("us-ascii");
-
private final Out out;
private final ReadableByteChannel source;
@@ -1218,7 +1217,7 @@ public class ScriptBuilder {
public void write(String phrase) throws Exception {
out.print(phrase);
- final ByteBuffer buffer = ASCII.encode(phrase);
+ final ByteBuffer buffer = US_ASCII.encode(phrase);
writeRemaining(buffer);
}
diff --git a/mpt/core/src/main/java/org/apache/james/mpt/session/ExternalSession.java b/mpt/core/src/main/java/org/apache/james/mpt/session/ExternalSession.java
index 17812a1..5eaf98e 100644
--- a/mpt/core/src/main/java/org/apache/james/mpt/session/ExternalSession.java
+++ b/mpt/core/src/main/java/org/apache/james/mpt/session/ExternalSession.java
@@ -19,10 +19,11 @@
package org.apache.james.mpt.session;
+import static java.nio.charset.StandardCharsets.US_ASCII;
+
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
-import java.nio.charset.Charset;
import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.NotImplementedException;
@@ -42,8 +43,6 @@ public final class ExternalSession implements Session {
private final ByteBuffer readBuffer;
- private final Charset ascii;
-
private final ByteBuffer lineEndBuffer;
private boolean first = true;
@@ -59,7 +58,6 @@ public final class ExternalSession implements Session {
this.socket = socket;
this.monitor = monitor;
readBuffer = ByteBuffer.allocateDirect(2048);
- ascii = Charset.forName("US-ASCII");
lineEndBuffer = ByteBuffer.wrap(CRLF);
this.shabang = shabang;
}
@@ -161,7 +159,7 @@ public final class ExternalSession implements Session {
public void writeLine(String line) throws Exception {
monitor.note("-> " + line);
monitor.debug("[Writing line]");
- ByteBuffer writeBuffer = ascii.encode(line);
+ ByteBuffer writeBuffer = US_ASCII.encode(line);
while (writeBuffer.hasRemaining()) {
socket.write(writeBuffer);
}
@@ -187,7 +185,7 @@ public final class ExternalSession implements Session {
final String TAB = " ";
return "External ( " + "socket = " + this.socket + TAB + "monitor = " + this.monitor + TAB
- + "readBuffer = " + this.readBuffer + TAB + "ascii = " + this.ascii + TAB + "lineEndBuffer = "
+ + "readBuffer = " + this.readBuffer + TAB + "lineEndBuffer = "
+ this.lineEndBuffer + TAB + "first = " + this.first + TAB + "shabang = " + this.shabang + TAB + " )";
}
diff --git a/mpt/core/src/test/java/org/apache/james/mpt/DiscardProtocol.java b/mpt/core/src/test/java/org/apache/james/mpt/DiscardProtocol.java
index 2774079..36259e0 100644
--- a/mpt/core/src/test/java/org/apache/james/mpt/DiscardProtocol.java
+++ b/mpt/core/src/test/java/org/apache/james/mpt/DiscardProtocol.java
@@ -19,13 +19,14 @@
package org.apache.james.mpt;
+import static java.nio.charset.StandardCharsets.US_ASCII;
+
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
-import java.nio.charset.Charset;
import java.util.Collection;
import java.util.LinkedList;
import java.util.Queue;
@@ -38,9 +39,6 @@ import org.slf4j.LoggerFactory;
* Simple <a href='http://tools.ietf.org/html/rfc863'>RFC 863</a> implementation.
*/
public class DiscardProtocol {
-
- private static final Charset ASCII = Charset.forName("US-ASCII");
-
private static final int SOCKET_CONNECTION_WAIT_MILLIS = 30;
private static final int IDLE_TIMEOUT = 120000;
@@ -259,7 +257,7 @@ public class DiscardProtocol {
*/
private void decant() {
buffer.flip();
- final CharBuffer decoded = ASCII.decode(buffer);
+ final CharBuffer decoded = US_ASCII.decode(buffer);
out.append(decoded);
buffer.clear();
}
diff --git a/protocols/api/src/main/java/org/apache/james/protocols/api/ProtocolSessionImpl.java b/protocols/api/src/main/java/org/apache/james/protocols/api/ProtocolSessionImpl.java
index ec27d9e..f824826 100644
--- a/protocols/api/src/main/java/org/apache/james/protocols/api/ProtocolSessionImpl.java
+++ b/protocols/api/src/main/java/org/apache/james/protocols/api/ProtocolSessionImpl.java
@@ -19,6 +19,8 @@
package org.apache.james.protocols.api;
+import static java.nio.charset.StandardCharsets.US_ASCII;
+
import java.net.InetSocketAddress;
import java.nio.charset.Charset;
import java.util.HashMap;
@@ -41,7 +43,6 @@ public class ProtocolSessionImpl implements ProtocolSession {
private final Map<AttachmentKey<?>, Object> sessionState;
private Username username;
protected final ProtocolConfiguration config;
- private static final Charset CHARSET = Charset.forName("US-ASCII");
private static final String DELIMITER = "\r\n";
public ProtocolSessionImpl(ProtocolTransport transport, ProtocolConfiguration config) {
@@ -173,7 +174,7 @@ public class ProtocolSessionImpl implements ProtocolSession {
*/
@Override
public Charset getCharset() {
- return CHARSET;
+ return US_ASCII;
}
/**
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java b/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
index 458f3e2..e8706be 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
@@ -19,6 +19,8 @@
package org.apache.james.imap.decode;
+import static java.nio.charset.StandardCharsets.US_ASCII;
+
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
@@ -55,8 +57,6 @@ public abstract class ImapRequestLineReader {
private static final int QUOTED_BUFFER_INITIAL_CAPACITY = 64;
- private static final Charset US_ASCII = Charset.forName("US-ASCII");
-
protected boolean nextSeen = false;
protected char nextChar; // unknown
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/encode/base/ImapResponseComposerImpl.java b/protocols/imap/src/main/java/org/apache/james/imap/encode/base/ImapResponseComposerImpl.java
index 55908bb..bbe4698 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/encode/base/ImapResponseComposerImpl.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/encode/base/ImapResponseComposerImpl.java
@@ -19,8 +19,9 @@
package org.apache.james.imap.encode.base;
+import static java.nio.charset.StandardCharsets.US_ASCII;
+
import java.io.IOException;
-import java.nio.charset.Charset;
import javax.mail.Flags;
@@ -52,13 +53,10 @@ public class ImapResponseComposerImpl implements ImapConstants, ImapResponseComp
private final FastByteArrayOutputStream buffer;
- private final Charset usAscii;
-
private boolean skipNextSpace;
public ImapResponseComposerImpl(ImapResponseWriter writer, int bufferSize) {
skipNextSpace = false;
- usAscii = Charset.forName("US-ASCII");
this.writer = writer;
this.buffer = new FastByteArrayOutputStream(bufferSize);
}
@@ -197,7 +195,7 @@ public class ImapResponseComposerImpl implements ImapConstants, ImapResponseComp
private void writeASCII(String string) throws IOException {
- buffer.write(string.getBytes(usAscii));
+ buffer.write(string.getBytes(US_ASCII));
}
@Override
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java
index 24620b9..38709cf 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java
@@ -20,7 +20,7 @@
package org.apache.james.imap.processor;
import java.io.Closeable;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
@@ -71,7 +71,7 @@ public class AuthenticateProcessor extends AbstractAuthProcessor<AuthenticateReq
responder.respond(new AuthenticateResponse());
session.pushLineHandler((requestSession, data) -> {
// cut of the CRLF
- String initialClientResponse = new String(data, 0, data.length - 2, Charset.forName("US-ASCII"));
+ String initialClientResponse = new String(data, 0, data.length - 2, StandardCharsets.US_ASCII);
doPlainAuth(initialClientResponse, requestSession, request, responder);
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserCharsetTest.java b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserCharsetTest.java
index dad9fef..8296512 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserCharsetTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserCharsetTest.java
@@ -19,6 +19,8 @@
package org.apache.james.imap.decode.parser;
+import static java.nio.charset.StandardCharsets.US_ASCII;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.james.imap.ImapFixture.TAG;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.eq;
@@ -30,8 +32,6 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
import org.apache.james.imap.api.ImapConstants;
import org.apache.james.imap.api.ImapMessage;
@@ -46,24 +46,19 @@ import org.junit.Before;
import org.junit.Test;
public class SearchCommandParserCharsetTest {
-
- private static final Charset UTF8 = Charset.forName("UTF-8");
-
- private static final Charset ASCII = Charset.forName("US-ASCII");
-
private static final String ASCII_SEARCH_TERM = "A Search Term";
private static final String NON_ASCII_SEARCH_TERM = "как Дела?";
private static final byte[] BYTES_NON_ASCII_SEARCH_TERM = NioUtils.toBytes(
- NON_ASCII_SEARCH_TERM, UTF8);
+ NON_ASCII_SEARCH_TERM, UTF_8);
private static final byte[] BYTES_UTF8_NON_ASCII_SEARCH_TERM = NioUtils
- .add(NioUtils.toBytes(" {16}\r\n", ASCII),
+ .add(NioUtils.toBytes(" {16}\r\n", US_ASCII),
BYTES_NON_ASCII_SEARCH_TERM);
private static final byte[] CHARSET = NioUtils.toBytes("CHARSET UTF-8 ",
- ASCII);
+ US_ASCII);
SearchCommandParser parser;
StatusResponseFactory mockStatusResponseFactory;
@@ -79,7 +74,7 @@ public class SearchCommandParserCharsetTest {
@Test
public void testBadCharset() throws Exception {
ImapRequestLineReader reader = new ImapRequestStreamLineReader(
- new ByteArrayInputStream("CHARSET BOGUS ".getBytes(StandardCharsets.US_ASCII)),
+ new ByteArrayInputStream("CHARSET BOGUS ".getBytes(US_ASCII)),
new ByteArrayOutputStream());
parser.decode(reader, TAG, false, new FakeImapSession());
@@ -95,50 +90,50 @@ public class SearchCommandParserCharsetTest {
@Test
public void testBCCShouldConvertCharset() throws Exception {
SearchKey key = SearchKey.buildBcc(NON_ASCII_SEARCH_TERM);
- checkUTF8Valid("BCC".getBytes(StandardCharsets.US_ASCII), key);
+ checkUTF8Valid("BCC".getBytes(US_ASCII), key);
}
@Test
public void testBODYShouldConvertCharset() throws Exception {
SearchKey key = SearchKey.buildBody(NON_ASCII_SEARCH_TERM);
- checkUTF8Valid("BODY".getBytes(StandardCharsets.US_ASCII), key);
+ checkUTF8Valid("BODY".getBytes(US_ASCII), key);
}
@Test
public void testCCShouldConvertCharset() throws Exception {
SearchKey key = SearchKey.buildCc(NON_ASCII_SEARCH_TERM);
- checkUTF8Valid("CC".getBytes(StandardCharsets.US_ASCII), key);
+ checkUTF8Valid("CC".getBytes(US_ASCII), key);
}
@Test
public void testFROMShouldConvertCharset() throws Exception {
SearchKey key = SearchKey.buildFrom(NON_ASCII_SEARCH_TERM);
- checkUTF8Valid("FROM".getBytes(StandardCharsets.US_ASCII), key);
+ checkUTF8Valid("FROM".getBytes(US_ASCII), key);
}
@Test
public void testHEADERShouldConvertCharset() throws Exception {
SearchKey key = SearchKey
.buildHeader("whatever", NON_ASCII_SEARCH_TERM);
- checkUTF8Valid("HEADER whatever".getBytes(StandardCharsets.US_ASCII), key);
+ checkUTF8Valid("HEADER whatever".getBytes(US_ASCII), key);
}
@Test
public void testSUBJECTShouldConvertCharset() throws Exception {
SearchKey key = SearchKey.buildSubject(NON_ASCII_SEARCH_TERM);
- checkUTF8Valid("SUBJECT".getBytes(StandardCharsets.US_ASCII), key);
+ checkUTF8Valid("SUBJECT".getBytes(US_ASCII), key);
}
@Test
public void testTEXTShouldConvertCharset() throws Exception {
SearchKey key = SearchKey.buildText(NON_ASCII_SEARCH_TERM);
- checkUTF8Valid("TEXT".getBytes(StandardCharsets.US_ASCII), key);
+ checkUTF8Valid("TEXT".getBytes(US_ASCII), key);
}
@Test
public void testTOShouldConvertCharset() throws Exception {
SearchKey key = SearchKey.buildTo(NON_ASCII_SEARCH_TERM);
- checkUTF8Valid("TO".getBytes(StandardCharsets.US_ASCII), key);
+ checkUTF8Valid("TO".getBytes(US_ASCII), key);
}
@Test
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraNodeConfTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraNodeConfTest.java
index 738e50b..361de3f 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraNodeConfTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraNodeConfTest.java
@@ -24,7 +24,7 @@ import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import org.apache.james.backends.cassandra.DockerCassandra;
import org.apache.james.backends.cassandra.init.configuration.ClusterConfiguration;
@@ -128,6 +128,6 @@ class CassandraNodeConfTest {
ByteBuffer byteBuffer = ByteBuffer.allocate(1000);
socketChannel.read(byteBuffer);
byte[] bytes = byteBuffer.array();
- return new String(bytes, Charset.forName("UTF-8"));
+ return new String(bytes, StandardCharsets.UTF_8);
}
}
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesServerWithRetryConnectionTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesServerWithRetryConnectionTest.java
index 8afe525..f6c8531 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesServerWithRetryConnectionTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesServerWithRetryConnectionTest.java
@@ -25,7 +25,7 @@ import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
@@ -114,6 +114,6 @@ class JamesServerWithRetryConnectionTest {
ByteBuffer byteBuffer = ByteBuffer.allocate(1000);
socketChannel.read(byteBuffer);
byte[] bytes = byteBuffer.array();
- return new String(bytes, Charset.forName("UTF-8"));
+ return new String(bytes, StandardCharsets.UTF_8);
}
}
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/CassandraSchemaVersionStartUpCheckTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/CassandraSchemaVersionStartUpCheckTest.java
index d1402e9..e22bb48 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/CassandraSchemaVersionStartUpCheckTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/CassandraSchemaVersionStartUpCheckTest.java
@@ -27,7 +27,7 @@ import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.util.Optional;
import org.apache.james.CassandraExtension;
@@ -148,6 +148,6 @@ class CassandraSchemaVersionStartUpCheckTest {
socketChannel.read(byteBuffer);
byte[] bytes = byteBuffer.array();
- return new String(bytes, Charset.forName("UTF-8"));
+ return new String(bytes, StandardCharsets.UTF_8);
}
}
diff --git a/server/container/guice/guice-common/src/test/java/org/apache/james/JamesServerContract.java b/server/container/guice/guice-common/src/test/java/org/apache/james/JamesServerContract.java
index 0f241d8..7c71bc4 100644
--- a/server/container/guice/guice-common/src/test/java/org/apache/james/JamesServerContract.java
+++ b/server/container/guice/guice-common/src/test/java/org/apache/james/JamesServerContract.java
@@ -24,7 +24,7 @@ import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import org.apache.james.modules.protocols.ImapGuiceProbe;
import org.apache.james.modules.protocols.LmtpGuiceProbe;
@@ -79,6 +79,6 @@ public interface JamesServerContract {
ByteBuffer byteBuffer = ByteBuffer.allocate(1000);
socketChannel.read(byteBuffer);
byte[] bytes = byteBuffer.array();
- return new String(bytes, Charset.forName("UTF-8"));
+ return new String(bytes, StandardCharsets.UTF_8);
}
}
diff --git a/server/container/guice/jpa-smtp-mariadb/src/test/java/org/apache/james/JPAJamesServerTest.java b/server/container/guice/jpa-smtp-mariadb/src/test/java/org/apache/james/JPAJamesServerTest.java
index 998b6ef..6f141fb 100644
--- a/server/container/guice/jpa-smtp-mariadb/src/test/java/org/apache/james/JPAJamesServerTest.java
+++ b/server/container/guice/jpa-smtp-mariadb/src/test/java/org/apache/james/JPAJamesServerTest.java
@@ -25,7 +25,7 @@ import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import org.apache.james.modules.protocols.SmtpGuiceProbe;
import org.apache.james.server.core.configuration.Configuration;
@@ -84,7 +84,7 @@ public class JPAJamesServerTest {
ByteBuffer byteBuffer = ByteBuffer.allocate(1000);
socketChannel.read(byteBuffer);
byte[] bytes = byteBuffer.array();
- return new String(bytes, Charset.forName("UTF-8"));
+ return new String(bytes, StandardCharsets.UTF_8);
}
}
diff --git a/server/container/guice/jpa-smtp/src/test/java/org/apache/james/JPAJamesServerTest.java b/server/container/guice/jpa-smtp/src/test/java/org/apache/james/JPAJamesServerTest.java
index 72cc48a..542022a 100644
--- a/server/container/guice/jpa-smtp/src/test/java/org/apache/james/JPAJamesServerTest.java
+++ b/server/container/guice/jpa-smtp/src/test/java/org/apache/james/JPAJamesServerTest.java
@@ -25,7 +25,7 @@ import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import javax.persistence.EntityManagerFactory;
@@ -91,7 +91,7 @@ public class JPAJamesServerTest {
ByteBuffer byteBuffer = ByteBuffer.allocate(1000);
socketChannel.read(byteBuffer);
byte[] bytes = byteBuffer.array();
- return new String(bytes, Charset.forName("UTF-8"));
+ return new String(bytes, StandardCharsets.UTF_8);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org