Skip to content

Commit

Permalink
configure scripting out
Browse files Browse the repository at this point in the history
  • Loading branch information
bdw429s committed Apr 11, 2024
1 parent d2fcef1 commit 29d21a6
Showing 1 changed file with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package ortus.boxlang.runtime.context;

import java.io.PrintStream;
import java.net.URI;
import java.util.UUID;

Expand Down Expand Up @@ -63,6 +64,8 @@ public class ScriptingRequestBoxContext extends RequestBoxContext {
// default random key GUID
private Key sessionID = new Key( UUID.randomUUID().toString() );

private PrintStream out = System.out;

/**
* --------------------------------------------------------------------------
* Constructors
Expand Down Expand Up @@ -259,6 +262,27 @@ public IScope getDefaultAssignmentScope() {
return variablesScope;
}

/**
* Set the output stream for this context
*
* @param out The output stream
*
* @return This context
*/
ScriptingRequestBoxContext setOut( PrintStream out ) {
this.out = out;
return this;
}

/**
* Get the output stream for this context
*
* @return The output stream
*/
public PrintStream getOut() {
return out;
}

/**
* Flush the buffer to the output stream
*
Expand All @@ -280,14 +304,14 @@ public IBoxContext flushBuffer( boolean force ) {
clearBuffer();
}
// If a scripting context is our top-level context, we flush to the console.
System.out.print( output );
getOut().print( output );
} else if ( force ) {
for ( StringBuffer buf : buffers ) {
synchronized ( buf ) {
output = buf.toString();
buf.setLength( 0 );
}
System.out.print( output );
getOut().print( output );
}
}
return this;
Expand Down

0 comments on commit 29d21a6

Please sign in to comment.