public ApacheUnixSocket() throws IOException { this.inner = AFUNIXSocket.newInstance(); }
@Override public void connect(final SocketAddress endpoint, final int timeout) throws IOException { inner.connect(endpoint, timeout); setAllSocketOptions(); }
@Override public InputStream getInputStream() throws IOException { return inner.getInputStream(); }
"junixsocket-test.sock"); try (AFUNIXSocket sock = AFUNIXSocket.newInstance()) { try { sock.connect(new AFUNIXSocketAddress(socketFile)); } catch (SocketException e) { System.out.println("Cannot connect to server. Have you started it?"); try (InputStream is = sock.getInputStream(); // OutputStream os = sock.getOutputStream();) {
/** * Creates a new {@link AFUNIXSocket} and connects it to the given {@link AFUNIXSocketAddress}. * * @param addr The address to connect to. * @return A new, connected socket. * @throws IOException if the operation fails. */ public static AFUNIXSocket connectTo(AFUNIXSocketAddress addr) throws IOException { AFUNIXSocket socket = newInstance(); socket.connect(addr); return socket; }
((AFUNIXSocket) socket).setSoTimeout((int) timeUnit.toMillis(timeout)); ((AFUNIXSocket) socket).connect(new AFUNIXSocketAddress(socketFile));
@Override public OutputStream getOutputStream() throws IOException { return inner.getOutputStream(); }
@Override public synchronized void close() throws IOException { inner.close(); }
@Override public boolean isConnected() { return inner.isConnected(); }
@Override public void run() throws SocketException { inner.setSoTimeout(timeout); } });
@Override public Socket connect(String host, int portNumber, Properties props) throws SocketException, IOException { // Adjust the path to your MySQL socket by setting the // "junixsocket.file" property // If no socket path is given, use the default: /tmp/mysql.sock final File socketFile = new File(props.getProperty("junixsocket.file", "/tmp/mysql.sock")); socket = AFUNIXSocket.connectTo(new AFUNIXSocketAddress(socketFile)); return socket; } }
/** * Creates a new {@link AFUNIXSocket} and connects it to the given {@link AFUNIXSocketAddress}. * * @param addr The address to connect to. * @return A new, connected socket. */ public static AFUNIXSocket connectTo(AFUNIXSocketAddress addr) throws IOException { AFUNIXSocket socket = newInstance(); socket.connect(addr); return socket; }
((AFUNIXSocket) socket).setSoTimeout((int) timeUnit.toMillis(timeout)); ((AFUNIXSocket) socket).connect(new AFUNIXSocketAddress(socketFile));
@Override public OutputStream getOutputStream() throws IOException { return inner.getOutputStream(); }
/** * {@inheritDoc} */ public void detach() throws IOException { ((AFUNIXSocket) this.socket).close(); } }
private void setSocketOption(final SocketOptionSetter s) throws SocketException { if (inner.isConnected()) { s.run(); } else { if (!optionsToSet.offer(s)) { throw new SocketException("Failed to queue option"); } } }
@Override public void run() throws SocketException { inner.setSoTimeout(timeout); } });
@Override public Socket createSocket(String host, int port) throws IOException, UnknownHostException { if (!isHostnameSupported(host)) { throw new UnknownHostException(); } if (port < 0) { throw new IllegalArgumentException("Illegal port"); } AFUNIXSocketAddress socketAddress = addressFromHost(host, port); String socketFile = socketAddress.getSocketFile(); if (socketFile == null || socketFile.isEmpty()) { throw new UnknownHostException("Illegal socketFile"); } File file = new File(socketFile); if (!file.exists()) { throw new UnknownHostException("Socketfile does not exist"); } return AFUNIXSocket.connectTo(socketAddress); }
UnixPipe(IPCClient ipcClient, HashMap<String, Callback> callbacks, String location) throws IOException { super(ipcClient, callbacks); socket = AFUNIXSocket.newInstance(); socket.connect(new AFUNIXSocketAddress(new File(location))); }
@Override public Socket createSocket(HttpParams params) throws IOException { AFUNIXSocket socket = AFUNIXSocket.newInstance(); return socket; }