Browse Source

Explicitly specify charset when constructing PrintWriter

Change-Id: Ie1631784b5eba04edb21f66df284f9e279fd2ec0
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
stable-5.2
David Pursehouse 6 years ago
parent
commit
a97e79d95d
  1. 5
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/RegexPipelineTest.java
  2. 65
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java
  3. 10
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTest.java
  4. 7
      org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java
  5. 6
      org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java

5
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/RegexPipelineTest.java

@ -47,8 +47,10 @@ import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URI;
@ -83,7 +85,8 @@ public class RegexPipelineTest extends HttpTestCase {
protected void doGet(HttpServletRequest req, HttpServletResponse res)
throws IOException {
res.setStatus(200);
PrintWriter out = new PrintWriter(res.getOutputStream());
PrintWriter out = new PrintWriter(new BufferedWriter(
new OutputStreamWriter(res.getOutputStream(), UTF_8)));
out.write(name);
out.write("\n");
out.write(String.valueOf(req.getServletPath()));

65
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java

@ -43,6 +43,7 @@
*/
package org.eclipse.jgit.api;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.eclipse.jgit.util.FileUtils.RECURSIVE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@ -118,7 +119,7 @@ public class AddCommandTest extends RepositoryTestCase {
public void testAddExistingSingleFile() throws IOException, GitAPIException {
File file = new File(db.getWorkTree(), "a.txt");
FileUtils.createNewFile(file);
try (PrintWriter writer = new PrintWriter(file)) {
try (PrintWriter writer = new PrintWriter(file, UTF_8.name())) {
writer.print("content");
}
@ -489,7 +490,7 @@ public class AddCommandTest extends RepositoryTestCase {
GitAPIException {
File file = new File(db.getWorkTree(), "a.txt");
FileUtils.createNewFile(file);
try (PrintWriter writer = new PrintWriter(file)) {
try (PrintWriter writer = new PrintWriter(file, UTF_8.name())) {
writer.print("row1\r\nrow2");
}
@ -519,7 +520,7 @@ public class AddCommandTest extends RepositoryTestCase {
data.append("row1\r\nrow2");
}
String crData = data.toString();
try (PrintWriter writer = new PrintWriter(file)) {
try (PrintWriter writer = new PrintWriter(file, UTF_8.name())) {
writer.print(crData);
}
String lfData = data.toString().replaceAll("\r", "");
@ -544,7 +545,7 @@ public class AddCommandTest extends RepositoryTestCase {
GitAPIException {
File file = new File(db.getWorkTree(), "a.txt");
FileUtils.createNewFile(file);
try (PrintWriter writer = new PrintWriter(file)) {
try (PrintWriter writer = new PrintWriter(file, UTF_8.name())) {
writer.print("row1\r\nrow2\u0000");
}
@ -570,7 +571,7 @@ public class AddCommandTest extends RepositoryTestCase {
FileUtils.mkdir(new File(db.getWorkTree(), "sub"));
File file = new File(db.getWorkTree(), "sub/a.txt");
FileUtils.createNewFile(file);
try (PrintWriter writer = new PrintWriter(file)) {
try (PrintWriter writer = new PrintWriter(file, UTF_8.name())) {
writer.print("content");
}
@ -588,7 +589,7 @@ public class AddCommandTest extends RepositoryTestCase {
GitAPIException {
File file = new File(db.getWorkTree(), "a.txt");
FileUtils.createNewFile(file);
try (PrintWriter writer = new PrintWriter(file)) {
try (PrintWriter writer = new PrintWriter(file, UTF_8.name())) {
writer.print("content");
}
@ -597,7 +598,7 @@ public class AddCommandTest extends RepositoryTestCase {
dc.getEntry(0).getObjectId();
try (PrintWriter writer = new PrintWriter(file)) {
try (PrintWriter writer = new PrintWriter(file, UTF_8.name())) {
writer.print("other content");
}
@ -613,7 +614,7 @@ public class AddCommandTest extends RepositoryTestCase {
public void testAddExistingSingleFileTwiceWithCommit() throws Exception {
File file = new File(db.getWorkTree(), "a.txt");
FileUtils.createNewFile(file);
try (PrintWriter writer = new PrintWriter(file)) {
try (PrintWriter writer = new PrintWriter(file, UTF_8.name())) {
writer.print("content");
}
@ -624,7 +625,7 @@ public class AddCommandTest extends RepositoryTestCase {
git.commit().setMessage("commit a.txt").call();
try (PrintWriter writer = new PrintWriter(file)) {
try (PrintWriter writer = new PrintWriter(file, UTF_8.name())) {
writer.print("other content");
}
@ -640,7 +641,7 @@ public class AddCommandTest extends RepositoryTestCase {
public void testAddRemovedFile() throws Exception {
File file = new File(db.getWorkTree(), "a.txt");
FileUtils.createNewFile(file);
try (PrintWriter writer = new PrintWriter(file)) {
try (PrintWriter writer = new PrintWriter(file, UTF_8.name())) {
writer.print("content");
}
@ -663,7 +664,7 @@ public class AddCommandTest extends RepositoryTestCase {
public void testAddRemovedCommittedFile() throws Exception {
File file = new File(db.getWorkTree(), "a.txt");
FileUtils.createNewFile(file);
try (PrintWriter writer = new PrintWriter(file)) {
try (PrintWriter writer = new PrintWriter(file, UTF_8.name())) {
writer.print("content");
}
@ -690,13 +691,13 @@ public class AddCommandTest extends RepositoryTestCase {
File file = new File(db.getWorkTree(), "a.txt");
FileUtils.createNewFile(file);
try (PrintWriter writer = new PrintWriter(file)) {
try (PrintWriter writer = new PrintWriter(file, UTF_8.name())) {
writer.print("content");
}
File file2 = new File(db.getWorkTree(), "b.txt");
FileUtils.createNewFile(file2);
try (PrintWriter writer = new PrintWriter(file2)) {
try (PrintWriter writer = new PrintWriter(file2, UTF_8.name())) {
writer.print("content b");
}
@ -707,12 +708,12 @@ public class AddCommandTest extends RepositoryTestCase {
addEntryToBuilder("b.txt", file2, newObjectInserter, builder, 0);
addEntryToBuilder("a.txt", file, newObjectInserter, builder, 1);
try (PrintWriter writer = new PrintWriter(file)) {
try (PrintWriter writer = new PrintWriter(file, UTF_8.name())) {
writer.print("other content");
}
addEntryToBuilder("a.txt", file, newObjectInserter, builder, 3);
try (PrintWriter writer = new PrintWriter(file)) {
try (PrintWriter writer = new PrintWriter(file, UTF_8.name())) {
writer.print("our content");
}
addEntryToBuilder("a.txt", file, newObjectInserter, builder, 2)
@ -743,13 +744,13 @@ public class AddCommandTest extends RepositoryTestCase {
public void testAddTwoFiles() throws Exception {
File file = new File(db.getWorkTree(), "a.txt");
FileUtils.createNewFile(file);
try (PrintWriter writer = new PrintWriter(file)) {
try (PrintWriter writer = new PrintWriter(file, UTF_8.name())) {
writer.print("content");
}
File file2 = new File(db.getWorkTree(), "b.txt");
FileUtils.createNewFile(file2);
try (PrintWriter writer = new PrintWriter(file2)) {
try (PrintWriter writer = new PrintWriter(file2, UTF_8.name())) {
writer.print("content b");
}
@ -767,13 +768,13 @@ public class AddCommandTest extends RepositoryTestCase {
FileUtils.mkdir(new File(db.getWorkTree(), "sub"));
File file = new File(db.getWorkTree(), "sub/a.txt");
FileUtils.createNewFile(file);
try (PrintWriter writer = new PrintWriter(file)) {
try (PrintWriter writer = new PrintWriter(file, UTF_8.name())) {
writer.print("content");
}
File file2 = new File(db.getWorkTree(), "sub/b.txt");
FileUtils.createNewFile(file2);
try (PrintWriter writer = new PrintWriter(file2)) {
try (PrintWriter writer = new PrintWriter(file2, UTF_8.name())) {
writer.print("content b");
}
@ -791,19 +792,19 @@ public class AddCommandTest extends RepositoryTestCase {
FileUtils.mkdir(new File(db.getWorkTree(), "sub"));
File file = new File(db.getWorkTree(), "sub/a.txt");
FileUtils.createNewFile(file);
try (PrintWriter writer = new PrintWriter(file)) {
try (PrintWriter writer = new PrintWriter(file, UTF_8.name())) {
writer.print("content");
}
File ignoreFile = new File(db.getWorkTree(), ".gitignore");
FileUtils.createNewFile(ignoreFile);
try (PrintWriter writer = new PrintWriter(ignoreFile)) {
try (PrintWriter writer = new PrintWriter(ignoreFile, UTF_8.name())) {
writer.print("sub/b.txt");
}
File file2 = new File(db.getWorkTree(), "sub/b.txt");
FileUtils.createNewFile(file2);
try (PrintWriter writer = new PrintWriter(file2)) {
try (PrintWriter writer = new PrintWriter(file2, UTF_8.name())) {
writer.print("content b");
}
@ -821,13 +822,13 @@ public class AddCommandTest extends RepositoryTestCase {
FileUtils.mkdir(new File(db.getWorkTree(), "sub"));
File file = new File(db.getWorkTree(), "sub/a.txt");
FileUtils.createNewFile(file);
try (PrintWriter writer = new PrintWriter(file)) {
try (PrintWriter writer = new PrintWriter(file, UTF_8.name())) {
writer.print("content");
}
File file2 = new File(db.getWorkTree(), "sub/b.txt");
FileUtils.createNewFile(file2);
try (PrintWriter writer = new PrintWriter(file2)) {
try (PrintWriter writer = new PrintWriter(file2, UTF_8.name())) {
writer.print("content b");
}
@ -849,13 +850,13 @@ public class AddCommandTest extends RepositoryTestCase {
FileUtils.mkdir(new File(db.getWorkTree(), "sub"));
File file = new File(db.getWorkTree(), "sub/a.txt");
FileUtils.createNewFile(file);
try (PrintWriter writer = new PrintWriter(file)) {
try (PrintWriter writer = new PrintWriter(file, UTF_8.name())) {
writer.print("content");
}
File file2 = new File(db.getWorkTree(), "sub/b.txt");
FileUtils.createNewFile(file2);
try (PrintWriter writer = new PrintWriter(file2)) {
try (PrintWriter writer = new PrintWriter(file2, UTF_8.name())) {
writer.print("content b");
}
@ -872,12 +873,12 @@ public class AddCommandTest extends RepositoryTestCase {
// new unstaged file sub/c.txt
File file3 = new File(db.getWorkTree(), "sub/c.txt");
FileUtils.createNewFile(file3);
try (PrintWriter writer = new PrintWriter(file3)) {
try (PrintWriter writer = new PrintWriter(file3, UTF_8.name())) {
writer.print("content c");
}
// file sub/a.txt is modified
try (PrintWriter writer = new PrintWriter(file)) {
try (PrintWriter writer = new PrintWriter(file, UTF_8.name())) {
writer.print("modified content");
}
@ -904,13 +905,13 @@ public class AddCommandTest extends RepositoryTestCase {
FileUtils.mkdir(new File(db.getWorkTree(), "sub"));
File file = new File(db.getWorkTree(), "sub/a.txt");
FileUtils.createNewFile(file);
try (PrintWriter writer = new PrintWriter(file)) {
try (PrintWriter writer = new PrintWriter(file, UTF_8.name())) {
writer.print("content");
}
File file2 = new File(db.getWorkTree(), "sub/b.txt");
FileUtils.createNewFile(file2);
try (PrintWriter writer = new PrintWriter(file2)) {
try (PrintWriter writer = new PrintWriter(file2, UTF_8.name())) {
writer.print("content b");
}
@ -927,12 +928,12 @@ public class AddCommandTest extends RepositoryTestCase {
// new unstaged file sub/c.txt
File file3 = new File(db.getWorkTree(), "sub/c.txt");
FileUtils.createNewFile(file3);
try (PrintWriter writer = new PrintWriter(file3)) {
try (PrintWriter writer = new PrintWriter(file3, UTF_8.name())) {
writer.print("content c");
}
// file sub/a.txt is modified
try (PrintWriter writer = new PrintWriter(file)) {
try (PrintWriter writer = new PrintWriter(file, UTF_8.name())) {
writer.print("modified content");
}

10
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTest.java

@ -121,7 +121,7 @@ public class CommitAndLogCommandTest extends RepositoryTestCase {
// create first file
File file = new File(db.getWorkTree(), "a.txt");
FileUtils.createNewFile(file);
try (PrintWriter writer = new PrintWriter(file)) {
try (PrintWriter writer = new PrintWriter(file, UTF_8.name())) {
writer.print("content1");
}
@ -132,7 +132,7 @@ public class CommitAndLogCommandTest extends RepositoryTestCase {
// create second file
file = new File(db.getWorkTree(), "b.txt");
FileUtils.createNewFile(file);
try (PrintWriter writer = new PrintWriter(file)) {
try (PrintWriter writer = new PrintWriter(file, UTF_8.name())) {
writer.print("content2");
}
@ -232,7 +232,7 @@ public class CommitAndLogCommandTest extends RepositoryTestCase {
JGitInternalException, GitAPIException {
File file = new File(db.getWorkTree(), "a.txt");
FileUtils.createNewFile(file);
try (PrintWriter writer = new PrintWriter(file)) {
try (PrintWriter writer = new PrintWriter(file, UTF_8.name())) {
writer.print("content");
}
@ -243,7 +243,7 @@ public class CommitAndLogCommandTest extends RepositoryTestCase {
assertEquals("6b584e8ece562ebffc15d38808cd6b98fc3d97ea",
tw.getObjectId(0).getName());
try (PrintWriter writer = new PrintWriter(file)) {
try (PrintWriter writer = new PrintWriter(file, UTF_8.name())) {
writer.print("content2");
}
commit = git.commit().setMessage("second commit").call();
@ -266,7 +266,7 @@ public class CommitAndLogCommandTest extends RepositoryTestCase {
// create file
File file = new File(db.getWorkTree(), "a.txt");
FileUtils.createNewFile(file);
try (PrintWriter writer = new PrintWriter(file)) {
try (PrintWriter writer = new PrintWriter(file, UTF_8.name())) {
writer.print("content1");
}

7
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java

@ -42,6 +42,7 @@
package org.eclipse.jgit.internal.storage.file;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@ -189,7 +190,8 @@ public class ObjectDirectoryTest extends RepositoryTestCase {
String commit = "d3148f9410b071edd4a4c85d2a43d1fa2574b0d2";
try (PrintWriter writer = new PrintWriter(
new File(repository.getDirectory(), Constants.SHALLOW))) {
new File(repository.getDirectory(), Constants.SHALLOW),
UTF_8.name())) {
writer.println(commit);
}
Set<ObjectId> shallowCommits = dir.getShallowCommits();
@ -205,7 +207,8 @@ public class ObjectDirectoryTest extends RepositoryTestCase {
String commit = "X3148f9410b071edd4a4c85d2a43d1fa2574b0d2";
try (PrintWriter writer = new PrintWriter(
new File(repository.getDirectory(), Constants.SHALLOW))) {
new File(repository.getDirectory(), Constants.SHALLOW),
UTF_8.name())) {
writer.println(commit);
}

6
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java

@ -651,7 +651,8 @@ public class WalkEncryptionTest {
Properties props = Props.discover();
props.put(AmazonS3.Keys.PASSWORD, JGIT_PASS);
props.put(AmazonS3.Keys.CRYPTO_ALG, algorithm);
try (PrintWriter writer = new PrintWriter(JGIT_CONF_FILE)) {
try (PrintWriter writer = new PrintWriter(JGIT_CONF_FILE,
UTF_8.name())) {
props.store(writer, "JGIT S3 connection configuration file.");
}
}
@ -665,7 +666,8 @@ public class WalkEncryptionTest {
static void configCreate(Properties source) throws Exception {
Properties target = Props.discover();
target.putAll(source);
try (PrintWriter writer = new PrintWriter(JGIT_CONF_FILE)) {
try (PrintWriter writer = new PrintWriter(JGIT_CONF_FILE,
UTF_8.name())) {
target.store(writer, "JGIT S3 connection configuration file.");
}
}

Loading…
Cancel
Save