Merge branch 'stable-2.15'
* stable-2.15:
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: I6a092c00591dff27121a1f33137973b5037d6301
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 a73859c..bebd520 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.IdString;
import com.google.gerrit.extensions.restapi.RestApiException;
@@ -26,7 +28,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;
@@ -62,17 +63,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 62c01d1..c0e4c20 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;
@@ -157,7 +158,7 @@
private ObjectId createNoteContent(String branch, ServiceUserInfo serviceUser)
throws IOException, OrmException, MethodNotAllowedException, PermissionBackendException {
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)