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


Java Files.write方法代码示例

本文整理汇总了Java中com.google.common.io.Files.write方法的典型用法代码示例。如果您正苦于以下问题:Java Files.write方法的具体用法?Java Files.write怎么用?Java Files.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.io.Files的用法示例。


在下文中一共展示了Files.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: should_read_files_in_directory

import com.google.common.io.Files; //导入方法依赖的package包/类
@Test
public void should_read_files_in_directory() throws IOException {
    // Given a temp directory that contains
    File tempDir = Files.createTempDir();
    tempDir.deleteOnExit();
    // json file
    File file1 = File.createTempFile("file1", ".json", tempDir);
    String content1 = "content1";
    Files.write(content1.getBytes(), file1);
    // n1ql file
    File file2 = File.createTempFile("file2", ".N1QL", tempDir);
    String content2 = "content2";
    Files.write(content2.getBytes(), file2);
    // txt file
    Files.write(getRandomString().getBytes(), File.createTempFile(getRandomString(), ".txt", tempDir));

    // When we read files in this directory with extension filter
    Map<String, String> result = FileUtils.readFilesInDirectory(tempDir.toPath(), "json", "n1ql");

    // Then we should have file content matching this extension
    Assert.assertEquals(2, result.size());
    Assert.assertEquals(content1, result.get(file1.getName()));
    Assert.assertEquals(content2, result.get(file2.getName()));
}
 
开发者ID:differentway,项目名称:couchmove,代码行数:25,代码来源:FileUtilsTest.java

示例2: complicatedSelfHost

import com.google.common.io.Files; //导入方法依赖的package包/类
@Test
public void complicatedSelfHost() throws IOException {
  File yaml = new File("test-files/complicatedSelfHost/cmakeify.yml");
  yaml.getParentFile().mkdirs();
  Files.write("includes: [extra-includes]\n" +
          "android:\n" +
          "  flavors:\n" +
          "    myflags:\n" +
          "      - -DANDROID\n" +
          "  lib: libbob.a\n" +
          "  ndk:\n" +
          "    platforms: [21, 22]\n",
      yaml, StandardCharsets.UTF_8);
  String result1 = main("-wf", yaml.getParent(), "--dump");
  yaml.delete();
  Files.write(result1, yaml, StandardCharsets.UTF_8);
  System.out.print(result1);
  String result2 = main("-wf", yaml.getParent(), "--dump");
  assertThat(result2).isEqualTo(result1);
  assertThat(result2).contains("-DANDROID");
  assertThat(result2).doesNotContain("default-flavor");
}
 
开发者ID:jomof,项目名称:cmakeify,代码行数:23,代码来源:TestCmakeify.java

示例3: mergeHeaders

import com.google.common.io.Files; //导入方法依赖的package包/类
@Test
public void mergeHeaders() throws Exception {
  File output = new File(".test-files/mergeHeaders/merged-manifest.yml");
  File zip = new File(".test-files/mergeHeaders/headers.zip");
  zip.getParentFile().mkdirs();
  Files.write("xyz", zip, StandardCharsets.UTF_8);
  output.delete();
  String text = main("merge", "headers",
      "com.github.jomof:sqlite:3.16.2-rev48",
      zip.toString(),
      "include",
      output.toString());
  assertThat(text).doesNotContain("Usage");
  assertThat(text).contains("Merged com.github.jomof:sqlite:3.16.2-rev48 and ");
  System.out.printf(text);
  System.out.printf(FileUtils.readAllText(output));
}
 
开发者ID:jomof,项目名称:cdep,代码行数:18,代码来源:TestCDep.java

示例4: unfindableLocalFile

import com.google.common.io.Files; //导入方法依赖的package包/类
@Test
public void unfindableLocalFile() throws Exception {
  CDepYml config = new CDepYml();
  System.out.printf(new Yaml().dump(config));
  File yaml = new File(".test-files/unfindableLocalFile/cdep.yml");
  yaml.getParentFile().mkdirs();
  Files.write("builders: [cmake, cmakeExamples]\ndependencies:\n- compile: ../not-a-file/cdep-manifest.yml\n",
      yaml, StandardCharsets.UTF_8);

  try {
    main("-wf", yaml.getParent());
    fail("Expected failure");
  } catch (RuntimeException e) {
    assertThat(e).hasMessage("Could not resolve '../not-a-file/cdep-manifest.yml'. It doesn't exist.");
  }
}
 
开发者ID:jomof,项目名称:cdep,代码行数:17,代码来源:TestCDep.java

示例5: testLifecycle

import com.google.common.io.Files; //导入方法依赖的package包/类
@Test
public void testLifecycle() throws IOException, InterruptedException {
  File f1 = new File(tmpDir, "file1");
  Files.write("file1line1\nfile1line2\n", f1, Charsets.UTF_8);

  Context context = new Context();
  context.put(POSITION_FILE, posFilePath);
  context.put(FILE_GROUPS, "f1");
  context.put(FILE_GROUPS_PREFIX + "f1", tmpDir.getAbsolutePath() + "/file1$");
  Configurables.configure(source, context);

  for (int i = 0; i < 3; i++) {
    source.start();
    source.process();
    assertTrue("Reached start or error", LifecycleController.waitForOneOf(
        source, LifecycleState.START_OR_ERROR));
    assertEquals("Server is started", LifecycleState.START,
        source.getLifecycleState());

    source.stop();
    assertTrue("Reached stop or error",
        LifecycleController.waitForOneOf(source, LifecycleState.STOP_OR_ERROR));
    assertEquals("Server is stopped", LifecycleState.STOP,
        source.getLifecycleState());
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:27,代码来源:TestTaildirSource.java

示例6: checkThatHashesWork

import com.google.common.io.Files; //导入方法依赖的package包/类
@Test
public void checkThatHashesWork() throws Exception {
  File yaml = new File(".test-files/checkThatHashesWork/cdep.yml");
  yaml.getParentFile().mkdirs();
  Files.write("builders: [cmake, cmakeExamples]\ndependencies:\n- compile: com.github" +
      ".jomof:low-level-statistics:0.0.16\n", yaml, StandardCharsets.UTF_8);
  File hashes = new File(".test-files/checkThatHashesWork/cdep.sha256");
  Files.write("- coordinate: com.github.jomof:low-level-statistics:0.0.16\n  " +
      "sha256: dogbone", hashes, StandardCharsets.UTF_8);
  try {
    main("-wf", yaml.getParent());
    fail("Expected failure");
  } catch (RuntimeException e) {
    assertThat(e).hasMessage("SHA256 of cdep-manifest.yml for package 'com.github.jomof:low-level-statistics:0.0.16' " +
        "does not agree with constant in cdep.sha256. Something changed.");
  }
}
 
开发者ID:jomof,项目名称:cdep,代码行数:18,代码来源:TestCDep.java

示例7: saveHistory

import com.google.common.io.Files; //导入方法依赖的package包/类
/**
 * Saves the projects history.
 */

public final void saveHistory() {
	try {
		final StringBuilder builder = new StringBuilder();
		for(int i = 0; i < projectsModel.size(); i++) {
			builder.append(projectsModel.getElementAt(i) + System.lineSeparator());
		}
		Files.write(builder.toString(), new File(Utils.getParentFolder(), Constants.FILE_GUI_HISTORY), StandardCharsets.UTF_8);
	}
	catch(final Exception ex) {
		ex.printStackTrace(guiPrintStream);
		ex.printStackTrace();
		JOptionPane.showMessageDialog(ProjectsFrame.this, String.format(Constants.GUI_DIALOG_ERROR_MESSAGE, ex.getMessage()), ex.getClass().getName(), JOptionPane.ERROR_MESSAGE);
	}
}
 
开发者ID:Skyost,项目名称:SkyDocs,代码行数:19,代码来源:ProjectsFrame.java

示例8: testBadFile

import com.google.common.io.Files; //导入方法依赖的package包/类
@Test(timeout=60000)
public void testBadFile() throws IOException {
  File mapFile = File.createTempFile(getClass().getSimpleName() +
      ".testBadFile", ".txt");
  Files.write("bad contents", mapFile, Charsets.UTF_8);
  mapFile.deleteOnExit();
  TableMapping mapping = new TableMapping();

  Configuration conf = new Configuration();
  conf.set(NET_TOPOLOGY_TABLE_MAPPING_FILE_KEY, mapFile.getCanonicalPath());
  mapping.setConf(conf);

  List<String> names = new ArrayList<String>();
  names.add(hostName1);
  names.add(hostName2);

  List<String> result = mapping.resolve(names);
  assertEquals(names.size(), result.size());
  assertEquals(result.get(0), NetworkTopology.DEFAULT_RACK);
  assertEquals(result.get(1), NetworkTopology.DEFAULT_RACK);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:22,代码来源:TestTableMapping.java

示例9: testClearingCachedMappings

import com.google.common.io.Files; //导入方法依赖的package包/类
@Test
public void testClearingCachedMappings() throws IOException {
  File mapFile = File.createTempFile(getClass().getSimpleName() +
      ".testClearingCachedMappings", ".txt");
  Files.write(hostName1 + " /rack1\n" +
              hostName2 + "\t/rack2\n", mapFile, Charsets.UTF_8);
  mapFile.deleteOnExit();

  TableMapping mapping = new TableMapping();

  Configuration conf = new Configuration();
  conf.set(NET_TOPOLOGY_TABLE_MAPPING_FILE_KEY, mapFile.getCanonicalPath());
  mapping.setConf(conf);

  List<String> names = new ArrayList<String>();
  names.add(hostName1);
  names.add(hostName2);

  List<String> result = mapping.resolve(names);
  assertEquals(names.size(), result.size());
  assertEquals("/rack1", result.get(0));
  assertEquals("/rack2", result.get(1));

  Files.write("", mapFile, Charsets.UTF_8);

  mapping.reloadCachedMappings();

  names = new ArrayList<String>();
  names.add(hostName1);
  names.add(hostName2);

  result = mapping.resolve(names);
  assertEquals(names.size(), result.size());
  assertEquals(NetworkTopology.DEFAULT_RACK, result.get(0));
  assertEquals(NetworkTopology.DEFAULT_RACK, result.get(1));
}
 
开发者ID:naver,项目名称:hadoop,代码行数:37,代码来源:TestTableMapping.java

示例10: testDestinationExistsAndSameFileNotOnWindows

import com.google.common.io.Files; //导入方法依赖的package包/类
@Test(expected = IllegalStateException.class)
public void testDestinationExistsAndSameFileNotOnWindows() throws IOException {
  System.setProperty("os.name", "Some version of Linux");

  File f1 = new File(tmpDir.getAbsolutePath() + "/file1");
  File f1Completed = new File(tmpDir.getAbsolutePath() + "/file1" +
      completedSuffix);

  Files.write("file1line1\nfile1line2\n", f1, Charsets.UTF_8);
  Files.write("file1line1\nfile1line2\n", f1Completed, Charsets.UTF_8);

  ReliableSpoolingFileEventReader parser = getParser();

  List<String> out = Lists.newArrayList();

  for (int i = 0; i < 2; i++) {
    out.add(bodyAsString(parser.readEvent()));
    parser.commit();
  }

  File f2 = new File(tmpDir.getAbsolutePath() + "/file2");
  Files.write("file2line1\nfile2line2\n", f2, Charsets.UTF_8);

  for (int i = 0; i < 2; i++) {
    out.add(bodyAsString(parser.readEvent()));
    parser.commit();
  }

  // Not reached
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:31,代码来源:TestSpoolingFileLineReader.java

示例11: setup

import com.google.common.io.Files; //导入方法依赖的package包/类
@Before
public void setup() throws Exception {
  baseDir = Files.createTempDir();
  keyStorePasswordFile = new File(baseDir, "keyStorePasswordFile");
  Files.write("keyStorePassword", keyStorePasswordFile, Charsets.UTF_8);
  keyAliasPassword = Maps.newHashMap();
  keyStoreFile = new File(baseDir, "keyStoreFile");
  Assert.assertTrue(keyStoreFile.createNewFile());

}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:11,代码来源:TestJCEFileKeyProvider.java

示例12: testBadKeyStorePassword

import com.google.common.io.Files; //导入方法依赖的package包/类
@Test
public void testBadKeyStorePassword() throws Exception {
  Files.write("invalid", keyStorePasswordFile, Charsets.UTF_8);
  Map<String, String> overrides = getOverridesForEncryption();
  try {
    channel = TestUtils.createFileChannel(checkpointDir.getAbsolutePath(),
        dataDir, overrides);
    Assert.fail();
  } catch (RuntimeException ex) {
    Assert.assertEquals("java.io.IOException: Keystore was tampered with, or " +
        "password was incorrect", ex.getMessage());
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:14,代码来源:TestFileChannelEncryption.java

示例13: dump

import com.google.common.io.Files; //导入方法依赖的package包/类
@Override
public void dump() {
    try {
        Files.write(GSON.toJson(pluginCache).getBytes(), storePath.toFile());
        LOGGER.trace("Plugin data been dumped to path: " + storePath);
    } catch (IOException e) {
        throw new PluginException(e.getMessage());
    }
}
 
开发者ID:FlowCI,项目名称:flow-platform,代码行数:10,代码来源:PluginDaoImpl.java

示例14: testTableCaching

import com.google.common.io.Files; //导入方法依赖的package包/类
@Test
public void testTableCaching() throws IOException {
  File mapFile = File.createTempFile(getClass().getSimpleName() +
      ".testTableCaching", ".txt");
  Files.write(hostName1 + " /rack1\n" +
      hostName2 + "\t/rack2\n", mapFile, Charsets.UTF_8);
  mapFile.deleteOnExit();
  TableMapping mapping = new TableMapping();

  Configuration conf = new Configuration();
  conf.set(NET_TOPOLOGY_TABLE_MAPPING_FILE_KEY, mapFile.getCanonicalPath());
  mapping.setConf(conf);

  List<String> names = new ArrayList<String>();
  names.add(hostName1);
  names.add(hostName2);

  List<String> result1 = mapping.resolve(names);
  assertEquals(names.size(), result1.size());
  assertEquals("/rack1", result1.get(0));
  assertEquals("/rack2", result1.get(1));

  // unset the file, see if it gets read again
  conf.set(NET_TOPOLOGY_TABLE_MAPPING_FILE_KEY, "some bad value for a file");

  List<String> result2 = mapping.resolve(names);
  assertEquals(result1, result2);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:29,代码来源:TestTableMapping.java

示例15: testDestinationExistsAndDifferentFile

import com.google.common.io.Files; //导入方法依赖的package包/类
@Test(expected = IllegalStateException.class)
public void testDestinationExistsAndDifferentFile() throws IOException {
  File f1 = new File(tmpDir.getAbsolutePath() + "/file1");
  File f1Completed =
      new File(tmpDir.getAbsolutePath() + "/file1" + completedSuffix);

  Files.write("file1line1\nfile1line2\n", f1, Charsets.UTF_8);
  Files.write("file1line1\nfile1XXXe2\n", f1Completed, Charsets.UTF_8);

  ReliableSpoolingFileEventReader parser = getParser();

  List<String> out = Lists.newArrayList();

  for (int i = 0; i < 2; i++) {
    out.add(bodyAsString(parser.readEvent()));
    parser.commit();
  }

  File f2 = new File(tmpDir.getAbsolutePath() + "/file2");
  Files.write("file2line1\nfile2line2\n", f2, Charsets.UTF_8);

  for (int i = 0; i < 2; i++) {
    out.add(bodyAsString(parser.readEvent()));
    parser.commit();
  }
  // Not reached
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:28,代码来源:TestSpoolingFileLineReader.java


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