Example usage for org.apache.commons.net.io FromNetASCIIInputStream FromNetASCIIInputStream

List of usage examples for org.apache.commons.net.io FromNetASCIIInputStream FromNetASCIIInputStream

Introduction

In this page you can find the example usage for org.apache.commons.net.io FromNetASCIIInputStream FromNetASCIIInputStream.

Prototype

public FromNetASCIIInputStream(InputStream input) 

Source Link

Document

Creates a FromNetASCIIInputStream instance that wraps an existing InputStream.

Usage

From source file:cn.sh.zyh.ftpserver.impl.representation.AsciiRepresentation.java

/**
 * Gets the input stream of special socket.
 * //from  ww  w .  j ava2  s  . c o m
 * @param socket
 *            the socket
 * 
 * @return the input stream
 * 
 * @throws IOException
 *             the IO exception
 * @see cn.sh.zyh.ftpserver.impl.representation.Representation#getInputStream(java.net.Socket)
 */
public InputStream getInputStream(final Socket socket) throws IOException {
    return new FromNetASCIIInputStream(socket.getInputStream());
}

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. jav 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/* w  ww.  j  a  v a  2 s  .c o  m*/
 */
protected boolean _retrieveFile(String command, String remote, OutputStream local) throws IOException {
    Socket socket = _openDataConnection_(command, remote);

    if (socket == null) {
        return false;
    }

    InputStream input = getBufferedInputStream(socket.getInputStream());
    if (__fileType == ASCII_FILE_TYPE) {
        input = new FromNetASCIIInputStream(input);
    }

    CSL csl = null;
    if (__controlKeepAliveTimeout > 0) {
        csl = new CSL(this, __controlKeepAliveTimeout, __controlKeepAliveReplyTimeout);
    }

    // Treat everything else as binary for now
    try {
        Util.copyStream(input, local, getBufferSize(), CopyStreamEvent.UNKNOWN_STREAM_SIZE,
                __mergeListeners(csl), false);
    } finally {
        Util.closeQuietly(input);
        Util.closeQuietly(socket);
        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  w w  w  .  ja va  2s . c  o  m
 */
protected InputStream _retrieveFileStream(String command, String remote) throws IOException {
    Socket socket = _openDataConnection_(command, remote);

    if (socket == null) {
        return null;
    }

    InputStream input = socket.getInputStream();
    if (__fileType == ASCII_FILE_TYPE) {
        // We buffer ascii transfers because the buffering has to
        // be interposed between FromNetASCIIOutputSream and the underlying
        // socket input 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 SocketInputStream we return
        // for file types other than ASCII.
        input = getBufferedInputStream(input);
        input = new FromNetASCIIInputStream(input);
    }
    return new org.apache.commons.net.io.SocketInputStream(socket, input);
}

From source file:org.opendaylight.snmp4sdn.internal.ExpectHandler.java

public ExpectHandler(String sw_ipAddr, String username_prompt, String password_prompt, String username,
        String password) throws Exception {
    if (isDummy)//from   w w w.  j  a va 2 s  . c  o  m
        return;
    this.sw_ipAddr = new String(sw_ipAddr);
    this.username_prompt = new String(username_prompt);
    this.password_prompt = new String(password_prompt);
    this.username = new String(username);
    this.password = new String(password);
    System.out.println("NexusCLIHandler() sw_ipaddr:" + sw_ipAddr);
    client = new TelnetClient();
    //client.connect(sw_ipAddr);
    //read();
    //write(username.getBytes());
    //client.disconnect();
    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(sw_ipAddr, 23);
    //System.out.println("after login"); 
    //writer = new OutputStreamWriter(os); 
    out = new PrintStream(client.getOutputStream());
    telnetLogin();
    InputStream is = new FromNetASCIIInputStream(client.getInputStream()); // null until client connected
    //OutputStream os = new ToNetASCIIOutputStream( client.getOutputStream() );
    reader = new InputStreamReader(is);

    //executeNexus("show vlan"); 
    //sendCommand("show vlan");
    //disconnect();
}