Consistently import constants from StandardCharsets as static
Change-Id: I143c242c0e3299323ae166a59947b1195539e6bf Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
This commit is contained in:
parent
52923e9b07
commit
04c485b396
|
@ -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<KnownHostEntry> readFromFile(Path path)
|
||||
throws IOException {
|
||||
List<KnownHostEntry> 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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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] = ':';
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<String> oldLines = Files.readAllLines(backup.toPath(),
|
||||
StandardCharsets.UTF_8);
|
||||
List<String> 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<String> newLines = Files.readAllLines(newFile.toPath(),
|
||||
StandardCharsets.UTF_8);
|
||||
List<String> 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);
|
||||
|
|
|
@ -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<String> lines = Files.readAllLines(publicKey.toPath(),
|
||||
StandardCharsets.UTF_8);
|
||||
List<String> 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.
|
||||
|
|
Loading…
Reference in New Issue