Skip to content
Snippets Groups Projects
Select Git revision
  • 2b1728f763048a9c340234ef1975746e52108c42
  • master default
  • labcomm2014
  • labcomm2006
  • python_sig_hash
  • typedefs
  • anders.blomdell
  • typeref
  • pragma
  • compiler-refactoring
  • labcomm2013
  • v2014.6
  • v2015.0
  • v2014.5
  • v2014.4
  • v2006.0
  • v2014.3
  • v2014.2
  • v2014.1
  • v2014.0
  • v2013.0
21 results

Decoder.java

Blame
  • Decoder.java 2.22 KiB
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.InputStream;
    
    import se.lth.control.labcomm.LabCommDecoderChannel;
    
    public class Decoder
      implements theTwoInts.Handler, anotherTwoInts.Handler, IntString.Handler, TwoArrays.Handler, TwoFixedArrays.Handler
    
    {
    
      LabCommDecoderChannel decoder;
    
      public Decoder(InputStream in) 
        throws Exception 
      {
        decoder = new LabCommDecoderChannel(in);
        theTwoInts.register(decoder, this);
        anotherTwoInts.register(decoder, this);
        IntString.register(decoder, this);
        TwoArrays.register(decoder, this);
        TwoFixedArrays.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 printTwoInts(TwoInts d) throws java.io.IOException {
        System.out.println("a="+d.a+", b="+d.b);
      }
    
      public void handle_theTwoInts(TwoInts d) throws java.io.IOException {
        System.out.print("Got theTwoInts: ");
        printTwoInts(d);
      }
    
      public void handle_anotherTwoInts(TwoInts d) throws java.io.IOException {
        System.out.print("Got anotherheTwoInts: ");
        printTwoInts(d);
      }
    
      public void handle_IntString(IntString d) throws java.io.IOException {
        System.out.println("Got IntString, x="+d.x+", s="+d.s);
      }
    
      public void handle_TwoArrays(TwoArrays d) throws java.io.IOException {
        System.out.println("Got TwoArrays:");
        for(int i=0; i<d.fixed.length; i++) {
    	System.out.print(d.fixed[i]+" ");
        }
        System.out.println();
        for(int i=0; i<d.variable[0].length; i++) {
    	System.out.print(d.variable[0][i]+" ");
    	System.out.print(d.variable[1][i]+" ");
        }
        System.out.println();
      }
    
      public void handle_TwoFixedArrays(TwoFixedArrays d) throws java.io.IOException {
        System.out.println("Got TwoFixedArrays:");
        for(int i=0; i<d.a.length; i++) {
    	System.out.print(d.a[i]+" ");
        }
        System.out.println();
        for(int i=0; i<d.b[0].length; i++) {
    	System.out.print(d.b[0][i]+" ");
    	System.out.print(d.b[1][i]+" ");
        }
        System.out.println();
      }
    
    
      public static void main(String[] arg) throws Exception {
        Decoder example = new Decoder(
          new FileInputStream(new File(arg[0]))
        );
      }
    }