diff --git a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/KnownHostEntryReader.java b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/KnownHostEntryReader.java index 4db24a16b..659ffae00 100644 --- a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/KnownHostEntryReader.java +++ b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/KnownHostEntryReader.java @@ -42,13 +42,13 @@ */ package org.eclipse.jgit.internal.transport.sshd; +import static java.nio.charset.StandardCharsets.UTF_8; import static java.text.MessageFormat.format; import static org.apache.sshd.client.config.hosts.HostPatternsHolder.NON_STANDARD_PORT_PATTERN_ENCLOSURE_END_DELIM; import static org.apache.sshd.client.config.hosts.HostPatternsHolder.NON_STANDARD_PORT_PATTERN_ENCLOSURE_START_DELIM; import java.io.BufferedReader; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.Arrays; @@ -99,8 +99,7 @@ private KnownHostEntryReader() { public static List readFromFile(Path path) throws IOException { List result = new LinkedList<>(); - try (BufferedReader r = Files.newBufferedReader(path, - StandardCharsets.UTF_8)) { + try (BufferedReader r = Files.newBufferedReader(path, UTF_8)) { r.lines().forEachOrdered(l -> { if (l == null) { return; diff --git a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/OpenSshServerKeyVerifier.java b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/OpenSshServerKeyVerifier.java index cfd3d19a7..7d8f3fd39 100644 --- a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/OpenSshServerKeyVerifier.java +++ b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/OpenSshServerKeyVerifier.java @@ -42,6 +42,7 @@ */ package org.eclipse.jgit.internal.transport.sshd; +import static java.nio.charset.StandardCharsets.UTF_8; import static java.text.MessageFormat.format; import java.io.BufferedReader; @@ -52,7 +53,6 @@ import java.io.OutputStreamWriter; import java.net.InetSocketAddress; import java.net.SocketAddress; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.InvalidPathException; import java.nio.file.Path; @@ -386,7 +386,7 @@ private void updateKnownHostsFile(ClientSession clientSession, try { try (BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(lock.getOutputStream(), - StandardCharsets.UTF_8))) { + UTF_8))) { writer.newLine(); writer.write(entry.getConfigLine()); writer.newLine(); @@ -422,10 +422,9 @@ private void updateModifiedServerKey(ClientSession clientSession, if (lock.lock()) { try { try (BufferedWriter writer = new BufferedWriter( - new OutputStreamWriter(lock.getOutputStream(), - StandardCharsets.UTF_8)); + new OutputStreamWriter(lock.getOutputStream(), UTF_8)); BufferedReader reader = Files.newBufferedReader(path, - StandardCharsets.UTF_8)) { + UTF_8)) { boolean done = false; String line; while ((line = reader.readLine()) != null) { diff --git a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/auth/BasicAuthentication.java b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/auth/BasicAuthentication.java index efb1f5586..a257a5ebc 100644 --- a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/auth/BasicAuthentication.java +++ b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/auth/BasicAuthentication.java @@ -42,13 +42,14 @@ */ package org.eclipse.jgit.internal.transport.sshd.auth; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.net.Authenticator; import java.net.Authenticator.RequestorType; import java.net.InetSocketAddress; import java.net.PasswordAuthentication; import java.nio.ByteBuffer; import java.nio.CharBuffer; -import java.nio.charset.StandardCharsets; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.Arrays; @@ -99,7 +100,7 @@ private byte[] convert(char[] pass) { if (pass == null) { return new byte[0]; } - ByteBuffer bytes = StandardCharsets.UTF_8.encode(CharBuffer.wrap(pass)); + ByteBuffer bytes = UTF_8.encode(CharBuffer.wrap(pass)); byte[] pwd = new byte[bytes.remaining()]; bytes.get(pwd); if (bytes.hasArray()) { diff --git a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/proxy/HttpClientConnector.java b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/proxy/HttpClientConnector.java index 46cdd52f5..c66ee38ca 100644 --- a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/proxy/HttpClientConnector.java +++ b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/proxy/HttpClientConnector.java @@ -42,12 +42,13 @@ */ package org.eclipse.jgit.internal.transport.sshd.proxy; +import static java.nio.charset.StandardCharsets.US_ASCII; +import static java.nio.charset.StandardCharsets.UTF_8; import static java.text.MessageFormat.format; import java.io.IOException; import java.net.HttpURLConnection; import java.net.InetSocketAddress; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; @@ -164,7 +165,7 @@ public void sendClientProxyMetadata(ClientSession sshSession) } private void send(StringBuilder msg, IoSession session) throws Exception { - byte[] data = eol(msg).toString().getBytes(StandardCharsets.US_ASCII); + byte[] data = eol(msg).toString().getBytes(US_ASCII); Buffer buffer = new ByteArrayBuffer(data.length, false); buffer.putRawBytes(data); session.writePacket(buffer).verify(getTimeout()); @@ -196,7 +197,7 @@ public void messageReceived(IoSession session, Readable buffer) int length = buffer.available(); byte[] data = new byte[length]; buffer.getRawBytes(data, 0, length); - String[] reply = new String(data, StandardCharsets.US_ASCII) + String[] reply = new String(data, US_ASCII) .split("\r\n"); //$NON-NLS-1$ handleMessage(session, Arrays.asList(reply)); } catch (Exception e) { @@ -348,7 +349,7 @@ public String getToken() throws Exception { throw new IOException(format( SshdText.get().proxyHttpInvalidUserName, proxy, user)); } - byte[] rawUser = user.getBytes(StandardCharsets.UTF_8); + byte[] rawUser = user.getBytes(UTF_8); byte[] toEncode = new byte[rawUser.length + 1 + password.length]; System.arraycopy(rawUser, 0, toEncode, 0, rawUser.length); toEncode[rawUser.length] = ':'; diff --git a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/proxy/Socks5ClientConnector.java b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/proxy/Socks5ClientConnector.java index 1844fdc79..27d6f418b 100644 --- a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/proxy/Socks5ClientConnector.java +++ b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/proxy/Socks5ClientConnector.java @@ -42,12 +42,13 @@ */ package org.eclipse.jgit.internal.transport.sshd.proxy; +import static java.nio.charset.StandardCharsets.US_ASCII; +import static java.nio.charset.StandardCharsets.UTF_8; import static java.text.MessageFormat.format; import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; -import java.nio.charset.StandardCharsets; import org.apache.sshd.client.session.ClientSession; import org.apache.sshd.common.io.IoSession; @@ -295,8 +296,7 @@ private void sendConnectInfo(IoSession session) throws Exception { byte type; int length = 0; if (rawAddress == null) { - remoteName = remoteAddress.getHostString() - .getBytes(StandardCharsets.US_ASCII); + remoteName = remoteAddress.getHostString().getBytes(US_ASCII); if (remoteName == null || remoteName.length == 0) { throw new IOException( format(SshdText.get().proxySocksNoRemoteHostName, @@ -542,7 +542,7 @@ public Buffer getToken() throws IOException { return null; } try { - byte[] rawUser = user.getBytes(StandardCharsets.UTF_8); + byte[] rawUser = user.getBytes(UTF_8); if (rawUser.length > 255) { throw new IOException(format( SshdText.get().proxySocksUsernameTooLong, proxy, diff --git a/org.eclipse.jgit.test/src/org/eclipse/jgit/transport/ssh/SshTestBase.java b/org.eclipse.jgit.test/src/org/eclipse/jgit/transport/ssh/SshTestBase.java index dde55b6d7..2f367ba51 100644 --- a/org.eclipse.jgit.test/src/org/eclipse/jgit/transport/ssh/SshTestBase.java +++ b/org.eclipse.jgit.test/src/org/eclipse/jgit/transport/ssh/SshTestBase.java @@ -42,6 +42,7 @@ */ package org.eclipse.jgit.transport.ssh; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -51,7 +52,6 @@ import java.io.File; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.List; import java.util.Locale; @@ -409,8 +409,7 @@ public void testSshModifiedHostKeyWithProviderDeny() throws Exception { private void checkKnownHostsModifiedHostKey(File backup, File newFile, String wrongKey) throws IOException { - List oldLines = Files.readAllLines(backup.toPath(), - StandardCharsets.UTF_8); + List oldLines = Files.readAllLines(backup.toPath(), UTF_8); // Find the original entry. We should have that again in known_hosts. String oldKeyPart = null; for (String oldLine : oldLines) { @@ -424,8 +423,7 @@ private void checkKnownHostsModifiedHostKey(File backup, File newFile, } } assertNotNull("Old key not found", oldKeyPart); - List newLines = Files.readAllLines(newFile.toPath(), - StandardCharsets.UTF_8); + List newLines = Files.readAllLines(newFile.toPath(), UTF_8); assertFalse("Old host key still found in known_hosts file" + newFile, hasHostKey("localhost", testPort, wrongKey, newLines)); assertTrue("New host key not found in known_hosts file" + newFile, @@ -448,10 +446,10 @@ public void testSshModifiedHostKeyAllow() throws Exception { "IdentityFile " + privateKey1.getAbsolutePath()); // File should not have been updated! String[] oldLines = Files - .readAllLines(backup.toPath(), StandardCharsets.UTF_8) + .readAllLines(backup.toPath(), UTF_8) .toArray(new String[0]); String[] newLines = Files - .readAllLines(knownHosts.toPath(), StandardCharsets.UTF_8) + .readAllLines(knownHosts.toPath(), UTF_8) .toArray(new String[0]); assertArrayEquals("Known hosts file should not be modified", oldLines, newLines); diff --git a/org.eclipse.jgit.test/src/org/eclipse/jgit/transport/ssh/SshTestHarness.java b/org.eclipse.jgit.test/src/org/eclipse/jgit/transport/ssh/SshTestHarness.java index 59925a5a1..ada16b75e 100644 --- a/org.eclipse.jgit.test/src/org/eclipse/jgit/transport/ssh/SshTestHarness.java +++ b/org.eclipse.jgit.test/src/org/eclipse/jgit/transport/ssh/SshTestHarness.java @@ -42,6 +42,8 @@ */ package org.eclipse.jgit.transport.ssh; +import static java.nio.charset.StandardCharsets.US_ASCII; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; @@ -54,7 +56,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.ArrayList; import java.util.Arrays; @@ -150,7 +151,7 @@ public void setUp() throws Exception { knownHosts = new File(sshDir, "known_hosts"); Files.write(knownHosts.toPath(), Collections.singleton("[localhost]:" + testPort + ' ' - + publicHostKey.toString(StandardCharsets.US_ASCII.name()))); + + publicHostKey.toString(US_ASCII.name()))); factory = createSessionFactory(); SshSessionFactory.setInstance(factory); } @@ -200,8 +201,7 @@ private static byte[] createHostKey(OutputStream publicKey) */ protected static String createKnownHostsFile(File file, String host, int port, File publicKey) throws IOException { - List lines = Files.readAllLines(publicKey.toPath(), - StandardCharsets.UTF_8); + List lines = Files.readAllLines(publicKey.toPath(), UTF_8); assertEquals("Public key has too many lines", 1, lines.size()); String pubKey = lines.get(0); // Strip off the comment.