diff --git a/build.gradle b/build.gradle index dcd5a73..88a021d 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ dependencies { compile 'com.github.boukefalos:jlibloader:0.2' compile 'commons-io:commons-io:2.+' - compile 'commons-cli:commons-cli:1.+' + compile 'commons-cli:commons-cli:1.+' compile 'commons-pool:commons-pool:1.+' compile 'org.slf4j:slf4j-api:1.+' compile 'org.slf4j:slf4j-log4j12:1.7.5' @@ -21,7 +21,7 @@ dependencies { repositories { maven { - url 'https://github.com/Boukefalos/mimis/raw/mvn-repo/' + url 'https://github.com/Boukefalos/jlibpipe/raw/mvn-repo/' } maven { url 'https://github.com/Boukefalos/jlibloader/raw/mvn-repo/' diff --git a/src/main/java/pipe/Client.java b/src/main/java/pipe/Client.java deleted file mode 100644 index 3257f2b..0000000 --- a/src/main/java/pipe/Client.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright (C) 2016 Rik Veenboer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package pipe; - -import java.io.RandomAccessFile; - -public class Client { - public static void main(String[] args) { - try { - // Connect to the pipe - RandomAccessFile pipe = new RandomAccessFile("\\\\.\\pipe\\detest", "rw"); - String echoText = "Hello word\n"; - - // write to pipe - pipe.write(echoText.getBytes()); - - // read response - String echoResponse = pipe.readLine(); - System.out.println(echoResponse); - pipe.close(); - } catch (Exception e) { - e.printStackTrace(); - } - - } -} diff --git a/src/main/java/pipe/Pipe.java b/src/main/java/pipe/Pipe.java deleted file mode 100644 index f734658..0000000 --- a/src/main/java/pipe/Pipe.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Copyright (C) 2016 Rik Veenboer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package pipe; - -import com.github.boukefalos.jlibloader.Native; - -/** - * @author Vikram S Khatri vikram.khatri@us.ibm.com - */ -public class Pipe { - static final int ERROR_PIPE_CONNECTED = 535; - static final int ERROR_BROKEN_PIPE = 109; - static final int PIPE_ACCESS_DUPLEX = 0x00000003; - static final int PIPE_WAIT = 0x00000000; - - static { - Native.load("com.github.boukefalos", "jlibpipe"); - } - - public static final native int CreateNamedPipe( - String pipeName, - int ppenMode, - int pipeMode, - int maxInstances, - int outBufferSize, - int inBufferSize, - int defaultTimeOut, - int securityAttributes); - - public static final native boolean ConnectNamedPipe(int namedPipeHandle, int overlapped); - - public static final native int GetLastError(); - - public static final native boolean CloseHandle(int bbject); - - public static final native byte[] ReadFile(int file, int numberOfBytesToRead); - - public static final native int WriteFile(int file, byte[] buffer, int numberOfBytesToWrite); - - public static final native boolean FlushFileBuffers(int file); - - public static final native boolean DisconnectNamedPipe(int namedPipeHandle); - - public static final native int CreateFile( - String fileName, - int desiredAccess, - int shareMode, - int securityAttributes, - int creationDisposition, - int flagsAndAttributes, - int templateFile); - - public static final native boolean WaitNamedPipe(String namedPipeName, int timeOut); - - public static final native String FormatMessage(int errorCode); - - public static final native void Print(String message); -} diff --git a/src/main/java/pipe/TestPipe.java b/src/main/java/pipe/TestPipe.java deleted file mode 100644 index f70801a..0000000 --- a/src/main/java/pipe/TestPipe.java +++ /dev/null @@ -1,103 +0,0 @@ -/** - * Copyright (C) 2016 Rik Veenboer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package pipe; - -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; - -public class TestPipe { - - private int namedPipeHandle; - private String pipeName, srcFile; - private int pipeBuffer = 131072, fileBuffer = 8192; - - public TestPipe(String pipeName, String srcFile) { - this.pipeName = pipeName; - this.srcFile = srcFile; - } - - private void log(String message) { - System.out.println(message); - } - - private boolean createPipe() { - namedPipeHandle = Pipe.CreateNamedPipe( - pipeName, - Pipe.PIPE_ACCESS_DUPLEX, - Pipe.PIPE_WAIT, - 5, - pipeBuffer, - pipeBuffer, - 0xffffffff, - 0); - if (namedPipeHandle == -1) { - log("CreateNamedPipe failed for " + pipeName + " for error Message " + Pipe.FormatMessage(Pipe.GetLastError())); - } else { - log("Named Pipe " + pipeName + " created successfully Handle=" + namedPipeHandle); - } - return namedPipeHandle != -1; - } - - private boolean connectToPipe() { - log("Waiting for a client to connect to pipe " + pipeName); - boolean connected = Pipe.ConnectNamedPipe(namedPipeHandle, 0); - if (!connected) { - int lastError = Pipe.GetLastError(); - if (lastError == Pipe.ERROR_PIPE_CONNECTED) - connected = true; - } - log((connected ? "Connected to the pipe " : "Falied to connect to the pipe ") + pipeName); - return connected; - } - - public void runPipe() { - if (createPipe() && connectToPipe()) { - log("Client connected."); - try { - File f1 = new File(this.srcFile); - InputStream in = new FileInputStream(f1); - log("Sending data to the pipe"); - byte[] buf = new byte[fileBuffer]; - int len, bytesWritten; - while ((len = in.read(buf)) > 0) { - bytesWritten = Pipe.WriteFile(namedPipeHandle, buf, len); - log("Sent " + len + "/" + bytesWritten + " bytes to the pipe"); - if (bytesWritten == -1) { - int errorNumber = Pipe.GetLastError(); - log("Error Writing to pipe " + Pipe.FormatMessage(errorNumber)); - } - } - in.close(); - Pipe.FlushFileBuffers(namedPipeHandle); - Pipe.CloseHandle(namedPipeHandle); - Pipe.DisconnectNamedPipe(namedPipeHandle); - log("Writing to the pipe completed."); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - - public static void main(String[] args) { - String pipeName = "\\\\.\\pipe\\detest"; - String fileName = "txt/mp3"; - fileName = "C:\\Users\\Rik\\Music\\Artists\\+44\\When Your Heart Stops Beating\\+44 - 155.mp3"; - TestPipe testPipe = new TestPipe(pipeName, fileName); - testPipe.runPipe(); - } -}