Merge branch 'stable-2.14' into stable-2.15
* stable-2.14:
CreateServiceUserCommand: Don't concatenate Strings in a loop
Use StandardCharsets.UTF_8 instead of "UTF-8" string
Format Java files with google-java-format 1.6
Change-Id: I3d0bdafc522652c87e699964831ae7e7a18f9197
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/CreateServiceUserCommand.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/CreateServiceUserCommand.java
index c102c50..1b6d925 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/CreateServiceUserCommand.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/CreateServiceUserCommand.java
@@ -14,6 +14,8 @@
package com.googlesource.gerrit.plugins.serviceuser;
+import static java.nio.charset.StandardCharsets.UTF_8;
+
import com.google.gerrit.extensions.annotations.RequiresCapability;
import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.server.config.ConfigResource;
@@ -24,7 +26,6 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
-import java.io.UnsupportedEncodingException;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.Option;
@@ -37,11 +38,10 @@
private String username;
@Option(
- name = "--ssh-key",
- required = true,
- metaVar = "-|KEY",
- usage = "public key for SSH authentication"
- )
+ name = "--ssh-key",
+ required = true,
+ metaVar = "-|KEY",
+ usage = "public key for SSH authentication")
private String sshKey;
@Inject private CreateServiceUser.Factory createServiceUser;
@@ -58,17 +58,18 @@
}
}
- private String readSshKey() throws UnsupportedEncodingException, IOException {
+ private String readSshKey() throws IOException {
if (sshKey == null) {
return null;
}
if ("-".equals(sshKey)) {
- sshKey = "";
- BufferedReader br = new BufferedReader(new InputStreamReader(in, "UTF-8"));
+ StringBuilder key = new StringBuilder();
+ BufferedReader br = new BufferedReader(new InputStreamReader(in, UTF_8));
String line;
while ((line = br.readLine()) != null) {
- sshKey += line + "\n";
+ key.append(line).append("\n");
}
+ sshKey = key.toString();
}
return sshKey;
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/CreateServiceUserNotes.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/CreateServiceUserNotes.java
index d4faca9..31333fd 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/CreateServiceUserNotes.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/CreateServiceUserNotes.java
@@ -16,6 +16,7 @@
import static com.googlesource.gerrit.plugins.serviceuser.CreateServiceUser.KEY_CREATED_BY;
import static com.googlesource.gerrit.plugins.serviceuser.CreateServiceUser.KEY_OWNER;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.eclipse.jgit.lib.Constants.OBJ_COMMIT;
import com.google.gerrit.extensions.common.AccountInfo;
@@ -153,7 +154,7 @@
private ObjectId createNoteContent(String branch, ServiceUserInfo serviceUser)
throws IOException, OrmException {
return getInserter()
- .insert(Constants.OBJ_BLOB, createServiceUserNote(branch, serviceUser).getBytes("UTF-8"));
+ .insert(Constants.OBJ_BLOB, createServiceUserNote(branch, serviceUser).getBytes(UTF_8));
}
private String createServiceUserNote(String branch, ServiceUserInfo serviceUser)