Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tommy Olofsson
LabComm
Commits
28c454c2
Commit
28c454c2
authored
Nov 02, 2011
by
Sven Robertz
Browse files
added simple Java example
parent
58956828
Changes
5
Show whitespace changes
Inline
Side-by-side
.bzrignore
View file @
28c454c2
...
...
@@ -17,3 +17,4 @@ lib/java/se/lth/control/labcomm/LabCommReader.class
lib/java/se/lth/control/labcomm/LabCommSample.class
lib/java/se/lth/control/labcomm/LabCommType.class
lib/java/se/lth/control/labcomm/LabCommWriter.class
gen
examples/simple/Decoder.java
0 → 100644
View file @
28c454c2
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.InputStream
;
import
se.lth.control.labcomm.LabCommDecoderChannel
;
public
class
Decoder
implements
TwoInts
.
Handler
,
IntString
.
Handler
{
LabCommDecoderChannel
decoder
;
public
Decoder
(
InputStream
in
)
throws
Exception
{
decoder
=
new
LabCommDecoderChannel
(
in
);
TwoInts
.
register
(
decoder
,
this
);
IntString
.
register
(
decoder
,
this
);
try
{
System
.
out
.
println
(
"Running decoder."
);
decoder
.
run
();
}
catch
(
java
.
io
.
EOFException
e
)
{
System
.
out
.
println
(
"Decoder reached end of file."
);
}
}
public
void
handle_TwoInts
(
TwoInts
d
)
throws
java
.
io
.
IOException
{
System
.
out
.
println
(
"Got TwoInts, a="
+
d
.
a
+
", b="
+
d
.
b
);
}
public
void
handle_IntString
(
IntString
d
)
throws
java
.
io
.
IOException
{
System
.
out
.
println
(
"Got IntString, x="
+
d
.
x
+
", s="
+
d
.
s
);
}
public
static
void
main
(
String
[]
arg
)
throws
Exception
{
Decoder
example
=
new
Decoder
(
new
FileInputStream
(
new
File
(
arg
[
0
]))
);
}
}
examples/simple/Encoder.java
0 → 100644
View file @
28c454c2
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.OutputStream
;
import
se.lth.control.labcomm.LabCommEncoderChannel
;
public
class
Encoder
{
LabCommEncoderChannel
encoder
;
public
Encoder
(
OutputStream
out
)
throws
Exception
{
encoder
=
new
LabCommEncoderChannel
(
out
);
TwoInts
.
register
(
encoder
);
IntString
.
register
(
encoder
);
}
public
void
doEncode
()
throws
java
.
io
.
IOException
{
TwoInts
x
=
new
TwoInts
();
x
.
a
=
17
;
x
.
b
=
42
;
IntString
y
=
new
IntString
();
y
.
x
=
37
;
y
.
s
=
"Testing, testing"
;
TwoInts
.
encode
(
encoder
,
x
);
IntString
.
encode
(
encoder
,
y
);
}
public
static
void
main
(
String
[]
arg
)
throws
Exception
{
FileOutputStream
fos
=
new
FileOutputStream
(
new
File
(
arg
[
0
]));
Encoder
example
=
new
Encoder
(
fos
);
example
.
doEncode
();
fos
.
close
();
}
}
examples/simple/compile.sh
View file @
28c454c2
java
-jar
../../labComm.jar
--java
=
java simple.lc
java
-jar
../../labComm.jar
--java
=
gen simple.lc
javac
-cp
../../lib/java:. gen/
*
.java Encoder.java Decoder.java
examples/simple/run.sh
0 → 100644
View file @
28c454c2
java
-cp
.:../../lib/java:gen Encoder encoded_data
java
-cp
.:../../lib/java:gen Decoder encoded_data
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment