当前位置: 首页>>代码示例>>Java>>正文


Java Files.append方法代码示例

本文整理汇总了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();
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:25,代码来源:TestSpoolingFileLineReader.java

示例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));
    }
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:18,代码来源:TestSpooldirSource.java

示例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);
    }
}
 
开发者ID:actiontech,项目名称:dble,代码行数:20,代码来源:ServerLoadDataInfileHandler.java

示例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);
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:14,代码来源:TestScenarioSelector.java

示例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);
}
 
开发者ID:telstra,项目名称:open-kilda,代码行数:16,代码来源:FilerBolt.java

示例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;
}
 
开发者ID:telstra,项目名称:open-kilda,代码行数:18,代码来源:FileUtil.java

示例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);

        }



}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:29,代码来源:ServerLoadDataInfileHandler.java

示例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();
    }
}
 
开发者ID:DianoxDragon,项目名称:UltimateSpawn,代码行数:14,代码来源:FileUtils.java

示例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);

}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:44,代码来源:DefaultConfigTest.java

示例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);
}
 
开发者ID:zhangjunfang,项目名称:util,代码行数:7,代码来源:FileUtil.java


注:本文中的com.google.common.io.Files.append方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。