Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/debugtools/DDR_VM/src/com/ibm/j9ddr/command/CommandReader.java
6005 views
1
/*******************************************************************************
2
* Copyright (c) 1991, 2014 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
23
package com.ibm.j9ddr.command;
24
25
import java.io.InputStream;
26
import java.io.PrintStream;
27
import java.text.ParseException;
28
29
import com.ibm.j9ddr.tools.ddrinteractive.DDRInteractive;
30
31
public abstract class CommandReader {
32
33
protected final PrintStream out;
34
35
public CommandReader(PrintStream out) {
36
this.out = out;
37
}
38
39
/**
40
* Execute next command, and execute it in DDRInteractive
41
*
42
* @throws Exception
43
*/
44
public abstract void processInput(DDRInteractive engine) throws Exception;
45
46
/**
47
* Set the input stream on which commands will be read from. This may be
48
* ignored by the underlying implementation if this redirection is not
49
* supported.
50
*
51
* @param in
52
* InputStream to read commands from
53
*/
54
public abstract void setInputStream(InputStream in);
55
56
public void processLine(DDRInteractive engine, String line) throws Exception {
57
line = line.trim();
58
59
if (line.toLowerCase().equals("quit")) {
60
out.println("Quitting...");
61
62
throw new ExitException();
63
}
64
if (line.toLowerCase().equals("exit")) {
65
out.println("Exiting...");
66
67
throw new ExitException();
68
}
69
70
CommandParser parser;
71
try {
72
parser = new CommandParser(line);
73
} catch (ParseException e) {
74
out.println("Error running command: " + e.getMessage());
75
return;
76
}
77
78
79
engine.execute(parser);
80
}
81
}
82
83