Java Code Examples for org.apache.flink.util.FileUtils#writeFileUtf8()

The following examples show how to use org.apache.flink.util.FileUtils#writeFileUtf8() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IncrementalSSSPITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Before
public void before() throws Exception {
	resultPath = tempFolder.newFile().toURI().toString();
	File verticesFile = tempFolder.newFile();
	FileUtils.writeFileUtf8(verticesFile, IncrementalSSSPData.VERTICES);

	File edgesFile = tempFolder.newFile();
	FileUtils.writeFileUtf8(edgesFile, IncrementalSSSPData.EDGES);

	File edgesInSSSPFile = tempFolder.newFile();
	FileUtils.writeFileUtf8(edgesInSSSPFile, IncrementalSSSPData.EDGES_IN_SSSP);

	verticesPath = verticesFile.toURI().toString();
	edgesPath = edgesFile.toURI().toString();
	edgesInSSSPPath = edgesInSSSPFile.toURI().toString();
}
 
Example 2
Source File: IncrementalSSSPITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Before
public void before() throws Exception {
	resultPath = tempFolder.newFile().toURI().toString();
	File verticesFile = tempFolder.newFile();
	FileUtils.writeFileUtf8(verticesFile, IncrementalSSSPData.VERTICES);

	File edgesFile = tempFolder.newFile();
	FileUtils.writeFileUtf8(edgesFile, IncrementalSSSPData.EDGES);

	File edgesInSSSPFile = tempFolder.newFile();
	FileUtils.writeFileUtf8(edgesInSSSPFile, IncrementalSSSPData.EDGES_IN_SSSP);

	verticesPath = verticesFile.toURI().toString();
	edgesPath = edgesFile.toURI().toString();
	edgesInSSSPPath = edgesInSSSPFile.toURI().toString();
}
 
Example 3
Source File: CsvFilesystemBatchITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testParseError() throws Exception {
	String path = new URI(resultPath()).getPath();
	new File(path).mkdirs();
	File file = new File(path, "test_file");
	file.createNewFile();
	FileUtils.writeFileUtf8(file,
		"x5,5,1,1\n" +
			"x5,5,2,2,2\n" +
			"x5,5,1,1");

	check("select * from nonPartitionedTable",
		Arrays.asList(
			Row.of("x5,5,1,1"),
			Row.of("x5,5,1,1")));
}
 
Example 4
Source File: PageRankITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Before
public void before() throws Exception{
	File resultFile = tempFolder.newFile();
	//Delete file because the Scala API does not respect WriteMode set by the configuration
	resultFile.delete();
	resultPath = resultFile.toURI().toString();

	File verticesFile = tempFolder.newFile();
	FileUtils.writeFileUtf8(verticesFile, PageRankData.VERTICES);

	File edgesFile = tempFolder.newFile();
	FileUtils.writeFileUtf8(edgesFile, PageRankData.EDGES);

	verticesPath = verticesFile.toURI().toString();
	edgesPath = edgesFile.toURI().toString();
}
 
Example 5
Source File: IncrementalSSSPITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Before
public void before() throws Exception {
	resultPath = tempFolder.newFile().toURI().toString();
	File verticesFile = tempFolder.newFile();
	FileUtils.writeFileUtf8(verticesFile, IncrementalSSSPData.VERTICES);

	File edgesFile = tempFolder.newFile();
	FileUtils.writeFileUtf8(edgesFile, IncrementalSSSPData.EDGES);

	File edgesInSSSPFile = tempFolder.newFile();
	FileUtils.writeFileUtf8(edgesInSSSPFile, IncrementalSSSPData.EDGES_IN_SSSP);

	verticesPath = verticesFile.toURI().toString();
	edgesPath = edgesFile.toURI().toString();
	edgesInSSSPPath = edgesInSSSPFile.toURI().toString();
}
 
Example 6
Source File: FileCacheReadsFromBlobTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public File getFile(JobID jobId, PermanentBlobKey key) throws IOException {
	if (key.equals(permanentBlobKey)) {
		File f = temporaryFolder.newFile("cacheFile");
		FileUtils.writeFileUtf8(f, testFileContent);
		return f;
	} else {
		throw new IllegalArgumentException("This service contains only entry for " + permanentBlobKey);
	}
}
 
