Skip to content

Commit a2b862b

Browse files
committed
JShellWrapper moved sysout char limit into the config
1 parent cf9ed64 commit a2b862b

4 files changed

Lines changed: 14 additions & 5 deletions

File tree

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11

2-
public record Config(int evalTimeoutSeconds) {
2+
public record Config(int evalTimeoutSeconds, int sysOutCharLimit) {
3+
static int loadIntEnv(String envName) {
4+
return Integer.parseInt(System.getenv(envName));
5+
}
36
public static Config load() {
47
return new Config(
5-
Integer.parseInt(System.getenv("evalTimeoutSeconds"))
8+
loadIntEnv("evalTimeoutSeconds"),
9+
loadIntEnv("sysOutCharLimit")
610
);
711
}
12+
13+
public Config {
14+
if(evalTimeoutSeconds <= 0) throw new IllegalArgumentException("Invalid evalTimeoutSeconds : " + evalTimeoutSeconds);
15+
if(sysOutCharLimit <= 0) throw new IllegalArgumentException("Invalid sysOutCharLimit : " + sysOutCharLimit);
16+
}
817
}

JShellWrapper/src/main/java/JShellWrapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class JShellWrapper {
1616
public void run(Config config, InputStream in, PrintStream processOut) {
1717
Scanner processIn = new Scanner(in);
1818
String startup = desanitize(processIn.nextLine());
19-
StringOutputStream jshellOut = new StringOutputStream(1024);
19+
StringOutputStream jshellOut = new StringOutputStream(config.sysOutCharLimit());
2020
try (JShell shell = JShell.builder().out(new PrintStream(jshellOut)).build()) {
2121
verifyStartupEval(eval(shell, startup, new AtomicBoolean()));
2222
while(true) {

JShellWrapper/src/test/java/JShellWrapperStartupScriptTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class JShellWrapperStartupScriptTest {
99
@Test
1010
void testDoubleSnippets() {
11-
Config config = new Config(5);
11+
Config config = new Config(5, 1024);
1212
StringInputStream inputStream = new StringInputStream("""
1313
import java.util.*; void println(Object o) { System.out.println(o); }
1414
eval

JShellWrapper/src/test/java/JShellWrapperTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class JShellWrapperTest {
1313
PrintStream out;
1414
@BeforeAll
1515
static void setUp() {
16-
config = new Config(5);
16+
config = new Config(5, 1024);
1717
jshell = new JShellWrapper();
1818
}
1919
void evalTest(String input, String expectedOutput) {

0 commit comments

Comments
 (0)