diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2018-09-05 00:29:20 +0200 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2018-09-10 00:51:59 +0200 |
commit | f19625a1b8305c7762b57def535478f56975554f (patch) | |
tree | b2f77b097228b29ab1d960732f8e957c742b56c7 | |
parent | f0517b5f384d36718ab5b9198c2fb9b2b3735c3c (diff) | |
download | jgit-f19625a1b8305c7762b57def535478f56975554f.tar.gz jgit-f19625a1b8305c7762b57def535478f56975554f.zip |
SpotBugs: don't rely on default encoding
Change-Id: Ic42f30c564270230fc629a917be85194d27d0338
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
6 files changed, 26 insertions, 12 deletions
diff --git a/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/pgm/CLIGitCommand.java b/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/pgm/CLIGitCommand.java index 81875f11bc..9ad22ddf2e 100644 --- a/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/pgm/CLIGitCommand.java +++ b/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/pgm/CLIGitCommand.java @@ -42,11 +42,13 @@ */ package org.eclipse.jgit.pgm; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertNull; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; +import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; @@ -153,7 +155,8 @@ public class CLIGitCommand extends Main { @Override PrintWriter createErrorWriter() { - return new PrintWriter(result.err); + return new PrintWriter(new OutputStreamWriter( + result.err, UTF_8)); } @Override @@ -249,19 +252,19 @@ public class CLIGitCommand extends Main { } public String outString() { - return out.toString(); + return new String(out.toByteArray(), UTF_8); } public List<String> outLines() { - return IO.readLines(out.toString()); + return IO.readLines(outString()); } public String errString() { - return err.toString(); + return new String(err.toByteArray(), UTF_8); } public List<String> errLines() { - return IO.readLines(err.toString()); + return IO.readLines(errString()); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/ApplyCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/ApplyCommand.java index 5b84032b15..c6f3c671a9 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/ApplyCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/ApplyCommand.java @@ -42,11 +42,14 @@ */ package org.eclipse.jgit.api; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.File; import java.io.FileOutputStream; -import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; +import java.io.OutputStreamWriter; +import java.io.Writer; import java.nio.file.StandardCopyOption; import java.text.MessageFormat; import java.util.ArrayList; @@ -258,7 +261,8 @@ public class ApplyCommand extends GitCommand<ApplyResult> { if (sb.length() > 0) { sb.deleteCharAt(sb.length() - 1); } - try (FileWriter fw = new FileWriter(f)) { + try (Writer fw = new OutputStreamWriter(new FileOutputStream(f), + UTF_8)) { fw.write(sb.toString()); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheIterator.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheIterator.java index 19c916f810..6196e758a9 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheIterator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheIterator.java @@ -44,6 +44,8 @@ package org.eclipse.jgit.dircache; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.IOException; import java.io.InputStream; import java.util.Collections; @@ -75,7 +77,7 @@ import org.eclipse.jgit.util.RawParseUtils; public class DirCacheIterator extends AbstractTreeIterator { /** Byte array holding ".gitattributes" string */ private static final byte[] DOT_GIT_ATTRIBUTES_BYTES = Constants.DOT_GIT_ATTRIBUTES - .getBytes(); + .getBytes(UTF_8); /** The cache this iterator was created to walk. */ protected final DirCache cache; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java index f6ec4b90eb..c5661e5083 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java @@ -542,7 +542,7 @@ public class AmazonS3 { } buf = b.toByteArray(); if (buf.length > 0) { - err.initCause(new IOException("\n" + new String(buf))); //$NON-NLS-1$ + err.initCause(new IOException("\n" + new String(buf, UTF_8))); //$NON-NLS-1$ } } return err; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java index c43ab18c35..211707e9ad 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java @@ -44,6 +44,7 @@ package org.eclipse.jgit.transport; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.eclipse.jgit.transport.ReceiveCommand.Result.NOT_ATTEMPTED; import static org.eclipse.jgit.transport.ReceiveCommand.Result.OK; import static org.eclipse.jgit.transport.ReceiveCommand.Result.REJECTED_NONFASTFORWARD; @@ -337,7 +338,7 @@ class FetchProcess { try { if (lock.lock()) { try (Writer w = new OutputStreamWriter( - lock.getOutputStream())) { + lock.getOutputStream(), UTF_8)) { for (FetchHeadRecord h : fetchHeadUpdates) { h.write(w); result.add(h); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/NetRC.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/NetRC.java index e688f6340d..8562376aa9 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/NetRC.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/NetRC.java @@ -42,10 +42,13 @@ package org.eclipse.jgit.transport; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.BufferedReader; import java.io.File; -import java.io.FileReader; +import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStreamReader; import java.util.Collection; import java.util.HashMap; import java.util.Locale; @@ -211,7 +214,8 @@ public class NetRC { this.hosts.clear(); this.lastModified = this.netrc.lastModified(); - try (BufferedReader r = new BufferedReader(new FileReader(netrc))) { + try (BufferedReader r = new BufferedReader( + new InputStreamReader(new FileInputStream(netrc), UTF_8))) { String line = null; NetRCEntry entry = new NetRCEntry(); |