本文整理汇总了Java中org.codehaus.groovy.tools.shell.IO类的典型用法代码示例。如果您正苦于以下问题:Java IO类的具体用法?Java IO怎么用?Java IO使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IO类属于org.codehaus.groovy.tools.shell包,在下文中一共展示了IO类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldPluginSugar
import org.codehaus.groovy.tools.shell.IO; //导入依赖的package包/类
@Test
public void shouldPluginSugar() throws Exception {
MetaRegistryUtil.clearRegistry(new HashSet<>(Arrays.asList(TinkerGraph.class)));
final SugarGremlinPlugin plugin = new SugarGremlinPlugin();
final Groovysh groovysh = new Groovysh();
final Map<String, Object> env = new HashMap<>();
env.put("ConsolePluginAcceptor.io", new IO());
env.put("ConsolePluginAcceptor.shell", groovysh);
final SpyPluginAcceptor spy = new SpyPluginAcceptor(groovysh::execute, () -> env);
plugin.pluginTo(spy);
groovysh.getInterp().getContext().setProperty("g", TinkerFactory.createClassic());
assertEquals(6l, ((GraphTraversal) groovysh.execute("g.traversal().V()")).count().next());
assertEquals(6l, ((GraphTraversal) groovysh.execute("g.traversal().V")).count().next());
}
示例2: shouldPluginUtilities
import org.codehaus.groovy.tools.shell.IO; //导入依赖的package包/类
@Test
public void shouldPluginUtilities() throws Exception {
final UtilitiesGremlinPlugin plugin = new UtilitiesGremlinPlugin();
final Groovysh groovysh = new Groovysh();
groovysh.getInterp().getContext().setProperty("g", TinkerFactory.createClassic());
final Map<String, Object> env = new HashMap<>();
env.put("ConsolePluginAcceptor.io", new IO());
env.put("ConsolePluginAcceptor.shell", groovysh);
final SpyPluginAcceptor spy = new SpyPluginAcceptor(groovysh::execute, () -> env);
plugin.pluginTo(spy);
assertThat(groovysh.execute("describeGraph(org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph)").toString(), containsString("IMPLEMENTATION - org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph"));
}
示例3: pluginTo
import org.codehaus.groovy.tools.shell.IO; //导入依赖的package包/类
/**
* {@inheritDoc}
* <p/>
* Provides a base implementation for plugins by grabbing the console environment variables and assigning them
* to the {@link #io} and {@link #shell} member variables.
*
* @throws IllegalEnvironmentException if {@link #requireConsoleEnvironment} is set to true and if either
* the {@link #io} and {@link #shell} member variables are null.
*/
@Override
public void pluginTo(final PluginAcceptor pluginAcceptor) throws IllegalEnvironmentException, PluginInitializationException {
final Map<String, Object> environment = pluginAcceptor.environment();
io = (IO) environment.get(ENV_CONSOLE_IO);
shell = (Groovysh) environment.get(ENV_CONSOLE_SHELL);
if (requireConsoleEnvironment && (null == io || null == shell))
throw new IllegalEnvironmentException(this, ENV_CONSOLE_SHELL, ENV_CONSOLE_IO);
try {
afterPluginTo(pluginAcceptor);
} catch (PluginInitializationException pie) {
throw pie;
} catch (Exception ex) {
throw new PluginInitializationException(ex);
}
}
示例4: preferenceChange
import org.codehaus.groovy.tools.shell.IO; //导入依赖的package包/类
public void preferenceChange(final PreferenceChangeEvent event) {
if (event.getKey().equals(VERBOSITY_KEY)) {
String name = event.getNewValue();
if (name == null) {
name = IO.Verbosity.INFO.name;
}
try {
verbosity = IO.Verbosity.forName(name);
}
catch (Exception e) {
event.getNode().put(event.getKey(), verbosity.name);
}
}
}
示例5: GroovyInterpreter
import org.codehaus.groovy.tools.shell.IO; //导入依赖的package包/类
public GroovyInterpreter(Binding binding) throws IOException {
this.binding = binding;
if (this.binding == null)
this.binding = new Binding();
is = new PipedInputStream();
os = new PipedOutputStream();
pis = new PipedInputStream(os);
pos = new PipedOutputStream(is);
System.setProperty(TerminalFactory.JLINE_TERMINAL, "none");
AnsiConsole.systemInstall();
Ansi.setDetector(new AnsiDetector());
binding.setProperty("out", new ImmediateFlushingPrintWriter(pos));
shell = new Groovysh(binding, new IO(pis, pos, pos));
// {
// @Override
// public void displayWelcomeBanner(InteractiveShellRunner runner) {
// // do nothing
// }
// };
shell.getIo().setVerbosity(Verbosity.QUIET);
}
示例6: initializeShellWithScript
import org.codehaus.groovy.tools.shell.IO; //导入依赖的package包/类
private void initializeShellWithScript(final IO io, final String initScriptFile, final Groovysh groovy) {
if (initScriptFile != null) {
String line = "";
try {
final BufferedReader reader = new BufferedReader(new InputStreamReader(
new FileInputStream(initScriptFile), Charset.forName("UTF-8")));
while ((line = reader.readLine()) != null) {
groovy.execute(line);
}
reader.close();
} catch (FileNotFoundException fnfe) {
io.err.println(String.format("Gremlin initialization file not found at [%s].", initScriptFile));
System.exit(1);
} catch (IOException ioe) {
io.err.println(String.format("Bad line in Gremlin initialization file at [%s].", line));
System.exit(1);
}
}
}
示例7: GremlinSession
import org.codehaus.groovy.tools.shell.IO; //导入依赖的package包/类
public GremlinSession(Database database) {
this.database = database;
PrintStream out = new PrintStream(new BufferedOutputStream(baos));
io = new IO(System.in, out, out);
Map<String, Object> bindings = new HashMap<String, Object>();
bindings.put("g", getGremlinWrappedGraph());
bindings.put("out", out);
initialBindings = new ArrayList<String>(bindings.keySet());
try {
scriptEngine = new GremlinWebConsole(new Binding(bindings), io);
} catch (final Exception failure) {
scriptEngine = new GremlinWebConsole() {
@Override
public void execute(String script) {
io.out.println("Could not start Groovy during Gremlin initialization, reason:");
failure.printStackTrace(io.out);
}
};
}
}
示例8: shouldConstructRemoteAcceptorWhenInConsoleEnvironment
import org.codehaus.groovy.tools.shell.IO; //导入依赖的package包/类
@Test
public void shouldConstructRemoteAcceptorWhenInConsoleEnvironment() throws Exception {
final DriverGremlinPlugin plugin = new DriverGremlinPlugin();
final Map<String, Object> env = new HashMap<>();
env.put("ConsolePluginAcceptor.io", new IO());
env.put("ConsolePluginAcceptor.shell", new Groovysh());
final SpyPluginAcceptor spy = new SpyPluginAcceptor(() -> env);
plugin.pluginTo(spy);
assertThat(plugin.remoteAcceptor().isPresent(), is(true));
}
示例9: pluginTo
import org.codehaus.groovy.tools.shell.IO; //导入依赖的package包/类
@Override
public void pluginTo(final PluginAcceptor pluginAcceptor) {
pluginAcceptor.addImports(IMPORTS);
final Groovysh groovy = (Groovysh) pluginAcceptor.environment().get("ConsolePluginAcceptor.shell");
final IO io = (IO) pluginAcceptor.environment().get("ConsolePluginAcceptor.io");
groovy.register(new Bio4jCommand(groovy, io));
}
示例10: exportGraphson
import org.codehaus.groovy.tools.shell.IO; //导入依赖的package包/类
public static void exportGraphson(Groovysh shell, IO io, String query, String path) throws IOException {
// prepare to export
path = resolvePath(path, DEFAULT_JSON_NAME);
File file = new File(path);
FileOutputStream f = new FileOutputStream(file);
GraphSONWriter w = GraphSONWriter.build().create();
// execute the given query
shell.execute("t = " + query + ";null");
Traversal<?, Vertex> traversal = (Traversal<?, Vertex>) shell.getInterp().getContext().getProperty("t");
// try exporting
try {
w.writeVertices(f, traversal);
} catch (ClassCastException e){
shell.execute("t = " + query + ";null");
Traversal<?, Edge> edgeTraversal = (Traversal<?, Edge>) shell.getInterp().getContext().getProperty("t");
while (edgeTraversal.hasNext()){
Edge edge = edgeTraversal.next();
w.writeEdge(f, edge);
}
}
// done
f.close();
io.out.println("==> exported to " + path);
}
示例11: exportGraphml
import org.codehaus.groovy.tools.shell.IO; //导入依赖的package包/类
public static void exportGraphml(Groovysh shell, IO io, String graphName, String path) throws IOException {
// prepare to export
path = resolvePath(path, DEFAULT_XML_NAME);
File file = new File(path);
FileOutputStream f = new FileOutputStream(file);
GraphMLWriter w = GraphMLWriter.build().create();
// get the graph and export it to file
Graph graph = (Graph) shell.getInterp().getContext().getProperty(graphName);
w.writeGraph(f, graph);
// done
f.close();
io.out.println("==> exported to " + path);
}
示例12: runGroovy
import org.codehaus.groovy.tools.shell.IO; //导入依赖的package包/类
protected void runGroovy() {
try {
LOGGER.info("Running groovy shell");
IO io = new IO(in, out, err);
LOGGER.info("in: {} out: {} err: {}", in, out, err);
// TODO: fix to allow other bindings.
Binding binding = new Binding();
binding.setVariable("out", io.out);
Groovysh groovysh = new Groovysh(binding, io);
InteractiveShellRunner isr = new InteractiveShellRunner(groovysh, new GroovyPrompt(this));
isr.setErrorHandler(new OutputStreamErrorHandler(this, err));
try {
// groovysh.run((String) null);
isr.run();
} catch (Exception e) {
try (PrintStream ps = new PrintStream(out)) {
e.printStackTrace(ps);
}
this.alive = false;
}
} finally {
this.alive = false;
destroy();
callback.onExit(exitValue());
}
}
示例13: before
import org.codehaus.groovy.tools.shell.IO; //导入依赖的package包/类
@Before
public void before() {
io = mock(IO.class);
mBean = mock(GroovyMBean.class);
groovysh = new Groovysh(io);
jmxCommand = new JmxCommand(groovysh) {
@Override
GroovyMBean getMBean(String beanName) {
return mBean;
}
};
}
示例14: setIo
import org.codehaus.groovy.tools.shell.IO; //导入依赖的package包/类
public static void setIo(IO ioObject) {
io = ioObject;
}
示例15: getIo
import org.codehaus.groovy.tools.shell.IO; //导入依赖的package包/类
public static IO getIo() {
return io;
}