/** * @param command the command to send * @param remote the remote file name * @return the stream from which to read the file * @throws IOException on error * @since 3.1 */ protected InputStream _retrieveFileStream(String command, String remote) throws IOException { Socket socket = _openDataConnection_(command, remote); if (socket == null) { return null; } final InputStream input; 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 = new FromNetASCIIInputStream(getBufferedInputStream(socket.getInputStream())); } else { input = socket.getInputStream(); } return new org.apache.commons.net.io.SocketInputStream(socket, input); }
/*** * Reads the next number of bytes from the stream into an array and * returns the number of bytes read. Returns -1 if the end of the * stream has been reached. * * @param buffer The byte array in which to store the data. * @return The number of bytes read. Returns -1 if the * end of the message has been reached. * @throws IOException If an error occurs in reading the underlying * stream. ***/ @Override public int read(byte buffer[]) throws IOException { return read(buffer, 0, buffer.length); }
/*** * Handles special connection requirements. * <p> * @exception IOException If an error occurs during connection setup. ***/ protected void _connectAction_() throws IOException { super._connectAction_(); InputStream input; TelnetInputStream tmp; if (FromNetASCIIInputStream.isConversionRequired()) input = new FromNetASCIIInputStream(_input_); else input = _input_; tmp = new TelnetInputStream(input, this, readerThread); if(readerThread) { tmp._start(); } // __input CANNOT refer to the TelnetInputStream. We run into // blocking problems when some classes use TelnetInputStream, so // we wrap it with a BufferedInputStream which we know is safe. // This blocking behavior requires further investigation, but right // now it looks like classes like InputStreamReader are not implemented // in a safe manner. __input = new BufferedInputStream(tmp); __output = new ToNetASCIIOutputStream(new TelnetOutputStream(this)); }
/*** * Reads and returns the next byte in the stream. If the end of the * message has been reached, returns -1. Note that a call to this method * may result in multiple reads from the underlying input stream in order * to convert NETASCII line separators to the local line separator format. * This is transparent to the programmer and is only mentioned for * completeness. * * @return The next character in the stream. Returns -1 if the end of the * stream has been reached. * @throws IOException If an error occurs while reading the underlying * stream. ***/ @Override public int read() throws IOException { if (_noConversionRequired) { return super.read(); } return __read(); }
private int __read() throws IOException { int ch; ch = super.read(); if (ch == '\r') { ch = super.read(); if (ch == '\n') { unread(_lineSeparatorBytes); ch = super.read(); // This is a kluge for read(byte[], ...) to read the right amount --__length; } else { if (ch != -1) { unread(ch); } return '\r'; } } return ch; }
/*** * Handles special connection requirements. * <p> * @exception IOException If an error occurs during connection setup. ***/ @Override protected void _connectAction_() throws IOException { super._connectAction_(); InputStream input; TelnetInputStream tmp; if (FromNetASCIIInputStream.isConversionRequired()) input = new FromNetASCIIInputStream(_input_); else input = _input_; tmp = new TelnetInputStream(input, this, readerThread); if(readerThread) { tmp._start(); } // __input CANNOT refer to the TelnetInputStream. We run into // blocking problems when some classes use TelnetInputStream, so // we wrap it with a BufferedInputStream which we know is safe. // This blocking behavior requires further investigation, but right // now it looks like classes like InputStreamReader are not implemented // in a safe manner. __input = new BufferedInputStream(tmp); __output = new ToNetASCIIOutputStream(new TelnetOutputStream(this)); }
/*** * Reads and returns the next byte in the stream. If the end of the * message has been reached, returns -1. Note that a call to this method * may result in multiple reads from the underlying input stream in order * to convert NETASCII line separators to the local line separator format. * This is transparent to the programmer and is only mentioned for * completeness. * <p> * @return The next character in the stream. Returns -1 if the end of the * stream has been reached. * @exception IOException If an error occurs while reading the underlying * stream. ***/ public int read() throws IOException { if (_noConversionRequired) return super.read(); return __read(); }
private int __read() throws IOException { int ch; ch = super.read(); if (ch == '\r') { ch = super.read(); if (ch == '\n') { unread(_lineSeparatorBytes); ch = super.read(); // This is a kluge for read(byte[], ...) to read the right amount --__length; } else { if (ch != -1) unread(ch); return '\r'; } } return ch; }
input = new FromNetASCIIInputStream(getBufferedInputStream(socket.getInputStream())); } else { input = getBufferedInputStream(socket.getInputStream());
/*** * Reads the next number of bytes from the stream into an array and * returns the number of bytes read. Returns -1 if the end of the * stream has been reached. * <p> * @param buffer The byte array in which to store the data. * @return The number of bytes read. Returns -1 if the * end of the message has been reached. * @exception IOException If an error occurs in reading the underlying * stream. ***/ public int read(byte buffer[]) throws IOException { return read(buffer, 0, buffer.length); }
/*** * Reads and returns the next byte in the stream. If the end of the * message has been reached, returns -1. Note that a call to this method * may result in multiple reads from the underlying input stream in order * to convert NETASCII line separators to the local line separator format. * This is transparent to the programmer and is only mentioned for * completeness. * <p> * @return The next character in the stream. Returns -1 if the end of the * stream has been reached. * @exception IOException If an error occurs while reading the underlying * stream. ***/ @Override public int read() throws IOException { if (_noConversionRequired) return super.read(); return __read(); }
private int __read() throws IOException { int ch; ch = super.read(); if (ch == '\r') { ch = super.read(); if (ch == '\n') { unread(_lineSeparatorBytes); ch = super.read(); // This is a kluge for read(byte[], ...) to read the right amount --__length; } else { if (ch != -1) unread(ch); return '\r'; } } return ch; }
input = new FromNetASCIIInputStream(input);
/*** * Reads the next number of bytes from the stream into an array and * returns the number of bytes read. Returns -1 if the end of the * stream has been reached. * <p> * @param buffer The byte array in which to store the data. * @return The number of bytes read. Returns -1 if the * end of the message has been reached. * @exception IOException If an error occurs in reading the underlying * stream. ***/ @Override public int read(byte buffer[]) throws IOException { return read(buffer, 0, buffer.length); }
input = new FromNetASCIIInputStream(input);
getBufferSize()); if (__fileType == ASCII_FILE_TYPE) input = new FromNetASCIIInputStream(input);
getBufferSize()); if (__fileType == ASCII_FILE_TYPE) input = new FromNetASCIIInputStream(input);