當前位置: 首頁>>代碼示例>>Java>>正文


Java Files.toString方法代碼示例

本文整理匯總了Java中com.google.common.io.Files.toString方法的典型用法代碼示例。如果您正苦於以下問題:Java Files.toString方法的具體用法?Java Files.toString怎麽用?Java Files.toString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.common.io.Files的用法示例。


在下文中一共展示了Files.toString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: shouldGeneratePropertiesWithValues

import com.google.common.io.Files; //導入方法依賴的package包/類
@Test
public void shouldGeneratePropertiesWithValues() throws IOException {
  final long whEtlExecId = System.currentTimeMillis();
  final Properties etlJobProperties = new Properties();
  etlJobProperties.put("p1", "v1");
  etlJobProperties.put("p2", "v2");
  etlJobProperties.put("p3", "v3");

  final File propertiesFile = createTemporaryPropertiesFile(whEtlExecId, etlJobProperties);

  // when:
  final EtlJobName etlJobName = EtlJobName.valueOf("HIVE_DATASET_METADATA_ETL");
  ConfigUtil.generateProperties(etlJobName, 2, whEtlExecId, etlJobProperties);

  // then:
  final String content = Files.toString(propertiesFile, Charset.defaultCharset());
  assertThat(content)
          .contains("p1=v1")
          .contains("p2=v2")
          .contains("p3=v3");
}
 
開發者ID:thomas-young-2013,項目名稱:wherehowsX,代碼行數:22,代碼來源:ConfigUtilTest.java

示例2: writeRules

import com.google.common.io.Files; //導入方法依賴的package包/類
@Test
public void writeRules() throws Exception {
  BzlWriter writer = new BzlWriter(new String[]{}, System.getenv("TEST_TMPDIR"));
  writer.write(createRules("x:y:1.2.3"));
  String fileContents = Files.toString(
      new File(System.getenv("TEST_TMPDIR") + "/generate_workspace.bzl"),
      Charset.defaultCharset());
  assertThat(fileContents).contains("def generated_maven_jars():\n  native.maven_jar(\n"
      + "      name = \"x_y\",\n"
      + "      artifact = \"x:y:1.2.3\",\n"
      + "  )\n");
  assertThat(fileContents).contains("def generated_java_libraries():\n  native.java_library(\n"
      + "      name = \"x_y\",\n"
      + "      visibility = [\"//visibility:public\"],\n"
      + "      exports = [\"@x_y//jar\"],\n"
      + "  )\n");
}
 
開發者ID:bazelbuild,項目名稱:migration-tooling,代碼行數:18,代碼來源:BzlWriterTest.java

示例3: readMediaDictionaryJson

import com.google.common.io.Files; //導入方法依賴的package包/類
private void readMediaDictionaryJson() throws IOException {
    //Reading file
    File mediaFile = new File(unzippedToFolder, "media");
    String mediaStr = Files.toString(mediaFile, Charset.forName("UTF-8"));

    //Parsing JSON
    //The JSON is something like this:
    //{
    // "10": "paste-61641370632193.jpg",
    // "4": "paste-81522774245377.jpg",
    // "1": "latex-0cc8b5131ccb25b20258394ebcf13773bb8b2d19.png"
    //}
    imageNamesDictionary = new HashMap<>();

    JSONObject mediaObject = new JSONObject(mediaStr);
    mediaObject.toMap()
            .forEach((key, value) -> imageNamesDictionary.put(key, (String) value));
}
 
開發者ID:slavetto,項目名稱:anki-cards-web-browser,代碼行數:19,代碼來源:APKGParser.java

示例4: proceed

import com.google.common.io.Files; //導入方法依賴的package包/類
@Override
public void proceed() {
	try {
		File f = new File(srcPath);
		if(f.isDirectory()) {
			if( FileUtils.listFiles(f).iterator().hasNext() ) {
				f = FileUtils.listFiles(f).iterator().next();
			}
		}
		response = Files.toString(f, Charset.defaultCharset());
		
	} catch (Exception e) {
		LOGGER.error("[Connector:"+getName()+"] \t Connector error: " + getType(), e);
	} finally {
	}

}
 
開發者ID:rockitconsulting,項目名稱:test.rockitizer,代碼行數:18,代碼來源:FileGetConnector.java

示例5: testProjectPushdown

