Merge "Provide a convenient read() in RepositoryTestCase"
This commit is contained in:
commit
83e7554e17
|
@ -56,6 +56,7 @@
|
||||||
|
|
||||||
import org.eclipse.jgit.storage.file.FileRepository;
|
import org.eclipse.jgit.storage.file.FileRepository;
|
||||||
import org.eclipse.jgit.util.FileUtils;
|
import org.eclipse.jgit.util.FileUtils;
|
||||||
|
import org.eclipse.jgit.util.IO;
|
||||||
import org.eclipse.jgit.util.RawParseUtils;
|
import org.eclipse.jgit.util.RawParseUtils;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -174,6 +175,27 @@ public static void write(final File f, final String body)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fully read a UTF-8 file and return as a string.
|
||||||
|
*
|
||||||
|
* @param file
|
||||||
|
* file to read the content of.
|
||||||
|
* @return UTF-8 decoded content of the file, empty string if the file
|
||||||
|
* exists but has no content.
|
||||||
|
* @throws IOException
|
||||||
|
* the file does not exist, or could not be read.
|
||||||
|
*/
|
||||||
|
public static String read(final File file) throws IOException {
|
||||||
|
final byte[] body = IO.readFully(file);
|
||||||
|
return new String(body, 0, body.length, "UTF-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String read(final FileRepository db, final String name)
|
||||||
|
throws IOException {
|
||||||
|
File file = new File(db.getWorkTree(), name);
|
||||||
|
return read(file);
|
||||||
|
}
|
||||||
|
|
||||||
public static void deleteTrashFile(final FileRepository db,
|
public static void deleteTrashFile(final FileRepository db,
|
||||||
final String name) throws IOException {
|
final String name) throws IOException {
|
||||||
File path = new File(db.getWorkTree(), name);
|
File path = new File(db.getWorkTree(), name);
|
||||||
|
|
|
@ -68,7 +68,6 @@
|
||||||
import org.eclipse.jgit.storage.file.WindowCacheConfig;
|
import org.eclipse.jgit.storage.file.WindowCacheConfig;
|
||||||
import org.eclipse.jgit.util.FS;
|
import org.eclipse.jgit.util.FS;
|
||||||
import org.eclipse.jgit.util.FileUtils;
|
import org.eclipse.jgit.util.FileUtils;
|
||||||
import org.eclipse.jgit.util.IO;
|
|
||||||
import org.eclipse.jgit.util.SystemReader;
|
import org.eclipse.jgit.util.SystemReader;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -435,19 +434,8 @@ protected void write(final File f, final String body) throws IOException {
|
||||||
JGitTestUtil.write(f, body);
|
JGitTestUtil.write(f, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Fully read a UTF-8 file and return as a string.
|
|
||||||
*
|
|
||||||
* @param f
|
|
||||||
* file to read the content of.
|
|
||||||
* @return UTF-8 decoded content of the file, empty string if the file
|
|
||||||
* exists but has no content.
|
|
||||||
* @throws IOException
|
|
||||||
* the file does not exist, or could not be read.
|
|
||||||
*/
|
|
||||||
protected String read(final File f) throws IOException {
|
protected String read(final File f) throws IOException {
|
||||||
final byte[] body = IO.readFully(f);
|
return JGitTestUtil.read(f);
|
||||||
return new String(body, 0, body.length, "UTF-8");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String[] toEnvArray(final Map<String, String> env) {
|
private static String[] toEnvArray(final Map<String, String> env) {
|
||||||
|
|
|
@ -108,6 +108,10 @@ protected File writeTrashFile(final String subdir, final String name,
|
||||||
return JGitTestUtil.writeTrashFile(db, subdir, name, data);
|
return JGitTestUtil.writeTrashFile(db, subdir, name, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String read(final String name) throws IOException {
|
||||||
|
return JGitTestUtil.read(db, name);
|
||||||
|
}
|
||||||
|
|
||||||
protected void deleteTrashFile(final String name) throws IOException {
|
protected void deleteTrashFile(final String name) throws IOException {
|
||||||
JGitTestUtil.deleteTrashFile(db, name);
|
JGitTestUtil.deleteTrashFile(db, name);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue