summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.lfs
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@gmail.com>2017-12-07 10:23:38 +0900
committerDavid Pursehouse <david.pursehouse@gmail.com>2017-12-07 20:02:59 +0900
commit171f84a04117cfd02446f67565073a05128777a4 (patch)
treede60805128113634bc7d92cce426db59a0a96b52 /org.eclipse.jgit.lfs
parent5f94e4430800f6e1352733a3ff684e959341984d (diff)
downloadjgit-171f84a04117cfd02446f67565073a05128777a4.tar.gz
jgit-171f84a04117cfd02446f67565073a05128777a4.zip
Use constants from StandardCharsets instead of hard-coded strings
Instead of hard-coding the charset strings "US-ASCII", "UTF-8", and "ISO-8859-1", use the corresponding constants from StandardCharsets. UnsupportedEncodingException is not thrown when the StandardCharset constants are used, so remove the now redundant handling. Because the encoding names are no longer hard-coded strings, also remove redundant $NON-NLS warning suppressions. Also replace existing usages of the constants with static imports. Change-Id: I0a4510d3d992db5e277f009a41434276f95bda4e Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Diffstat (limited to 'org.eclipse.jgit.lfs')
-rw-r--r--org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPointer.java10
-rw-r--r--org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/errors/InvalidLongObjectIdException.java9
2 files changed, 9 insertions, 10 deletions
diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPointer.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPointer.java
index 0f62025be5..56e7987443 100644
--- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPointer.java
+++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPointer.java
@@ -42,6 +42,8 @@
*/
package org.eclipse.jgit.lfs;
+import static java.nio.charset.StandardCharsets.UTF_8;
+
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
@@ -49,7 +51,6 @@ import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
-import java.nio.charset.StandardCharsets;
import java.nio.charset.UnsupportedCharsetException;
import java.util.Locale;
@@ -120,7 +121,7 @@ public class LfsPointer {
*/
public void encode(OutputStream out) {
try (PrintStream ps = new PrintStream(out, false,
- StandardCharsets.UTF_8.name())) {
+ UTF_8.name())) {
ps.print("version "); //$NON-NLS-1$
ps.print(VERSION + "\n"); //$NON-NLS-1$
ps.print("oid " + HASH_FUNCTION_NAME + ":"); //$NON-NLS-1$ //$NON-NLS-2$
@@ -129,8 +130,7 @@ public class LfsPointer {
ps.print(size + "\n"); //$NON-NLS-1$
} catch (UnsupportedEncodingException e) {
// should not happen, we are using a standard charset
- throw new UnsupportedCharsetException(
- StandardCharsets.UTF_8.name());
+ throw new UnsupportedCharsetException(UTF_8.name());
}
}
@@ -152,7 +152,7 @@ public class LfsPointer {
long sz = -1;
try (BufferedReader br = new BufferedReader(
- new InputStreamReader(in, StandardCharsets.UTF_8.name()))) {
+ new InputStreamReader(in, UTF_8))) {
for (String s = br.readLine(); s != null; s = br.readLine()) {
if (s.startsWith("#") || s.length() == 0) { //$NON-NLS-1$
continue;
diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/errors/InvalidLongObjectIdException.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/errors/InvalidLongObjectIdException.java
index 44ac317a16..ee33d905dc 100644
--- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/errors/InvalidLongObjectIdException.java
+++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/errors/InvalidLongObjectIdException.java
@@ -45,7 +45,8 @@
package org.eclipse.jgit.lfs.errors;
-import java.io.UnsupportedEncodingException;
+import static java.nio.charset.StandardCharsets.US_ASCII;
+
import java.text.MessageFormat;
import org.eclipse.jgit.lfs.internal.LfsText;
@@ -80,10 +81,8 @@ public class InvalidLongObjectIdException extends IllegalArgumentException {
private static String asAscii(byte[] bytes, int offset, int length) {
try {
- return new String(bytes, offset, length, "US-ASCII"); //$NON-NLS-1$
- } catch (UnsupportedEncodingException e2) {
- return ""; //$NON-NLS-1$
- } catch (StringIndexOutOfBoundsException e2) {
+ return new String(bytes, offset, length, US_ASCII);
+ } catch (StringIndexOutOfBoundsException e) {
return ""; //$NON-NLS-1$
}
}