Example usage for org.eclipse.jdt.internal.compiler.tool EclipseFileObject EclipseFileObject

List of usage examples for org.eclipse.jdt.internal.compiler.tool EclipseFileObject EclipseFileObject

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.tool EclipseFileObject EclipseFileObject.

Prototype

public EclipseFileObject(String className, URI uri, Kind kind, Charset charset) 

Source Link

Usage

From source file:de.pavloff.spark4knime.jsnippet.JavaSnippet.java

License:Open Source License

/**
 * Create the java-file of the snippet.//from   w w w .jav a  2 s  .  c  o  m
 */
private JavaFileObject createJSnippetFile() throws IOException {
    m_snippetFile = new File(m_tempClassPathDir, "JSnippet" + m_uid + ".java");
    FileOutputStream fos = new FileOutputStream(m_snippetFile);
    OutputStreamWriter out = new OutputStreamWriter(fos, Charset.forName("UTF-8"));
    try {
        try {
            Document doc = getDocument();
            out.write(doc.getText(0, doc.getLength()));
        } catch (BadLocationException e) {
            // this should never happen.
            throw new IllegalStateException(e);
        }
    } finally {
        out.close();
    }

    return new EclipseFileObject("JSnippet" + m_uid, m_snippetFile.toURI(), Kind.SOURCE,
            Charset.defaultCharset());
}