/** * If there are any listeners, send them the reply details. * * @param replyCode the code extracted from the reply * @param reply the full reply text * @since 3.0 */ protected void fireReplyReceived(int replyCode, String reply) { if (getCommandSupport().getListenerCount() > 0) { getCommandSupport().fireReplyReceived(replyCode, reply); } }
/** * Create the CommandSupport instance if required */ protected void createCommandSupport(){ __commandSupport = new ProtocolCommandSupport(this); }
/** * Adds a ProtocolCommandListener. * * @param listener The ProtocolCommandListener to add. * @since 3.0 */ public void addProtocolCommandListener(ProtocolCommandListener listener) { getCommandSupport().addProtocolCommandListener(listener); }
/** * If there are any listeners, send them the command details. * * @param command the command name * @param message the complete message, including command name * @since 3.0 */ protected void fireCommandSent(String command, String message) { if (getCommandSupport().getListenerCount() > 0) { getCommandSupport().fireCommandSent(command, message); } }
/** * Removes a ProtocolCommandListener. * * @param listener The ProtocolCommandListener to remove. * @since 3.0 */ public void removeProtocolCommandListener(ProtocolCommandListener listener) { getCommandSupport().removeProtocolCommandListener(listener); }
public List<String> list(final FTPCmd command, final String pathname) throws IOException { this.pret(command, pathname); Socket socket = _openDataConnection_(command, pathname); BufferedReader reader = new BufferedReader( new InputStreamReader(socket.getInputStream(), getControlEncoding())); ArrayList<String> results = new ArrayList<String>(); String line; while((line = reader.readLine()) != null) { _commandSupport_.fireReplyReceived(-1, line); results.add(line); } reader.close(); socket.close(); if(!this.completePendingCommand()) { throw new FTPException(this.getReplyCode(), this.getReplyString()); } return results; }
private int __sendCommand(String command, String args, boolean includeSpace) throws IOException { String message; __commandBuffer.setLength(0); __commandBuffer.append(command); if (args != null) { if (includeSpace) __commandBuffer.append(' '); __commandBuffer.append(args); } __commandBuffer.append(SocketClient.NETASCII_EOL); _writer.write(message = __commandBuffer.toString()); _writer.flush(); if (_commandSupport_.getListenerCount() > 0) _commandSupport_.fireCommandSent(command, message); __getReply(); return _replyCode; }
/*** * Removes a ProtocolCommandListener. Delegates this task to * {@link #_commandSupport_ _commandSupport_ }. * <p> * @param listener The ProtocolCommandListener to remove. ***/ public void removeProtocolCommandListener(ProtocolCommandListener listener) { _commandSupport_.removeProtocolCommandListener(listener); }
/** * Overrides {@link SocketClient#fireReplyReceived(int, String)} so as to * avoid creating the reply string if there are no listeners to invoke. * * @param replyCode passed to the listeners * @param ignored the string is only created if there are listeners defined. * @see #getReplyString() * @since 3.4 */ @Override protected void fireReplyReceived(int replyCode, String ignored) { if (getCommandSupport().getListenerCount() > 0) { getCommandSupport().fireReplyReceived(replyCode, getReplyString()); } }
private int __sendCommand(String command, String args, boolean includeSpace) throws IOException { String message; __commandBuffer.setLength(0); __commandBuffer.append(command); if (args != null) { if (includeSpace) __commandBuffer.append(' '); __commandBuffer.append(args); } __commandBuffer.append(SocketClient.NETASCII_EOL); _writer.write(message = __commandBuffer.toString()); _writer.flush(); if (_commandSupport_.getListenerCount() > 0) _commandSupport_.fireCommandSent(command, message); __getReply(); return _replyCode; }
/*** * The default POP3Client constructor. Initializes the state * to <code>DISCONNECTED_STATE</code>. ***/ public POP3() { setDefaultPort(DEFAULT_PORT); __popState = DISCONNECTED_STATE; _reader = null; _writer = null; _replyLines = new ArrayList<String>(); _commandSupport_ = new ProtocolCommandSupport(this); }
/*** * Removes a ProtocolCommandListener. Delegates this task to * {@link #_commandSupport_ _commandSupport_ }. * <p> * @param listener The ProtocolCommandListener to remove. ***/ public void removeProtocolCommandListener(ProtocolCommandListener listener) { _commandSupport_.removeProtocolCommandListener(listener); }
/*** * Adds a ProtocolCommandListener. Delegates this task to * {@link #_commandSupport_ _commandSupport_ }. * <p> * @param listener The ProtocolCommandListener to add. ***/ public void addProtocolCommandListener(ProtocolCommandListener listener) { _commandSupport_.addProtocolCommandListener(listener); }
private void __getReply() throws IOException { String line; _replyLines.setSize(0); line = _reader.readLine(); if (line == null) throw new EOFException("Connection closed without indication."); if (line.startsWith(_OK)) _replyCode = POP3Reply.OK; else if (line.startsWith(_ERROR)) _replyCode = POP3Reply.ERROR; else throw new MalformedServerReplyException( "Received invalid POP3 protocol response from server."); _replyLines.addElement(line); _lastReplyLine = line; if (_commandSupport_.getListenerCount() > 0) _commandSupport_.fireReplyReceived(_replyCode, getReplyString()); }
/*** * Sends a command an arguments to the server and returns the reply code. * <p> * @param command The POP3 command to send. * @param args The command arguments. * @return The server reply code (either POP3Reply.OK or POP3Reply.ERROR). ***/ public int sendCommand(String command, String args) throws IOException { String message; __commandBuffer.setLength(0); __commandBuffer.append(command); if (args != null) { __commandBuffer.append(' '); __commandBuffer.append(args); } __commandBuffer.append(SocketClient.NETASCII_EOL); __writer.write(message = __commandBuffer.toString()); __writer.flush(); if (_commandSupport_.getListenerCount() > 0) _commandSupport_.fireCommandSent(command, message); __getReply(); return _replyCode; }
/** * Overloaded constructor where the user may specify a default encoding. * @param encoding the encoing to use * @since 2.0 */ public SMTP(String encoding) { setDefaultPort(DEFAULT_PORT); _replyLines = new ArrayList<String>(); _newReplyString = false; _replyString = null; _commandSupport_ = new ProtocolCommandSupport(this); this.encoding = encoding; }
/*** * Removes a ProtocolCommandListener. Delegates this task to * {@link #_commandSupport_ _commandSupport_ }. * <p> * @param listener The ProtocolCommandListener to remove. ***/ public void removeProtocolCommandistener(ProtocolCommandListener listener) { _commandSupport_.removeProtocolCommandListener(listener); }
/*** * Adds a ProtocolCommandListener. Delegates this task to * {@link #_commandSupport_ _commandSupport_ }. * <p> * @param listener The ProtocolCommandListener to add. ***/ public void addProtocolCommandListener(ProtocolCommandListener listener) { _commandSupport_.addProtocolCommandListener(listener); }
private void __getReply() throws IOException { String line; _replyLines.setSize(0); line = _reader.readLine(); if (line == null) throw new EOFException("Connection closed without indication."); if (line.startsWith(_OK)) _replyCode = POP3Reply.OK; else if (line.startsWith(_ERROR)) _replyCode = POP3Reply.ERROR; else throw new MalformedServerReplyException( "Received invalid POP3 protocol response from server."); _replyLines.addElement(line); _lastReplyLine = line; if (_commandSupport_.getListenerCount() > 0) _commandSupport_.fireReplyReceived(_replyCode, getReplyString()); }
/*** * Sends a command an arguments to the server and returns the reply code. * <p> * @param command The POP3 command to send. * @param args The command arguments. * @return The server reply code (either POP3Reply.OK or POP3Reply.ERROR). ***/ public int sendCommand(String command, String args) throws IOException { String message; __commandBuffer.setLength(0); __commandBuffer.append(command); if (args != null) { __commandBuffer.append(' '); __commandBuffer.append(args); } __commandBuffer.append(SocketClient.NETASCII_EOL); __writer.write(message = __commandBuffer.toString()); __writer.flush(); if (_commandSupport_.getListenerCount() > 0) _commandSupport_.fireCommandSent(command, message); __getReply(); return _replyCode; }