use of java.io.FileOutputStream in project flink by apache.
the class GraphCreationWithCsvITCase method createTempFile.
private FileInputSplit createTempFile(String content) throws IOException {
File tempFile = File.createTempFile("test_contents", "tmp");
tempFile.deleteOnExit();
OutputStreamWriter wrt = new OutputStreamWriter(new FileOutputStream(tempFile), Charset.forName("UTF-8"));
wrt.write(content);
wrt.close();
return new FileInputSplit(0, new Path(tempFile.toURI().toString()), 0, tempFile.length(), new String[] { "localhost" });
}
use of java.io.FileOutputStream in project groovy by apache.
the class JavaStubGenerator method generateClass.
public void generateClass(ClassNode classNode) throws FileNotFoundException {
// Only attempt to render our self if our super-class is resolved, else wait for it
if (requireSuperResolved && !classNode.getSuperClass().isResolved()) {
return;
}
// owner should take care for us
if (classNode instanceof InnerClassNode)
return;
// don't generate stubs for private classes, as they are only visible in the same file
if ((classNode.getModifiers() & Opcodes.ACC_PRIVATE) != 0)
return;
String fileName = classNode.getName().replace('.', '/');
mkdirs(outputPath, fileName);
toCompile.add(fileName);
File file = new File(outputPath, fileName + ".java");
FileOutputStream fos = new FileOutputStream(file);
Charset charset = Charset.forName(encoding);
PrintWriter out = new PrintWriter(new OutputStreamWriter(fos, charset));
try {
String packageName = classNode.getPackageName();
if (packageName != null) {
out.println("package " + packageName + ";\n");
}
printImports(out, classNode);
printClassContents(out, classNode);
} finally {
try {
out.close();
} catch (Exception e) {
// ignore
}
try {
fos.close();
} catch (IOException e) {
// ignore
}
}
}
use of java.io.FileOutputStream in project flink by apache.
the class ParameterToolTest method testFromPropertiesFile.
@Test
public void testFromPropertiesFile() throws IOException {
File propertiesFile = tmp.newFile();
Properties props = new Properties();
props.setProperty("input", "myInput");
props.setProperty("expectedCount", "15");
try (final OutputStream out = new FileOutputStream(propertiesFile)) {
props.store(out, "Test properties");
}
ParameterTool parameter = ParameterTool.fromPropertiesFile(propertiesFile.getAbsolutePath());
Assert.assertEquals(2, parameter.getNumberOfParameters());
validate(parameter);
}
use of java.io.FileOutputStream in project flink by apache.
the class PlanJSONDumpGenerator method dumpOptimizerPlanAsJSON.
public void dumpOptimizerPlanAsJSON(OptimizedPlan plan, File toFile) throws IOException {
PrintWriter pw = null;
try {
pw = new PrintWriter(new FileOutputStream(toFile), false);
dumpOptimizerPlanAsJSON(plan, pw);
pw.flush();
} finally {
if (pw != null) {
pw.close();
}
}
}
use of java.io.FileOutputStream in project groovy by apache.
the class AntlrParserPlugin method outputASTInVariousFormsIfNeeded.
private void outputASTInVariousFormsIfNeeded(SourceUnit sourceUnit, SourceBuffer sourceBuffer) {
// straight xstream output of AST
// uppercase to hide from jarjar
String formatProp = System.getProperty("ANTLR.AST".toLowerCase());
if ("xml".equals(formatProp)) {
saveAsXML(sourceUnit.getName(), ast);
}
// 'pretty printer' output of AST
if ("groovy".equals(formatProp)) {
try {
PrintStream out = new PrintStream(new FileOutputStream(sourceUnit.getName() + ".pretty.groovy"));
Visitor visitor = new SourcePrinter(out, tokenNames);
AntlrASTProcessor treewalker = new SourceCodeTraversal(visitor);
treewalker.process(ast);
} catch (FileNotFoundException e) {
System.out.println("Cannot create " + sourceUnit.getName() + ".pretty.groovy");
}
}
// which is a really nice way of seeing the AST, folding nodes etc
if ("mindmap".equals(formatProp)) {
try {
PrintStream out = new PrintStream(new FileOutputStream(sourceUnit.getName() + ".mm"));
Visitor visitor = new MindMapPrinter(out, tokenNames);
AntlrASTProcessor treewalker = new PreOrderTraversal(visitor);
treewalker.process(ast);
} catch (FileNotFoundException e) {
System.out.println("Cannot create " + sourceUnit.getName() + ".mm");
}
}
// include original line/col info and source code on the mindmap output
if ("extendedMindmap".equals(formatProp)) {
try {
PrintStream out = new PrintStream(new FileOutputStream(sourceUnit.getName() + ".mm"));
Visitor visitor = new MindMapPrinter(out, tokenNames, sourceBuffer);
AntlrASTProcessor treewalker = new PreOrderTraversal(visitor);
treewalker.process(ast);
} catch (FileNotFoundException e) {
System.out.println("Cannot create " + sourceUnit.getName() + ".mm");
}
}
// html output of AST
if ("html".equals(formatProp)) {
try {
PrintStream out = new PrintStream(new FileOutputStream(sourceUnit.getName() + ".html"));
List<VisitorAdapter> v = new ArrayList<VisitorAdapter>();
v.add(new NodeAsHTMLPrinter(out, tokenNames));
v.add(new SourcePrinter(out, tokenNames));
Visitor visitors = new CompositeVisitor(v);
AntlrASTProcessor treewalker = new SourceCodeTraversal(visitors);
treewalker.process(ast);
} catch (FileNotFoundException e) {
System.out.println("Cannot create " + sourceUnit.getName() + ".html");
}
}
}
Aggregations