import com.google.common.io.Files; //導入方法依賴的package包/類
@Test
@Ignore
public void testProjectPushdown() throws Exception {
  String[] queries = {Files.toString(FileUtils.getResourceAsFile("/store/json/project_pushdown_json_physical_plan.json"), Charsets.UTF_8)};
  long[] rowCounts = {3};
  String filename = "/store/json/schema_change_int_to_string.json";
  runTestsOnFile(filename, UserBitShared.QueryType.PHYSICAL, queries, rowCounts);

  List<QueryDataBatch> results = testPhysicalWithResults(queries[0]);
  assertEquals(1, results.size());
  // "`field_1`", "`field_3`.`inner_1`", "`field_3`.`inner_2`", "`field_4`.`inner_1`"

  RecordBatchLoader batchLoader = new RecordBatchLoader(getAllocator());
  QueryDataBatch batch = results.get(0);
  assertTrue(batchLoader.load(batch.getHeader().getDef(), batch.getData()));

  // this used to be five.  It is now three.  This is because the plan doesn't have a project.
  // Scanners are not responsible for projecting non-existent columns (as long as they project one column)
  assertEquals(3, batchLoader.getSchema().getFieldCount());
  testExistentColumns(batchLoader);

  batch.release();
  batchLoader.clear();
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:25,代碼來源:TestJsonReader.java

示例6: getPlainDoc

import com.google.common.io.Files; //導入方法依賴的package包/類
public String getPlainDoc(final Symbol docid) throws IOException {
  final File file = this.docIDToFileMap.get(docid);
  if (file != null) {
    return Files.toString(file, Charsets.UTF_8);
  } else {
    throw new RuntimeException("Don't know original text for " + docid);
  }
}
 
開發者ID:isi-nlp,項目名稱:tac-kbp-eal,代碼行數:9,代碼來源:PlainDocCache.java

示例7: writeAlias

import com.google.common.io.Files; //導入方法依賴的package包/類
@Test
public void writeAlias() throws Exception {
  BzlWriter writer = new BzlWriter(new String[]{}, System.getenv("TEST_TMPDIR"));
  writer.write(ImmutableList.of(new Rule(new DefaultArtifact("x:y:1.2.3"), "z")));
  String fileContents = Files.toString(
      new File(System.getenv("TEST_TMPDIR") + "/generate_workspace.bzl"),
      Charset.defaultCharset());
  assertThat(fileContents).doesNotContain("x:y:1.2.3");
  assertThat(fileContents).contains("exports = [\"@z//jar\"],");
}
 
開發者ID:bazelbuild,項目名稱:migration-tooling,代碼行數:11,代碼來源:BzlWriterTest.java

示例8: writeCommand

import com.google.common.io.Files; //導入方法依賴的package包/類
@Test
public void writeCommand() throws Exception {
  BzlWriter writer = new BzlWriter(new String[]{"x", "y", "z"}, System.getenv("TEST_TMPDIR"));
  writer.write(createRules());
  String fileContents = Files.toString(
      new File(System.getenv("TEST_TMPDIR") + "/generate_workspace.bzl"),
      Charset.defaultCharset());
  assertThat(fileContents).contains("# generate_workspace x y z");
}
 
開發者ID:bazelbuild,項目名稱:migration-tooling,代碼行數:10,代碼來源:BzlWriterTest.java

示例9: assertGenerated

import com.google.common.io.Files; //導入方法依賴的package包/類
private void assertGenerated(String testName)
        throws Exception
{
    File basedir = resources.getBasedir(testName);
    maven.forProject(basedir)
            .execute("verify")
            .assertErrorFreeLog();

    String expected = Resources.toString(getResource(format("expected/%s.txt", testName)), UTF_8);
    String actual = Files.toString(new File(basedir, "target/test.thrift"), UTF_8);
    assertEquals(expected, actual);
}
 
開發者ID:airlift,項目名稱:drift,代碼行數:13,代碼來源:TestIdlGeneratorIntegration.java

示例10: thenJSONResponseSimilarToFile

import com.google.common.io.Files; //導入方法依賴的package包/類
@Then("verify REST-JSON response is similar to '$file'")
public void thenJSONResponseSimilarToFile(String file) throws IOException, SAXException {
    File fileFromResources = getFileFromResourcesByFilePath(file);
    String expectedJSON = Files.toString(fileFromResources, Charset.defaultCharset());
    Response response = getVariableValue(KEY);
    String actualJSON = response.getBody().asString();
    assertJsonEquals(expectedJSON, actualJSON, when(IGNORING_VALUES));
}
 
開發者ID:tapack,項目名稱:satisfy,代碼行數:9,代碼來源:RestJSONOnlySteps.java

示例11: testGetByName

import com.google.common.io.Files; //導入方法依賴的package包/類
@Test
public void testGetByName() throws URISyntaxException, IOException  {

	Path SRC = Paths.get(ClassLoader.getSystemResource(tesfilePath).toURI());
	File srcFile = new File(SRC.toString());
	assertTrue(srcFile.exists());
	String remote = Files.toString(srcFile, Charset.defaultCharset());

	fileGetConnector.setSrcPath(SRC.toString());
	fileGetConnector.proceed();

	assertTrue(remote, remote.equals(fileGetConnector.getResponse()));

}
 
開發者ID:rockitconsulting,項目名稱:test.rockitizer,代碼行數:15,代碼來源:FileGetConnectorTest.java

示例12: loadDemoFlowYaml

import com.google.common.io.Files; //導入方法依賴的package包/類
public static String loadDemoFlowYaml(String classPath) {
    URL resource = TestBase.class.getClassLoader().getResource(classPath);
    try {
        return Files.toString(new File(resource.getFile()), Charset.forName("UTF-8"));
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
開發者ID:FlowCI,項目名稱:flow-platform,代碼行數:10,代碼來源:TestBase.java

示例13: simpleCsv

import com.google.common.io.Files; //導入方法依賴的package包/類
@Test
public void simpleCsv() throws Exception {
  // before executing the test deleting the existing CSV files in /tmp/csvtest
  Path path = new Path("/tmp/csvtest");
  if (fs.exists(path)) {
    fs.delete(path, true);
  }

  String plan = Files.toString(FileUtils.getResourceAsFile("/writer/simple_csv_writer.json"), Charsets.UTF_8);

  List<QueryDataBatch> results = testPhysicalWithResults(plan);

  RecordBatchLoader batchLoader = new RecordBatchLoader(getAllocator());

  QueryDataBatch batch = results.get(0);
  assertTrue(batchLoader.load(batch.getHeader().getDef(), batch.getData()));

  VarCharVector fragmentIdV = (VarCharVector) batchLoader.getValueAccessorById(VarCharVector.class, 0).getValueVector();
  BigIntVector recordWrittenV = (BigIntVector) batchLoader.getValueAccessorById(BigIntVector.class, 1).getValueVector();

  // expected only one row in output
  assertEquals(1, batchLoader.getRecordCount());

  assertEquals("0_0", fragmentIdV.getAccessor().getObject(0).toString());
  assertEquals(132000, recordWrittenV.getAccessor().get(0));

  // now verify csv files are written to disk
  assertTrue(fs.exists(path));

  // expect two files
  FileStatus[] fileStatuses = fs.globStatus(new Path(path.toString(), "*.csv"));
  assertTrue(2 == fileStatuses.length);

  for (QueryDataBatch b : results) {
    b.release();
  }
  batchLoader.clear();
}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:39,代碼來源:TestWriter.java

示例14: should_save_and_get_yml_success

import com.google.common.io.Files; //導入方法依賴的package包/類
@Test
public void should_save_and_get_yml_success() throws IOException {
    Job job = new Job(CommonUtil.randomId());
    ClassLoader classLoader = JobYmlDaoTest.class.getClassLoader();
    URL resource = classLoader.getResource("yml/flow.yaml");
    File path = new File(resource.getFile());
    String ymlString = Files.toString(path, AppConfig.DEFAULT_CHARSET);
    JobYml jys = new JobYml(job.getId(), ymlString);
    jobYmlDao.save(jys);
    JobYml storage = jobYmlDao.get(jys.getJobId());
    Assert.assertNotNull(storage);
    Assert.assertEquals(ymlString, storage.getFile());
}
 
開發者ID:FlowCI,項目名稱:flow-platform,代碼行數:14,代碼來源:JobYmlDaoTest.java

示例15: getResourceAsString

import com.google.common.io.Files; //導入方法依賴的package包/類
public static String getResourceAsString(String fileName) throws IOException {
  return Files.toString(getResourceAsFile(fileName), Charsets.UTF_8);
}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:4,代碼來源:FileUtils.java


注:本文中的com.google.common.io.Files.toString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。