Commit 0b806600 authored by Sven Robertz's avatar Sven Robertz
Browse files

started refactoring Java EncoderChannel to use LabCommWriter + minor fixes

parent 245a4f7c
......@@ -15,7 +15,7 @@
<property name="tools" value="tools"/>
<!-- "test" is the directory where tests are located. -->
<property name="test" value="test"/>
<property name="test" value="../test"/>
<!-- "jflex" is an ant task class for the scanner generator in JFlex.jar -->
<taskdef name="jflex" classname="JFlex.anttask.JFlexTask" classpath="tools/JFlex.jar"/>
......@@ -66,7 +66,7 @@ classpath="tools/jastadd2.jar"/>
<!-- compile sources -->
<target name="test" depends="jar">
<echo message = "Running tests"/>
<exec executable="./run" dir="test">
<exec executable="./run" dir="../test">
<env key="PYTHONPATH" value="../lib/python"/>
<!--arg value="hej"/-->
......@@ -6,4 +6,5 @@ extern int labcomm_fd_reader(
extern int labcomm_fd_writer(
labcomm_writer_t *r,
labcomm_writer_action_t action);
labcomm_writer_action_t action,
......@@ -7,18 +7,22 @@ import;
public class LabCommEncoderChannel implements LabCommEncoder {
private OutputStream writer;
private LabCommWriter writer;
private ByteArrayOutputStream bytes;
private DataOutputStream data;
private LabCommEncoderRegistry registry;
public LabCommEncoderChannel(OutputStream writer) {
public LabCommEncoderChannel(LabCommWriter writer) {
this.writer = writer;
bytes = new ByteArrayOutputStream();
data = new DataOutputStream(bytes);
registry = new LabCommEncoderRegistry();
public LabCommEncoderChannel(OutputStream writer) {
this(new WriterWrapper(writer));
public void register(LabCommDispatcher dispatcher) throws IOException {
int index = registry.add(dispatcher);
......@@ -37,7 +41,9 @@ public class LabCommEncoderChannel implements LabCommEncoder {
public void end(Class<? extends LabCommSample> c) throws IOException {
//XXX when writer was a stream, it was probably a bit more GC efficient:
package se.lth.control.labcomm;
public interface LabCommWriter {
public void write(byte[] data);
public void write(byte[] data) throws IOException;
package se.lth.control.labcomm;
class WriterWrapper implements LabCommWriter{
private OutputStream os;
public WriterWrapper(OutputStream os) {
this.os = os;
public void write(byte[] data) throws IOException {
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment