Explicitly specify charset when constructing FileWriter
Replace explicit construction of FileWriter with calls to the utility method Files.newBufferedWriter, which allows to specify the charset. Also convert to try-with-resource. Change-Id: I9fa3f612b9b2fc5ac12cd79d6e61ca181120dbf5 Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
This commit is contained in:
parent
62012d0bdd
commit
fa61fd6f61
|
@ -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 @@ private void tag(String tag, boolean annotatedTag) throws GitAPIException {
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 void absoluteGitDirRef() throws Exception {
|
|||
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 void relativeGitDirRef() throws Exception {
|
|||
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 void scanWithGitDirRef() throws Exception {
|
|||
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();
|
||||
|
|
|
@ -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.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 void repositoryWithRootLevelSubmoduleAbsoluteRef()
|
|||
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 void repositoryWithRootLevelSubmoduleRelativeRef()
|
|||
|
||||
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();
|
||||
|
|
Loading…
Reference in New Issue