本文整理汇总了Java中com.google.common.io.Files.append方法的典型用法代码示例。如果您正苦于以下问题:Java Files.append方法的具体用法?Java Files.append怎么用?Java Files.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.io.Files
的用法示例。
在下文中一共展示了Files.append方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFileChangesDuringRead
import com.google.common.io.Files; //导入方法依赖的package包/类
@Test(expected = IllegalStateException.class)
// Ensures that file immutability is enforced.
public void testFileChangesDuringRead() throws IOException {
File f1 = new File(tmpDir.getAbsolutePath() + "/file1");
Files.write("file1line1\nfile1line2\n", f1, Charsets.UTF_8);
ReliableSpoolingFileEventReader parser1 = getParser();
List<String> out = Lists.newArrayList();
out.addAll(bodiesAsStrings(parser1.readEvents(2)));
parser1.commit();
assertEquals(2, out.size());
assertTrue(out.contains("file1line1"));
assertTrue(out.contains("file1line2"));
Files.append("file1line3\n", f1, Charsets.UTF_8);
out.add(bodyAsString(parser1.readEvent()));
parser1.commit();
out.add(bodyAsString(parser1.readEvent()));
parser1.commit();
}
示例2: createInputTestFiles
import com.google.common.io.Files; //导入方法依赖的package包/类
/** Create a bunch of test files. */
private void createInputTestFiles(List<File> spoolDirs, int numFiles, int startNum)
throws IOException {
int numSpoolDirs = spoolDirs.size();
for (int dirNum = 0; dirNum < numSpoolDirs; dirNum++) {
File spoolDir = spoolDirs.get(dirNum);
for (int fileNum = startNum; fileNum < numFiles; fileNum++) {
// Stage the files on what is almost certainly the same FS partition.
File tmp = new File(spoolDir.getParent(), UUID.randomUUID().toString());
Files.append(getTestString(dirNum, fileNum), tmp, Charsets.UTF_8);
File dst = new File(spoolDir, String.format("test-file-%03d", fileNum));
// Ensure we move them into the spool directory atomically, if possible.
assertTrue(String.format("Failed to rename %s to %s", tmp, dst),
tmp.renameTo(dst));
}
}
}
示例3: saveDataToFile
import com.google.common.io.Files; //导入方法依赖的package包/类
private void saveDataToFile(LoadData data, String dnName) {
if (data.getFileName() == null) {
String dnPath = tempPath + dnName + ".txt";
data.setFileName(dnPath);
}
File dnFile = new File(data.getFileName());
try {
if (!dnFile.exists()) {
Files.createParentDirs(dnFile);
}
Files.append(joinLine(data.getData(), data), dnFile, Charset.forName(loadData.getCharset()));
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
data.setData(null);
}
}
示例4: addToScenarioList
import com.google.common.io.Files; //导入方法依赖的package包/类
private void addToScenarioList(String testId, Set<String> templates, File scenarioList, ResultsStore resultsStore) {
try {
long estimatedRuntime = getEstimatedRuntime(testId, resultsStore);
List<String> args = Lists.newArrayList();
args.add(testId);
args.add(String.valueOf(estimatedRuntime));
args.addAll(templates);
Files.touch(scenarioList);
Files.append(Joiner.on(';').join(args) + '\n', scenarioList, Charsets.UTF_8);
} catch (IOException e) {
throw new RuntimeException("Could not write to scenario list at " + scenarioList, e);
}
}
示例5: execute
import com.google.common.io.Files; //导入方法依赖的package包/类
@Override
public void execute(Tuple tuple) {
File file = getFile();
logger.debug("FILER: Writing tuple to disk: File = {}, tuple={}", file.getAbsolutePath(), tuple);
try {
// Start with just the values; determine later if the fields are needed.
//Files.append(tuple.getFields().toString(), file, Charsets.UTF_8);
Files.append(tuple.getValues().toString() + "\n", file, Charsets.UTF_8);
} catch (IOException e) {
logger.error("FILER: couldn't append to file: {}. Exception: {}. Cause: {}",
file.getAbsolutePath(), e.getMessage(), e.getCause());
}
_collector.ack(tuple);
}
示例6: append
import com.google.common.io.Files; //导入方法依赖的package包/类
/**
* Append the text. If an exception occurs, dump the text and return false.
*
* @return true if append worked, false otherwise.
*/
public boolean append(String text) {
boolean success = true;
try {
Files.append(text, getFile(), Charsets.UTF_8);
} catch (IOException e) {
success = false;
e.printStackTrace();
}
return success;
}
示例7: saveDataToFile
import com.google.common.io.Files; //导入方法依赖的package包/类
private void saveDataToFile(LoadData data,String dnName)
{
if (data.getFileName() == null)
{
String dnPath = tempPath + dnName + ".txt";
data.setFileName(dnPath);
}
File dnFile = new File(data.getFileName());
try
{
if (!dnFile.exists()) {
Files.createParentDirs(dnFile);
}
Files.append(joinLine(data.getData(),data), dnFile, Charset.forName(loadData.getCharset()));
} catch (IOException e)
{
throw new RuntimeException(e);
}finally
{
data.setData(null);
}
}
示例8: append
import com.google.common.io.Files; //导入方法依赖的package包/类
/**
* Append the specified string of data to the end of the specified file.
*
* @param data The string to append
* @param to The file to write to
*/
public static void append(String data, File to) {
try {
Files.append(data, to, Charset.forName("UTF-8"));
} catch (IOException e) {
e.printStackTrace();
}
}
示例9: testGetPropertyWithAllPropertyHierarchy
import com.google.common.io.Files; //导入方法依赖的package包/类
@Test
public void testGetPropertyWithAllPropertyHierarchy() throws Exception {
String someKey = "someKey";
String someSystemPropertyValue = "system-property-value";
String anotherKey = "anotherKey";
String someLocalFileValue = "local-file-value";
String lastKey = "lastKey";
String someResourceValue = "resource-value";
//set up system property
System.setProperty(someKey, someSystemPropertyValue);
//set up config repo
someProperties = new Properties();
someProperties.setProperty(someKey, someLocalFileValue);
someProperties.setProperty(anotherKey, someLocalFileValue);
when(configRepository.getConfig()).thenReturn(someProperties);
//set up resource file
File resourceFile = new File(someResourceDir, someNamespace + ".properties");
Files.write(someKey + "=" + someResourceValue, resourceFile, Charsets.UTF_8);
Files.append(System.getProperty("line.separator"), resourceFile, Charsets.UTF_8);
Files.append(anotherKey + "=" + someResourceValue, resourceFile, Charsets.UTF_8);
Files.append(System.getProperty("line.separator"), resourceFile, Charsets.UTF_8);
Files.append(lastKey + "=" + someResourceValue, resourceFile, Charsets.UTF_8);
DefaultConfig defaultConfig =
new DefaultConfig(someNamespace, configRepository);
String someKeyValue = defaultConfig.getProperty(someKey, null);
String anotherKeyValue = defaultConfig.getProperty(anotherKey, null);
String lastKeyValue = defaultConfig.getProperty(lastKey, null);
//clean up
System.clearProperty(someKey);
assertEquals(someSystemPropertyValue, someKeyValue);
assertEquals(someLocalFileValue, anotherKeyValue);
assertEquals(someResourceValue, lastKeyValue);
}
示例10: append
import com.google.common.io.Files; //导入方法依赖的package包/类
/**
* 追加String到File.
*/
public static void append(final CharSequence from, final File to) throws IOException {
Files.append(from, to, Charsets.UTF_8);
}