groovy.lang

## Class GroovyCodeSource

- java.lang.Object
- - groovy.lang.GroovyCodeSource

    public class GroovyCodeSource
    extends Object

CodeSource wrapper class that allows specific security policies to be associated with a class compiled from groovy source.

Author:
  Steve Goetze, Guillaume Laforge, Merlyn Albery-Speyer

### Constructor Summary

Constructors
Constructor and Description
`GroovyCodeSource(File infile)`
`GroovyCodeSource(File infile, String encoding)`
`GroovyCodeSource(InputStream inputStream, String name, String codeBase)` Deprecated. Prefer using methods taking a Reader rather than an InputStream to avoid wrong encoding issues.
`GroovyCodeSource(Reader reader, String name, String codeBase)` Construct a GroovyCodeSource for an inputStream of groovyCode that has an unknown provenance -- meaning it didn't come from a File or a URL (e.g.
`GroovyCodeSource(String script, String name, String codeBase)`
`GroovyCodeSource(URL url)`

### Method Summary

Methods
`File` `getFile()`
`InputStream` `getInputStream()` Deprecated. Prefer using methods taking a Reader rather than an InputStream to avoid wrong encoding issues.
`String` `getName()`
`String` `getScriptText()`
`boolean` `isCachable()`
`void` `setCachable(boolean b)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### GroovyCodeSource

    public GroovyCodeSource(String script,
                    String name,
                    String codeBase)

#### GroovyCodeSource

    public GroovyCodeSource(Reader reader,
                    String name,
                    String codeBase)

Construct a GroovyCodeSource for an inputStream of groovyCode that has an unknown provenance -- meaning it didn't come from a File or a URL (e.g. a String). The supplied codeBase will be used to construct a File URL that should match up with a java Policy entry that determines the grants to be associated with the class that will be built from the InputStream.

The permission groovy.security.GroovyCodeSourcePermission will be used to determine if the given codeBase may be specified. That is, the current Policy set must have a GroovyCodeSourcePermission that implies the codeBase, or an exception will be thrown. This is to prevent callers from hijacking existing codeBase policy entries unless explicitly authorized by the user.

#### GroovyCodeSource

    @Deprecated
    public GroovyCodeSource(InputStream inputStream,
                               String name,
                               String codeBase)

Deprecated. Prefer using methods taking a Reader rather than an InputStream to avoid wrong encoding issues.
Construct a GroovyCodeSource for an inputStream of groovyCode that has an unknown provenance -- meaning it didn't come from a File or a URL (e.g. a String). The supplied codeBase will be used to construct a File URL that should match up with a java Policy entry that determines the grants to be associated with the class that will be built from the InputStream.

The permission groovy.security.GroovyCodeSourcePermission will be used to determine if the given codeBase may be specified. That is, the current Policy set must have a GroovyCodeSourcePermission that implies the codeBase, or an exception will be thrown. This is to prevent callers from hijacking existing codeBase policy entries unless explicitly authorized by the user.

#### GroovyCodeSource

    public GroovyCodeSource(File infile,
                    String encoding)
                     throws IOException

Throws:
  `IOException`

#### GroovyCodeSource

    public GroovyCodeSource(File infile)
                     throws IOException

Parameters:
  `infile` - the file to create a GroovyCodeSource for.
Throws:
  `IOException` - if an issue arises opening and reading the file.

#### GroovyCodeSource

    public GroovyCodeSource(URL url)
                     throws IOException

Throws:
  `IOException`

### Method Detail

#### getInputStream

    @Deprecated
    public InputStream getInputStream()

Deprecated. Prefer using methods taking a Reader rather than an InputStream to avoid wrong encoding issues.

#### getScriptText

    public String getScriptText()

#### getName

    public String getName()

#### getFile

    public File getFile()

#### setCachable

    public void setCachable(boolean b)

#### isCachable

    public boolean isCachable()