diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DescribeCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DescribeCommandTest.java index a422ef91c..bb0714d23 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DescribeCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DescribeCommandTest.java @@ -42,13 +42,15 @@ */ package org.eclipse.jgit.api; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import java.io.BufferedWriter; import java.io.File; -import java.io.FileWriter; import java.io.IOException; +import java.nio.file.Files; import java.util.Arrays; import java.util.Collection; @@ -404,7 +406,7 @@ public class DescribeCommandTest extends RepositoryTestCase { } private static void touch(File f, String contents) throws Exception { - try (FileWriter w = new FileWriter(f)) { + try (BufferedWriter w = Files.newBufferedWriter(f.toPath(), UTF_8)) { w.write(contents); } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileRepositoryBuilderTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileRepositoryBuilderTest.java index deffa04b5..3697050bb 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileRepositoryBuilderTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileRepositoryBuilderTest.java @@ -43,14 +43,16 @@ package org.eclipse.jgit.internal.storage.file; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.io.BufferedWriter; import java.io.File; -import java.io.FileWriter; import java.io.IOException; +import java.nio.file.Files; import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase; import org.eclipse.jgit.lib.ConfigConstants; @@ -120,7 +122,8 @@ public class FileRepositoryBuilderTest extends LocalDiskRepositoryTestCase { Repository repo1 = createWorkRepository(); File dir = createTempDirectory("dir"); File dotGit = new File(dir, Constants.DOT_GIT); - try (FileWriter writer = new FileWriter(dotGit)) { + try (BufferedWriter writer = Files.newBufferedWriter(dotGit.toPath(), + UTF_8)) { writer.append("gitdir: " + repo1.getDirectory().getAbsolutePath()).close(); FileRepositoryBuilder builder = new FileRepositoryBuilder(); @@ -140,7 +143,8 @@ public class FileRepositoryBuilderTest extends LocalDiskRepositoryTestCase { File dir = new File(repo1.getWorkTree(), "dir"); assertTrue(dir.mkdir()); File dotGit = new File(dir, Constants.DOT_GIT); - try (FileWriter writer = new FileWriter(dotGit)) { + try (BufferedWriter writer = Files.newBufferedWriter(dotGit.toPath(), + UTF_8)) { writer.append("gitdir: ../" + Constants.DOT_GIT).close(); FileRepositoryBuilder builder = new FileRepositoryBuilder(); @@ -161,7 +165,8 @@ public class FileRepositoryBuilderTest extends LocalDiskRepositoryTestCase { Repository repo1 = createWorkRepository(); File dir = createTempDirectory("dir"); File dotGit = new File(dir, Constants.DOT_GIT); - try (FileWriter writer = new FileWriter(dotGit)) { + try (BufferedWriter writer = Files.newBufferedWriter(dotGit.toPath(), + UTF_8)) { writer.append( "gitdir: " + repo1.getDirectory().getAbsolutePath()).close(); FileRepositoryBuilder builder = new FileRepositoryBuilder(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java index fed22c026..a0cd37ee5 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java @@ -42,6 +42,7 @@ */ package org.eclipse.jgit.submodule; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_PATH; import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_URL; import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_SUBMODULE_SECTION; @@ -52,9 +53,10 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import java.io.BufferedWriter; import java.io.File; -import java.io.FileWriter; import java.io.IOException; +import java.nio.file.Files; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Status; @@ -155,10 +157,12 @@ public class SubmoduleWalkTest extends RepositoryTestCase { if (!dotGit.getParentFile().exists()) dotGit.getParentFile().mkdirs(); - File modulesGitDir = new File(db.getDirectory(), "modules" - + File.separatorChar + path); - new FileWriter(dotGit).append( - "gitdir: " + modulesGitDir.getAbsolutePath()).close(); + File modulesGitDir = new File(db.getDirectory(), + "modules" + File.separatorChar + path); + try (BufferedWriter fw = Files.newBufferedWriter(dotGit.toPath(), + UTF_8)) { + fw.append("gitdir: " + modulesGitDir.getAbsolutePath()); + } FileRepositoryBuilder builder = new FileRepositoryBuilder(); builder.setWorkTree(new File(db.getWorkTree(), path)); builder.build().create(); @@ -209,9 +213,11 @@ public class SubmoduleWalkTest extends RepositoryTestCase { File modulesGitDir = new File(db.getDirectory(), "modules" + File.separatorChar + path); - new FileWriter(dotGit).append( - "gitdir: " + "../" + Constants.DOT_GIT + "/modules/" + path) - .close(); + try (BufferedWriter fw = Files.newBufferedWriter(dotGit.toPath(), + UTF_8)) { + fw.append("gitdir: " + "../" + Constants.DOT_GIT + "/modules/" + + path); + } FileRepositoryBuilder builder = new FileRepositoryBuilder(); builder.setWorkTree(new File(db.getWorkTree(), path)); builder.build().create();