List of usage examples for org.apache.commons.net.io ToNetASCIIOutputStream ToNetASCIIOutputStream
public ToNetASCIIOutputStream(OutputStream output)
From source file:cn.sh.zyh.ftpserver.impl.representation.AsciiRepresentation.java
/** * Gets the output of special stream.//w ww . jav a2s . c o m * * @param socket * the socket * * @return the output stream * * @throws IOException * the IO exception * @see cn.sh.zyh.ftpserver.impl.representation.Representation#getOutputStream(java.net.Socket) */ public OutputStream getOutputStream(final Socket socket) throws IOException { return new ToNetASCIIOutputStream(socket.getOutputStream()); }
From source file:expect4j.ExpectUtils.java
/** * TODO Simulate "Could not open connection to the host, on port...." * TODO Simulate "Connection refused"//from w w w . j a v a2 s .c om */ public static Expect4j telnet(String hostname, int port) throws Exception { // This library has trouble with EOF final TelnetClient client = new TelnetClient(); TerminalTypeOptionHandler ttopt = new TerminalTypeOptionHandler("VT100", false, false, true, true); EchoOptionHandler echoopt = new EchoOptionHandler(true, false, true, false); SuppressGAOptionHandler gaopt = new SuppressGAOptionHandler(false, false, false, false); client.addOptionHandler(ttopt); client.addOptionHandler(echoopt); client.addOptionHandler(gaopt); client.connect(hostname, port); InputStream is = new FromNetASCIIInputStream(client.getInputStream()); // null until client connected OutputStream os = new ToNetASCIIOutputStream(client.getOutputStream()); StreamPair pair = new StreamPair(is, os) { public void close() { //super.close(); try { if (client != null) client.disconnect(); } catch (IOException ioe) { } } }; /* URL url=new URL("telnet", hostname, port, "", new thor.net.URLStreamHandler()); final URLConnection urlConnection=url.openConnection(); urlConnection.connect(); if (urlConnection instanceof TelnetURLConnection) { ((TelnetURLConnection)urlConnection).setTelnetTerminalHandler(new SimpleTelnetTerminalHandler()); } OutputStream os=urlConnection.getOutputStream(); InputStream is=urlConnection.getInputStream(); StreamPair pair = new StreamPair(is, os) { public void close() { try { ((TelnetURLConnection)urlConnection).disconnect(); }catch(Exception e) { } } }; */ Expect4j expect4j = new Expect4j(pair); return expect4j; }
From source file:com.atomicleopard.thundr.ftp.commons.FTPClient.java
/** * @since 3.1/*from w w w.j ava 2s . com*/ */ protected boolean _storeFile(String command, String remote, InputStream local) throws IOException { Socket socket = _openDataConnection_(command, remote); if (socket == null) { return false; } OutputStream output = getBufferedOutputStream(socket.getOutputStream()); if (__fileType == ASCII_FILE_TYPE) { output = new ToNetASCIIOutputStream(output); } CSL csl = null; if (__controlKeepAliveTimeout > 0) { csl = new CSL(this, __controlKeepAliveTimeout, __controlKeepAliveReplyTimeout); } // Treat everything else as binary for now try { Util.copyStream(local, output, getBufferSize(), CopyStreamEvent.UNKNOWN_STREAM_SIZE, __mergeListeners(csl), false); } catch (IOException e) { Util.closeQuietly(socket); // ignore close errors here if (csl != null) { csl.cleanUp(); // fetch any outstanding keepalive replies } throw e; } output.close(); // ensure the file is fully written socket.close(); // done writing the file if (csl != null) { csl.cleanUp(); // fetch any outstanding keepalive replies } // Get the transfer response boolean ok = completePendingCommand(); return ok; }
From source file:com.atomicleopard.thundr.ftp.commons.FTPClient.java
/** * @since 3.1//from www. ja va 2 s . co m */ protected OutputStream _storeFileStream(String command, String remote) throws IOException { Socket socket = _openDataConnection_(command, remote); if (socket == null) { return null; } OutputStream output = socket.getOutputStream(); if (__fileType == ASCII_FILE_TYPE) { // We buffer ascii transfers because the buffering has to // be interposed between ToNetASCIIOutputSream and the underlying // socket output stream. We don't buffer binary transfers // because we don't want to impose a buffering policy on the // programmer if possible. Programmers can decide on their // own if they want to wrap the SocketOutputStream we return // for file types other than ASCII. output = getBufferedOutputStream(output); output = new ToNetASCIIOutputStream(output); } return new org.apache.commons.net.io.SocketOutputStream(socket, output); }