beta
beta

Reputation: 647

Problems writing to a unix pipe through Java

I am writing to a framebuffer located at "/dev/fb0". Everything works fine until I try to write again to the pipe using an OutputStream, which hangs the program. I have resolved this by closing the output stream and then recreating it, but this seems awfully slow and blunt.

Framebuffer.java

public class Framebuffer extends Autobuffer {
private FileOutputStream out = null;
private File pipe = null;

public Framebuffer() {
   super(320, 240);
}

public Framebuffer(File pipe) {
   super(320, 240);
   try {
      out = new FileOutputStream(pipe);
   } catch (FileNotFoundException e) {
   e.printStackTrace();
  }
 this.pipe = pipe;
 }

 public void sync() throws IOException {
   out.write(getBytes());
   out.close();
   out = new FileOutputStream(pipe);
 }
 }

Any ideas?

Thanks.

Upvotes: 3

Views: 1301

Answers (3)

beta
beta

Reputation: 647

Changing the Output Stream to RandomAccessFile fixed all of my problems. I bet the stream wasn't working because it can't seek to position 0. Thanks to all who replied.

Upvotes: 1

Stephen C
Stephen C

Reputation: 719229

Firstly, unless something really weird is going on, "/dev/fb0" is a device file not a pipe. [This is a nitpick, but if you use the wrong terminology, 1) people won't understand you and 2) you will have difficulty searching for answers.]

Secondly, this looks like a weird way to interact with a framebuffer!!

I suspect that the problem is that you need to do the equivalent of a POSIX lseek call to set the stream position to zero each time you draw a frame. I've found two ways to do this:

Upvotes: 2

Aif
Aif

Reputation: 11220

What if you flush your output with flush (from OutputStream)?

Upvotes: 0

Related Questions