Search in sources :

Example 46 with FileOutputStream

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" });
}
Also used : Path(org.apache.flink.core.fs.Path) FileInputSplit(org.apache.flink.core.fs.FileInputSplit) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File)

Example 47 with FileOutputStream

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
        }
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) Charset(java.nio.charset.Charset) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) PrintWriter(java.io.PrintWriter)

Example 48 with FileOutputStream

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);
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) Properties(java.util.Properties) File(java.io.File) Test(org.junit.Test)

Example 49 with FileOutputStream

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();
        }
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) PrintWriter(java.io.PrintWriter)

Example 50 with FileOutputStream

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");
        }
    }
}
Also used : SourcePrinter(org.codehaus.groovy.antlr.treewalker.SourcePrinter) PrintStream(java.io.PrintStream) NodeAsHTMLPrinter(org.codehaus.groovy.antlr.treewalker.NodeAsHTMLPrinter) PreOrderTraversal(org.codehaus.groovy.antlr.treewalker.PreOrderTraversal) CompositeVisitor(org.codehaus.groovy.antlr.treewalker.CompositeVisitor) Visitor(org.codehaus.groovy.antlr.treewalker.Visitor) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) MindMapPrinter(org.codehaus.groovy.antlr.treewalker.MindMapPrinter) FileOutputStream(java.io.FileOutputStream) VisitorAdapter(org.codehaus.groovy.antlr.treewalker.VisitorAdapter) SourceCodeTraversal(org.codehaus.groovy.antlr.treewalker.SourceCodeTraversal) CompositeVisitor(org.codehaus.groovy.antlr.treewalker.CompositeVisitor)

Aggregations

FileOutputStream (java.io.FileOutputStream)5940 File (java.io.File)3316 IOException (java.io.IOException)2581 FileInputStream (java.io.FileInputStream)1060 OutputStream (java.io.OutputStream)960 BufferedOutputStream (java.io.BufferedOutputStream)793 InputStream (java.io.InputStream)771 FileNotFoundException (java.io.FileNotFoundException)634 OutputStreamWriter (java.io.OutputStreamWriter)586 Test (org.junit.Test)471 BufferedWriter (java.io.BufferedWriter)291 PrintWriter (java.io.PrintWriter)291 ZipEntry (java.util.zip.ZipEntry)277 DataOutputStream (java.io.DataOutputStream)252 ByteArrayOutputStream (java.io.ByteArrayOutputStream)249 ZipOutputStream (java.util.zip.ZipOutputStream)240 BufferedInputStream (java.io.BufferedInputStream)239 ArrayList (java.util.ArrayList)216 Writer (java.io.Writer)197 URL (java.net.URL)184