Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Cowhello
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
leinolm
Cowhello
Commits
c2831335
Commit
c2831335
authored
1 year ago
by
leinolm
Browse files
Options
Downloads
Patches
Plain Diff
hieman parempi poikkeusten käsittely
parent
56d3cd33
Branches
main
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/cowhello/ConsoleProcess.java
+12
-10
12 additions, 10 deletions
src/cowhello/ConsoleProcess.java
with
12 additions
and
10 deletions
src/cowhello/ConsoleProcess.java
+
12
−
10
View file @
c2831335
...
@@ -18,16 +18,18 @@ public class ConsoleProcess extends Thread{
...
@@ -18,16 +18,18 @@ public class ConsoleProcess extends Thread{
private
PrintStream
output
;
private
PrintStream
output
;
private
Scanner
input
;
private
Scanner
input
;
private
Commands
komennot
;
private
Commands
komennot
;
private
String
prompt
;
/**
/**
* initializes the class
* initializes the class
* @param in Stream that the thread will read from
* @param in Stream that the thread will read from
* @param out Stream that the thread will write into
* @param out Stream that the thread will write into
* @param prompt What gets displayed in the stream for prompt, eg "console>"
*/
*/
public
ConsoleProcess
(
InputStream
in
,
OutputStream
out
)
{
public
ConsoleProcess
(
InputStream
in
,
OutputStream
out
,
String
prompt
)
{
this
.
output
=
new
PrintStream
(
out
);
this
.
output
=
new
PrintStream
(
out
);
this
.
input
=
new
Scanner
(
in
);
this
.
input
=
new
Scanner
(
in
);
komennot
=
new
Commands
();
komennot
=
new
Commands
();
this
.
prompt
=
prompt
+
">"
;
}
}
/**
/**
...
@@ -36,14 +38,10 @@ public class ConsoleProcess extends Thread{
...
@@ -36,14 +38,10 @@ public class ConsoleProcess extends Thread{
@Override
@Override
public
void
run
()
{
public
void
run
()
{
while
(
true
)
{
while
(
true
)
{
output
.
print
(
"Cowhello>"
);
output
.
print
(
prompt
);
String
syote
=
input
.
nextLine
();
String
syote
=
input
.
nextLine
();
if
(
syote
.
equals
(
""
))
continue
;
if
(
syote
.
equals
(
""
))
continue
;
try
{
exec
(
syote
);
exec
(
syote
);
}
catch
(
Exception
e
)
{
puhu
(
e
,
"Virhe komennon kanssa: "
+
e
.
getMessage
());
}
}
}
}
}
...
@@ -91,7 +89,11 @@ public class ConsoleProcess extends Thread{
...
@@ -91,7 +89,11 @@ public class ConsoleProcess extends Thread{
private
void
exec
(
String
a
)
{
private
void
exec
(
String
a
)
{
String
[]
jutut
=
a
.
split
(
" "
);
String
[]
jutut
=
a
.
split
(
" "
);
komennot
.
exec
(
output
,
jutut
);
try
{
komennot
.
exec
(
output
,
jutut
);
}
catch
(
Exception
e
)
{
puhu
(
e
,
"Virhe komennon kanssa: "
+
e
.
getMessage
());
komennot
.
exec
(
output
,
new
String
[]{
"help"
,
jutut
[
0
]
});
}
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment