本文整理汇总了Java中org.apache.tools.ant.util.FileUtils.readFully方法的典型用法代码示例。如果您正苦于以下问题:Java FileUtils.readFully方法的具体用法?Java FileUtils.readFully怎么用?Java FileUtils.readFully使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.tools.ant.util.FileUtils
的用法示例。
在下文中一共展示了FileUtils.readFully方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBuildfile
import org.apache.tools.ant.util.FileUtils; //导入方法依赖的package包/类
@Test
public void testBuildfile() throws IOException {
buildRule.configureProject(DIR + "/cdataoutput.xml");
if (buildRule.getProject().getProperty("cdata.inner") == null) {
// avoid endless loop
buildRule.executeTarget("run-junit");
File f = buildRule.getProject().resolveFile(REPORT);
FileReader reader = null;
try {
reader = new FileReader(f);
String content = FileUtils.readFully(reader);
assertTrue(content.indexOf("</RESPONSE>]]>"
+ "</ERROR>") > 0);
} finally {
if (reader != null) {
reader.close();
}
f.delete();
}
}
}
示例2: testLogUTF8Echo
import org.apache.tools.ant.util.FileUtils; //导入方法依赖的package包/类
@Test
public void testLogUTF8Echo() throws IOException {
Project p = new Project();
p.init();
EchoTestLogger logger = new EchoTestLogger();
p.addBuildListener(logger);
Echo echo = new Echo();
echo.setProject(p);
echo.setTaskName("testLogUTF8Echo");
echo.setMessage("\u00e4\u00a9");
removeThis = new File("abc.txt");
echo.setFile(removeThis);
echo.setEncoding("UTF-8");
echo.execute();
String x = FileUtils.readFully(new InputStreamReader(new FileInputStream(removeThis), "UTF-8"));
assertEquals(x,"\u00e4\u00a9");
}
示例3: readOutputFile
import org.apache.tools.ant.util.FileUtils; //导入方法依赖的package包/类
/**
* Reads the output file into a string
*
* @param conf
* @return
* @throws IOException
*/
public String readOutputFile(Configuration conf) throws IOException {
FileSystem localFs = FileSystem.getLocal(conf);
Path file = new Path(outputDir, "part-00000");
Reader reader = new InputStreamReader(localFs.open(file));
String r = FileUtils.readFully(reader);
reader.close();
return r;
}
示例4: readOutputFile
import org.apache.tools.ant.util.FileUtils; //导入方法依赖的package包/类
/**
* Reads the output file into a string
*
* @param conf
* @return
* @throws IOException
*/
public String readOutputFile(Configuration conf) throws IOException {
FileSystem localFs = FileSystem.getLocal(conf);
Path file = new Path(outputDir, "part-r-00000");
Reader reader = new InputStreamReader(localFs.open(file));
String r = FileUtils.readFully(reader);
reader.close();
return r;
}
示例5: getKeyRings
import org.apache.tools.ant.util.FileUtils; //导入方法依赖的package包/类
public List<String> getKeyRings() throws IOException {
List<String> keys = new ArrayList<String>();
for (Resource resource : keyrings) {
log("Include keyring: " + resource.getName());
String key = FileUtils.readFully(new InputStreamReader(resource.getInputStream(), StandardCharsets.US_ASCII));
if (key != null) {
keys.add(normalizeKey(key)); // make sure to normalize line endings
}
}
return keys;
}
示例6: testFileResourceWithFilter
import org.apache.tools.ant.util.FileUtils; //导入方法依赖的package包/类
@Test
public void testFileResourceWithFilter() {
buildRule.executeTarget("testFileResourceWithFilter");
File file1 = new File(buildRule.getProject().getProperty("to.dir") + "/fileNR.txt");
assertTrue(file1.exists());
try {
try (FileReader f = new FileReader(file1)) {
String file1Content = FileUtils.readFully(f);
assertEquals("This is file 42", file1Content);
}
} catch (IOException e) {
// no-op: not a real business error
}
}
示例7: testCopyToSymlinkedSelf
import org.apache.tools.ant.util.FileUtils; //导入方法依赖的package包/类
/**
* Tests that the {@code copy} task doesn't corrupt the source file, if the target of the copy operation is a symlink
* to the source file being copied
*
* @throws Exception if something goes wrong
* @see <a href="https://bz.apache.org/bugzilla/show_bug.cgi?id=60644">issue 60644</a>
*/
@Test
public void testCopyToSymlinkedSelf() throws Exception {
// we are only going to test against systems that support symlinks
Assume.assumeTrue("Symlinks not supported on this operating system", Os.isFamily(Os.FAMILY_UNIX));
// setup the source files to run copying against
buildRule.executeTarget("setupSelfCopyTesting");
final File testDir = new File(buildRule.getProject().getProperty("self.copy.test.root.dir"));
Assert.assertTrue(testDir + " was expected to be a directory", testDir.isDirectory());
final File srcFile = new File(testDir, "file.txt");
Assert.assertTrue("Source file " + srcFile + " was expected to be a file", srcFile.isFile());
final long originalFileSize = srcFile.length();
final String originalContent;
final BufferedReader reader = new BufferedReader(new FileReader(srcFile));
try {
originalContent = FileUtils.readFully(reader);
} finally {
reader.close();
}
Assert.assertTrue("Content missing in file " + srcFile, originalContent != null && originalContent.length() > 0);
// run the copy tests
buildRule.executeTarget("testSelfCopy");
// make sure the source file hasn't been impacted by the copy
assertSizeAndContent(srcFile, originalFileSize, originalContent);
final File symlinkedFile = new File(testDir, "sylmink-file.txt");
Assert.assertTrue(symlinkedFile + " was expected to be a file", symlinkedFile.isFile());
assertSizeAndContent(symlinkedFile, originalFileSize, originalContent);
final File symlinkedTestDir = new File(buildRule.getProject().getProperty("self.copy.test.symlinked.dir"));
Assert.assertTrue(symlinkedTestDir + " was expected to be a directory", symlinkedTestDir.isDirectory());
assertSizeAndContent(new File(symlinkedTestDir, "file.txt"), originalFileSize, originalContent);
assertSizeAndContent(new File(symlinkedTestDir, "sylmink-file.txt"), originalFileSize, originalContent);
}
示例8: assertSizeAndContent
import org.apache.tools.ant.util.FileUtils; //导入方法依赖的package包/类
private void assertSizeAndContent(final File file, final long expectedSize, final String expectedContent) throws IOException {
Assert.assertTrue(file + " was expected to be a file", file.isFile());
Assert.assertEquals("Unexpected size of file " + file, expectedSize, file.length());
final BufferedReader reader = new BufferedReader(new FileReader(file));
final String content;
try {
content = FileUtils.readFully(reader);
} finally {
reader.close();
}
Assert.assertEquals("Unexpected content in file " + file, expectedContent, content);
}
示例9: testStackTraceLineBreaks
import org.apache.tools.ant.util.FileUtils; //导入方法依赖的package包/类
@Test
public void testStackTraceLineBreaks() throws Exception {
buildRule.executeTarget("testStackTraceLineBreaks");
assertIndexCreated();
FileReader r = null;
try {
r = new FileReader(new File(buildRule.getOutputDir(), "html/sampleproject/coins/0_CoinTest.html"));
String report = FileUtils.readFully(r);
assertContains("output must contain <br>:\n" + report, "junit.framework.AssertionFailedError: DOEG<br>", report);
assertContains("#51049: output must translate line breaks:\n" + report, "cur['line.separator'] = '\\r\\n';", report);
} finally {
FileUtils.close(r);
}
}
示例10: getFileString
import org.apache.tools.ant.util.FileUtils; //导入方法依赖的package包/类
private String getFileString(String filename) throws IOException {
Reader r = null;
try {
r = new FileReader(FILE_UTILS.resolveFile(buildRule.getProject().getBaseDir(),filename));
return FileUtils.readFully(r);
}
finally {
FileUtils.close(r);
}
}
示例11: getFileContents
import org.apache.tools.ant.util.FileUtils; //导入方法依赖的package包/类
/**
* Reads the contents of a file into a String.
* @param file the file to read.
* @return the contents of the given file as a string.
* @throws IOException on error reading the file (not existing, not readable etc)
*/
public static String getFileContents(File file) throws IOException {
FileReader rdr = null;
try {
rdr = new FileReader(file);
return FileUtils.readFully(rdr);
}
finally {
if (rdr != null) {
rdr.close();
}
}
}
示例12: loadGraphQLRequest
import org.apache.tools.ant.util.FileUtils; //导入方法依赖的package包/类
public String loadGraphQLRequest(String fileName) throws IOException {
try (InputStream in = PersistentResourceFetcherTest.class.getResourceAsStream("/graphql/requests/" + fileName)) {
return FileUtils.readFully(new InputStreamReader(in));
}
}
示例13: loadGraphQLResponse
import org.apache.tools.ant.util.FileUtils; //导入方法依赖的package包/类
public String loadGraphQLResponse(String fileName) throws IOException {
try (InputStream in = PersistentResourceFetcherTest.class.getResourceAsStream("/graphql/responses/" + fileName)) {
return FileUtils.readFully(new InputStreamReader(in));
}
}
示例14: getPackages
import org.apache.tools.ant.util.FileUtils; //导入方法依赖的package包/类
public List<Map<String, Object>> getPackages() throws IOException {
List<Map<String, Object>> packages = new ArrayList<Map<String, Object>>();
for (SPK spk : spks) {
log("Include SPK: " + spk.file.getName());
// make sure file is cached locally
if (spk.url != null) {
log("Using " + spk.url);
if (!spk.file.exists()) {
spk.file.getParentFile().mkdirs();
}
if (spk.url == null) {
spk.url = spk.url;
}
Get get = new Get();
get.bindToOwner(this);
get.setQuiet(true);
get.setUseTimestamp(true);
get.setSrc(spk.url);
get.setDest(spk.file);
get.execute();
} else {
log("Using " + spk.file);
}
// import SPK INFO
Map<String, Object> info = new LinkedHashMap<String, Object>();
TarFileSet tar = new TarFileSet();
tar.setProject(getProject());
tar.setSrc(spk.file);
tar.setIncludes(INFO);
for (Resource resource : tar) {
if (INFO.equals(resource.getName())) {
String text = FileUtils.readFully(new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8));
for (String line : NEWLINE.split(text)) {
String[] s = line.split("=", 2);
if (s.length == 2) {
if (s[1].startsWith("\"") && s[1].endsWith("\"")) {
s[1] = s[1].substring(1, s[1].length() - 1);
}
importSpkInfo(info, s[0], s[1]);
}
}
}
}
log(String.format("Imported %d fields from SPK: %s", info.size(), info.keySet()));
// add thumbnails and snapshots
if (spk.thumbnail.size() > 0) {
info.put(THUMBNAIL, spk.thumbnail.toArray(new String[0]));
}
if (spk.snapshot.size() > 0) {
info.put(SNAPSHOT, spk.snapshot.toArray(new String[0]));
}
// add user-defined fields
info.putAll(spk.infoList);
// automatically generate file size and checksum fields
if (!info.containsKey(LINK)) {
info.put(LINK, spk.url);
}
info.put(MD5, md5(spk.file));
info.put(SHA256, sha256(spk.file));
info.put(SIZE, spk.file.length());
packages.add(info);
}
return packages;
}
示例15: readFully
import org.apache.tools.ant.util.FileUtils; //导入方法依赖的package包/类
/**
* Reads to the end of the stream, returning the contents as a String.
*
* @return the remaining contents of the reader, as a String
*
* @exception IOException if the underlying reader throws one during
* reading
*/
protected final String readFully() throws IOException {
return FileUtils.readFully(in, BUFFER_SIZE);
}