Skip to content

Commit

Permalink
Minor code refactoring for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
elecharny committed Jan 7, 2025
1 parent bc14387 commit 583db0b
Show file tree
Hide file tree
Showing 19 changed files with 82 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
public interface Authentication {

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ public AuthenticationFailedException() {
* Constructs a <code>AuthenticationFailedException</code> object with a
* message.
*
* @param msg
* A description of the exception
* @param msg A description of the exception
*/
public AuthenticationFailedException(String msg) {
super(msg);
Expand All @@ -49,8 +48,7 @@ public AuthenticationFailedException(String msg) {
* Constructs a <code>AuthenticationFailedException</code> object with a
* <code>Throwable</code> cause.
*
* @param th
* The original cause
* @param th The original cause
*/
public AuthenticationFailedException(Throwable th) {
super(th);
Expand All @@ -61,8 +59,7 @@ public AuthenticationFailedException(Throwable th) {
* <code>Throwable</code> cause.
* @param msg A description of the exception
*
* @param th
* The original cause
* @param th The original cause
*/
public AuthenticationFailedException(String msg, Throwable th) {
super(msg, th);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,18 @@
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
public interface Authority {

/**
* Indicates weather this Authority can authorize a certain request
*
* @param request
* The request to authorize
* @param request The request to authorize
* @return True if the request can be authorized by this Authority
*/
boolean canAuthorize(AuthorizationRequest request);

/**
* Authorize an {@link AuthorizationRequest}.
*
* @param request
* The {@link AuthorizationRequest}
* @param request The {@link AuthorizationRequest}
* @return Returns a populated AuthorizationRequest as long as If
* {@link #canAuthorize(AuthorizationRequest)} returns <code>true</code> for the
* AuthorizationRequest, otherwise returns <code>null</code>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
public interface AuthorizationRequest {

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,32 @@
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
public interface DataConnection {

/**
* Transfer data from the client (e.g. STOR).
*
* @param session The current {@link FtpSession}
* @param out
* The {@link OutputStream} containing the destination of the
* @param out The {@link OutputStream} containing the destination of the
* data from the client.
* @return The length of the transferred data
* @throws IOException If the transfer failed
*/
long transferFromClient(FtpSession session, OutputStream out)
throws IOException;
long transferFromClient(FtpSession session, OutputStream out) throws IOException;

/**
* Transfer data to the client (e.g. RETR).
*
* @param session The current {@link FtpSession}
* @param in
* Data to be transfered to the client
* @param in Data to be transfered to the client
* @return The length of the transferred data
* @throws IOException If the transfer failed
*/
long transferToClient(FtpSession session, InputStream in)
throws IOException;
long transferToClient(FtpSession session, InputStream in) throws IOException;

/**
* Transfer a string to the client, e.g. during LIST
*
* @param session The current {@link FtpSession}
* @param str
* The string to transfer
* @param str The string to transfer
* @throws IOException If the transfer failed
*/
void transferToClient(FtpSession session, String str) throws IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
public interface DataConnectionFactory {

/**
* Open an active data connection
*
Expand All @@ -40,7 +39,6 @@ public interface DataConnectionFactory {
*
* @return <code>true</code> if the data socket will be secured
*/

boolean isSecure();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
* etc.
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*
*/

public interface DataTransferFtpReply extends FileActionFtpReply {
Expand Down
23 changes: 10 additions & 13 deletions ftplet-api/src/main/java/org/apache/ftpserver/ftplet/DataType.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
public enum DataType {

/**
* Binary data type
*/
Expand All @@ -39,22 +38,20 @@ public enum DataType {
/**
* Parses the argument value from the TYPE command into the type safe class
*
* @param argument
* The argument value from the TYPE command. Not case sensitive
* @param argument The argument value from the TYPE command. Not case sensitive
* @return The appropriate data type
* @throws IllegalArgumentException
* If the data type is unknown
* @throws IllegalArgumentException If the data type is unknown
*/
public static DataType parseArgument(char argument) {
switch (argument) {
case 'A':
case 'a':
return ASCII;
case 'I':
case 'i':
return BINARY;
default:
throw new IllegalArgumentException("Unknown data type: " + argument);
case 'A':
case 'a':
return ASCII;
case 'I':
case 'i':
return BINARY;
default:
throw new IllegalArgumentException("Unknown data type: " + argument);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
public class DefaultFtpReply implements FtpReply {

/** The reply code */
private int code;

/** The reply message */
private String message;

/**
* time when this reply was sent.
*/
/** time when this reply was sent. */
private long sentTime = 0L;

private static final String CRLF = "\r\n";

/**
* Constructor for single-line messages
*
* @param code The reply code
* @param message The reply message
*/
Expand All @@ -51,17 +51,20 @@ public DefaultFtpReply(final int code, final String message) {

/**
* Constructor for multi-line replies
*
* @param code The reply code
* @param message The reply message, one line per String
* @param messageLines The reply message, one line per String
*/
public DefaultFtpReply(final int code, final String[] message) {
public DefaultFtpReply(final int code, final String[] messageLines) {
this.code = code;

StringBuilder sb = new StringBuilder();
for (int i = 0; i < message.length; i++) {
sb.append(message[i]);

for (String line:messageLines) {
sb.append(line);
sb.append('\n');
}

this.message = sb.toString();
this.sentTime = System.currentTimeMillis();
}
Expand Down Expand Up @@ -89,7 +92,7 @@ public boolean isPositive() {
}

private boolean isDigit(char c) {
return c >= 48 && c <= 57;
return c >= '0' && c <= '9';
}

/*
Expand All @@ -101,6 +104,7 @@ private boolean isDigit(char c) {
public String toString() {
int code = getCode();
String notNullMessage = getMessage();

if (notNullMessage == null) {
notNullMessage = "";
}
Expand All @@ -124,7 +128,6 @@ public String toString() {
sb.append(notNullMessage);
sb.append(CRLF);
} else {

sb.append(code);
sb.append("-");

Expand All @@ -143,10 +146,10 @@ public String toString() {
&& line.length() > 2
&& isDigit(line.charAt(0))
&& isDigit(line.charAt(1))
&& isDigit(line.charAt(2))
) {
&& isDigit(line.charAt(2))) {
sb.append(" ");
}

sb.append(line);
sb.append(CRLF);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@
* single file or directory such as MKD, DELE, RMD etc.
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*
*/

public interface FileActionFtpReply extends FtpReply {

/**
* Returns the file (or directory) on which the action was taken
* (e.g. uploaded, created, listed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
public class FtpException extends Exception {

private static final long serialVersionUID = -1328383839915898987L;

/**
Expand All @@ -39,8 +38,7 @@ public FtpException() {
/**
* Constructs a <code>FtpException</code> object with a message.
*
* @param msg
* a description of the exception
* @param msg a description of the exception
*/
public FtpException(String msg) {
super(msg);
Expand All @@ -50,8 +48,7 @@ public FtpException(String msg) {
* Constructs a <code>FtpException</code> object with a
* <code>Throwable</code> cause.
*
* @param th
* the original cause
* @param th the original cause
*/
public FtpException(Throwable th) {
super(th.getMessage());
Expand All @@ -60,17 +57,17 @@ public FtpException(Throwable th) {
/**
* Constructs a <code>BaseException</code> object with a
* <code>Throwable</code> cause.
* @param msg A description of the exception
*
* @param th
* The original cause
* @param msg A description of the exception
* @param th The original cause
*/
public FtpException(String msg, Throwable th) {
super(msg);
}

/**
* Get the root cause.
*
* @return The root cause
* @deprecated Use {@link Exception#getCause()} instead
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
public interface FtpReply {

/**
* 110 Restart marker reply. In this case, the text is exact and not left to
* the particular implementation; it must read: MARK yyyy = mmmm Where yyyy
Expand Down Expand Up @@ -264,6 +263,7 @@ public interface FtpReply {

/**
* Tells whether or not this reply indicates a positive completion.
*
* @return <code>true</code>, if this reply is a positive completion or
* positive intermediate reply; <code>false</code>, otherwise.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,23 @@
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
public interface FtpRequest {

/**
* Get the client request string.
*
* @return The full request line, e.g. "MKDIR newdir"
*/
String getRequestLine();

/**
* Returns the ftp request command.
*
* @return The command part of the request line, e.g. "MKDIR"
*/
String getCommand();

/**
* Get the ftp request argument.
*
* @return The argument part of the request line, e.g. "newdir"
*/
String getArgument();
Expand Down
Loading

0 comments on commit 583db0b

Please sign in to comment.