Browse Source

Consistently import constants from StandardCharsets as static

Change-Id: I143c242c0e3299323ae166a59947b1195539e6bf
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
tags/v5.3.0.201903061415-rc1
David Pursehouse 5 years ago
parent
commit
04c485b396

+ 2
- 3
org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/KnownHostEntryReader.java View File

@@ -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 @@ public class 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;

+ 4
- 5
org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/OpenSshServerKeyVerifier.java View File

@@ -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.IOException;
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 @@ public class OpenSshServerKeyVerifier
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 @@ public class OpenSshServerKeyVerifier
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) {

+ 3
- 2
org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/auth/BasicAuthentication.java View File

@@ -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 @@ public abstract class BasicAuthentication<ParameterType, TokenType>
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()) {

+ 5
- 4
org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/proxy/HttpClientConnector.java View File

@@ -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 class HttpClientConnector extends AbstractClientProxyConnector {
}

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 class HttpClientConnector extends AbstractClientProxyConnector {
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 class HttpClientConnector extends AbstractClientProxyConnector {
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] = ':';

+ 4
- 4
org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/proxy/Socks5ClientConnector.java View File

@@ -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 @@ public class Socks5ClientConnector extends AbstractClientProxyConnector {
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 class Socks5ClientConnector extends AbstractClientProxyConnector {
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,

+ 5
- 7
org.eclipse.jgit.test/src/org/eclipse/jgit/transport/ssh/SshTestBase.java View File

@@ -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 static org.junit.Assume.assumeTrue;

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 abstract class SshTestBase extends SshTestHarness {

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 @@ public abstract class SshTestBase extends SshTestHarness {
}
}
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 abstract class SshTestBase extends SshTestHarness {
"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);

+ 4
- 4
org.eclipse.jgit.test/src/org/eclipse/jgit/transport/ssh/SshTestHarness.java View File

@@ -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.FileOutputStream;
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 abstract class SshTestHarness extends RepositoryTestCase {
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 @@ public abstract class SshTestHarness extends RepositoryTestCase {
*/
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…
Cancel
Save