本文整理汇总了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");
}
示例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");
}
示例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));
}
示例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 {
}
}
示例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();
}
示例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);
}
}
示例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\"],");
}
示例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");
}
示例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);
}
示例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));
}
示例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()));
}
示例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;
}
示例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();
}
示例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());
}
示例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);
}