Example 7
Source File: TestUserClassLoaderJar.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Pack the generated UDF class into a JAR and return the path of the JAR.
 */
public static File createJarFile(File tmpDir, String jarName) throws IOException {
	// write class source code to file
	File javaFile = Paths.get(tmpDir.toString(), GENERATED_UDF_CLASS + ".java").toFile();
	//noinspection ResultOfMethodCallIgnored
	javaFile.createNewFile();
	FileUtils.writeFileUtf8(javaFile, GENERATED_UDF_CODE);

	// compile class source code
	DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
	JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
	StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
	Iterable<? extends JavaFileObject> compilationUnit =
		fileManager.getJavaFileObjectsFromFiles(Collections.singletonList(javaFile));
	JavaCompiler.CompilationTask task = compiler.getTask(
		null,
		fileManager,
		diagnostics,
		Collections.emptyList(),
		null,
		compilationUnit);
	task.call();

	// pack class file to jar
	File classFile = Paths.get(tmpDir.toString(), GENERATED_UDF_CLASS + ".class").toFile();
	File jarFile = Paths.get(tmpDir.toString(), jarName).toFile();
	JarOutputStream jos = new JarOutputStream(new FileOutputStream(jarFile));
	JarEntry jarEntry = new JarEntry(GENERATED_UDF_CLASS + ".class");
	jos.putNextEntry(jarEntry);
	byte[] classBytes = FileUtils.readAllBytes(classFile.toPath());
	jos.write(classBytes);
	jos.closeEntry();
	jos.close();

	return jarFile;
}
 
Example 8
Source File: AbstractTestBase.java    From flink with Apache License 2.0 5 votes vote down vote up
public String createTempFile(String fileName, String contents) throws IOException {
	File f = createAndRegisterTempFile(fileName);
	if (!f.getParentFile().exists()) {
		f.getParentFile().mkdirs();
	}
	f.createNewFile();
	FileUtils.writeFileUtf8(f, contents);
	return f.toURI().toString();
}
 
Example 9
Source File: StreamWindowSQLExample.java    From flink-learning with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a temporary file with the contents and returns the absolute path.
 */
private static String createTempFile(String contents) throws IOException {
	File tempFile = File.createTempFile("orders", ".csv");
	tempFile.deleteOnExit();
	FileUtils.writeFileUtf8(tempFile, contents);
	return tempFile.toURI().toString();
}
 
Example 10
Source File: AbstractTestBase.java    From flink with Apache License 2.0 5 votes vote down vote up
public String createTempFile(String fileName, String contents) throws IOException {
	File f = createAndRegisterTempFile(fileName);
	if (!f.getParentFile().exists()) {
		f.getParentFile().mkdirs();
	}
	f.createNewFile();
	FileUtils.writeFileUtf8(f, contents);
	return f.toURI().toString();
}
 
Example 11
Source File: StreamWindowSQLExample.java    From flink-learning with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a temporary file with the contents and returns the absolute path.
 */
private static String createTempFile(String contents) throws IOException {
	File tempFile = File.createTempFile("orders", ".csv");
	tempFile.deleteOnExit();
	FileUtils.writeFileUtf8(tempFile, contents);
	return tempFile.toURI().toString();
}
 
Example 12
Source File: TopSpeedWindowingExampleITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testTopSpeedWindowingExampleITCase() throws Exception {
	File inputFile = temporaryFolder.newFile();
	FileUtils.writeFileUtf8(inputFile, TopSpeedWindowingExampleData.CAR_DATA);

	final String resultPath = temporaryFolder.newFolder().toURI().toString();

	TopSpeedWindowing.main(new String[] {
		"--input", inputFile.getAbsolutePath(),
		"--output", resultPath});

	compareResultsByLinesInMemory(TopSpeedWindowingExampleData.TOP_SPEEDS, resultPath);
}
 
Example 13
Source File: SingleSourceShortestPathsITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Before
public void before() throws Exception {
	resultPath = tempFolder.newFile().toURI().toString();

	File edgesFile = tempFolder.newFile();
	FileUtils.writeFileUtf8(edgesFile, SingleSourceShortestPathsData.EDGES);
	edgesPath = edgesFile.toURI().toString();
}
 
