Last active
May 24, 2018 17:08
-
-
Save jorgejch/3c1e86518eea04c3b40b to your computer and use it in GitHub Desktop.
Class implements named pipe access and creation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File; | |
import java.io.FileInputStream; | |
import java.io.FileNotFoundException; | |
import java.io.FileOutputStream; | |
import java.io.FileReader; | |
import java.io.IOException; | |
import java.nio.channels.FileChannel; | |
// From: https://github.com/sioutisc/jdds/blob/master/JDDS/src/rtjdds/rtps/transport/NamedPipe.java | |
public class NamedPipe extends File { | |
private NamedPipe(String name) { | |
super(name); | |
} | |
public FileChannel getInputChannel() throws FileNotFoundException { | |
FileInputStream is = new FileInputStream(this); | |
return is.getChannel(); | |
} | |
public FileChannel getOutputChannel() throws FileNotFoundException { | |
FileOutputStream os = new FileOutputStream(this); | |
return os.getChannel(); | |
} | |
public static NamedPipe createPipe(String name) throws IOException { | |
Runtime.getRuntime().exec("mkfifo "+name); | |
NamedPipe pipe = new NamedPipe(name); | |
if (pipe.exists()) | |
return new NamedPipe(name); | |
else | |
throw new IOException("Errors while creating the pipe"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment