title: Can you read a float from a stream bytes via pipelines?
body: <p>Currently working on making a pipeline among two files in java and I would to transmit a float via stream bytes. However I don't know how I can receive it and convert it into a float. Here is what I have done so far:</p>
  <p>(3 files)</p>
  <p><strong>Consumi.java:</strong></p>
  <pre><code>package tryout5_stream_bytes;
  
  import java.io.Serializable;
  
  public class Consumi implements Serializable{
  
      private float consumi = 0.0F;
  
      public Consumi(float consumi){
          this.consumi = consumi;
      }
  
      public float getConsumi(){
          return consumi;
      }
  
      public byte[] getBytes(String encode){
          return String.valueOf(consumi).getBytes();
      }
  }
  </code></pre>
  <p><strong>SimulaConsumi.java</strong></p>
  <pre><code>package tryout5_stream_bytes;
  
  import java.io.PipedOutputStream;
  import java.io.IOException;
  import java.io.UnsupportedEncodingException;
  import java.util.concurrent.atomic.AtomicBoolean;
  
  public class SimulaConsumi implements Runnable {
      private AtomicBoolean isRunning = new AtomicBoolean(false);
      private PipedOutputStream pos = null;
  
      public SimulaConsumi(PipedOutputStream pos){
          this.pos = pos;
      }
  
      @Override
      public void run(){
          isRunning.set(true);
  
          while(isRunning.get()){
              Consumi c = new Consumi((float) (30 * Math.random()));
  
              byte[] message = null;
              message = c.getBytes(&quot;UTF-8&quot;);
              
              try{
                  pos.write(message);
                  pos.flush();
              } catch(IOException e){
                  e.printStackTrace();
              }
  
              try{
                  Thread.sleep(1000);
              } catch(InterruptedException e){
                  e.printStackTrace();
              }
          }
      }
  
      public void terminaSimulaConsumi(){
          isRunning.set(false);
      }
  
  }
  </code></pre>
  <p><strong>Main.java</strong></p>
  <pre><code>package tryout5_stream_bytes;
  
  import java.io.IOException;
  import java.io.PipedInputStream;
  import java.io.PipedOutputStream;
  import java.io.UnsupportedEncodingException;
  import java.nio.ByteOrder;
  import java.nio.charset.Charset;
  import java.io.*;
  import java.lang.object;
  import java.nio.ByteBuffer;
  
  public class Main {
      
      public static void main(String[] args){
          PipedInputStream pis = new PipedInputStream();
          PipedOutputStream pos = null;
  
          try{
              pos = new PipedOutputStream(pis);
          }catch(IOException e){
              e.printStackTrace();
          }
  
          SimulaConsumi sc = new SimulaConsumi(pos);
          Thread tsc = new Thread();
          tsc.start();
  
          while(true){
              try{
                  Thread.sleep(900);
              }catch(InterruptedException e){
                  e.printStackTrace();
              }
  
              byte[] buffer = new byte[256];
              try{
                  pis.read(buffer);
              }catch(IOException e){
                  e.printStackTrace();
              }
  
              float received = //Get a float from a stream bytes???
              System.out.println(&quot;Value:&quot;+received);
          }
      }
  }
  </code></pre>
  <p>I believe that the sending of the float in the file &quot;SimulaConsumi&quot; is done well (however I might still be wrong). On the other hand I really have no idea how I can receive it!</p>