Example 14
Source File: SingleSourceShortestPathsITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Before
public void before() throws Exception {
	resultPath = tempFolder.newFile().toURI().toString();

	File edgesFile = tempFolder.newFile();
	FileUtils.writeFileUtf8(edgesFile, SingleSourceShortestPathsData.EDGES);
	edgesPath = edgesFile.toURI().toString();
}
 
Example 15
Source File: StreamWindowSQLExample.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a temporary file with the contents and returns the absolute path.
 */
private static String createTempFile(String contents) throws IOException {
	File tempFile = File.createTempFile("orders", ".csv");
	tempFile.deleteOnExit();
	FileUtils.writeFileUtf8(tempFile, contents);
	return tempFile.toURI().toString();
}
 
Example 16
Source File: EuclideanGraphWeighingITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Before
public void before() throws Exception {
	resultPath = tempFolder.newFile().toURI().toString();
	File verticesFile = tempFolder.newFile();
	FileUtils.writeFileUtf8(verticesFile, EuclideanGraphData.VERTICES);

	File edgesFile = tempFolder.newFile();
	FileUtils.writeFileUtf8(edgesFile, EuclideanGraphData.EDGES);

	verticesPath = verticesFile.toURI().toString();
	edgesPath = edgesFile.toURI().toString();
}
 
Example 17
Source File: TopSpeedWindowingExampleITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testTopSpeedWindowingExampleITCase() throws Exception {
	File inputFile = temporaryFolder.newFile();
	FileUtils.writeFileUtf8(inputFile, TopSpeedWindowingExampleData.CAR_DATA);

	final String resultPath = temporaryFolder.newFolder().toURI().toString();

	TopSpeedWindowing.main(new String[] {
		"--input", inputFile.getAbsolutePath(),
		"--output", resultPath});

	compareResultsByLinesInMemory(TopSpeedWindowingExampleData.TOP_SPEEDS, resultPath);
}
 
Example 18
Source File: HiveTableFileInputFormatTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testSplit() throws IOException {
	File file = TEMPORARY_FOLDER.newFile();
	FileUtils.writeFileUtf8(file, "hahahahahahaha");
	FileInputSplit split = new FileInputSplit(0, new Path(file.getPath()), 0, -1, null);
	FileSplit fileSplit = HiveTableFileInputFormat.toHadoopFileSplit(split);
	Assert.assertEquals(14, fileSplit.getLength());
}
 
Example 19
Source File: PageRankITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Before
public void before() throws Exception{
	final File folder = tempFolder.newFolder();
	final File resultFile = new File(folder, UUID.randomUUID().toString());
	resultPath = resultFile.toURI().toString();

	File verticesFile = tempFolder.newFile();
	FileUtils.writeFileUtf8(verticesFile, PageRankData.VERTICES);

	File edgesFile = tempFolder.newFile();
	FileUtils.writeFileUtf8(edgesFile, PageRankData.EDGES);

	verticesPath = verticesFile.toURI().toString();
	edgesPath = edgesFile.toURI().toString();
}
 
Example 20
Source File: TupleGenerator.java    From flink with Apache License 2.0 4 votes vote down vote up
private static void insertCodeIntoFile(String code, File file) throws IOException {
	String fileContent = FileUtils.readFileUtf8(file);

	try (Scanner s = new Scanner(fileContent)) {
		StringBuilder sb = new StringBuilder();
		String line;

		boolean indicatorFound = false;

		// add file beginning
		while (s.hasNextLine() && (line = s.nextLine()) != null) {
			sb.append(line).append("\n");
			if (line.contains(BEGIN_INDICATOR)) {
				indicatorFound = true;
				break;
			}
		}

		if (!indicatorFound) {
			System.out.println("No indicator found in '" + file + "'. Will skip code generation.");
			s.close();
			return;
		}

		// add generator signature
		sb.append("\t// GENERATED FROM ").append(TupleGenerator.class.getName()).append(".\n");

		// add tuple dependent code
		sb.append(code).append("\n");

		// skip generated code
		while (s.hasNextLine() && (line = s.nextLine()) != null) {
			if (line.contains(END_INDICATOR)) {
				sb.append(line).append("\n");
				break;
			}
		}

		// add file ending
		while (s.hasNextLine() && (line = s.nextLine()) != null) {
			sb.append(line).append("\n");
		}
		s.close();
		FileUtils.writeFileUtf8(file, sb.toString());
	}
}