Skip to content
Permalink
Browse files
No need to nest in else.
  • Loading branch information
garydgregory committed Mar 5, 2021
1 parent c6efd4a commit 5d5d0c09d3c8fbfcf26976ff1a661a06f201d082
Showing 24 changed files with 180 additions and 217 deletions.
@@ -276,7 +276,8 @@ public void rexec(final String username, final String password,
}

throw new IOException(buffer.toString());
} else if (ch < 0) {
}
if (ch < 0) {
throw new IOException("Server closed connection.");
}
}
@@ -190,19 +190,15 @@ public static void main(final String[] args)
// transfer is completed (in the case of passive mode transfers).
// Therefore, calling store first would hang waiting for a preliminary
// reply.
if (ftp1.remoteRetrieve(file1) && ftp2.remoteStoreUnique(file2))
{
// if(ftp1.remoteRetrieve(file1) && ftp2.remoteStore(file2)) {
// We have to fetch the positive completion reply.
ftp1.completePendingCommand();
ftp2.completePendingCommand();
}
else
{
if (!ftp1.remoteRetrieve(file1) || !ftp2.remoteStoreUnique(file2)) {
System.err.println(
"Couldn't initiate transfer. Check that file names are valid.");
break __main;
}
// if(ftp1.remoteRetrieve(file1) && ftp2.remoteStore(file2)) {
// We have to fetch the positive completion reply.
ftp1.completePendingCommand();
ftp2.completePendingCommand();

}
catch (final IOException e)
@@ -99,27 +99,26 @@ public static void main(final String[] args)
for (argc = 0; argc < args.length; argc++)
{
arg = args[argc];
if (arg.startsWith("-")) {
if (arg.equals("-r")) {
receiveFile = true;
} else if (arg.equals("-s")) {
receiveFile = false;
} else if (arg.equals("-a")) {
transferMode = TFTP.ASCII_MODE;
} else if (arg.equals("-b")) {
transferMode = TFTP.BINARY_MODE;
} else if (arg.equals("-t")) {
timeout = 1000 * Integer.parseInt(args[++argc]);
} else if (arg.equals("-v")) {
verbose = true;
} else {
System.err.println("Error: unrecognized option.");
System.err.print(USAGE);
System.exit(1);
}
} else {
if (!arg.startsWith("-")) {
break;
}
if (arg.equals("-r")) {
receiveFile = true;
} else if (arg.equals("-s")) {
receiveFile = false;
} else if (arg.equals("-a")) {
transferMode = TFTP.ASCII_MODE;
} else if (arg.equals("-b")) {
transferMode = TFTP.BINARY_MODE;
} else if (arg.equals("-t")) {
timeout = 1000 * Integer.parseInt(args[++argc]);
} else if (arg.equals("-v")) {
verbose = true;
} else {
System.err.println("Error: unrecognized option.");
System.err.print(USAGE);
System.exit(1);
}
}

// Make sure there are enough arguments
@@ -287,12 +287,11 @@ public static void main(final String[] args) throws IOException, URISyntaxExcept
uri = URI.create(uriString);
} catch(final IllegalArgumentException e) { // cannot parse the path as is; let's pull it apart and try again
final Matcher m = Pattern.compile("(imaps?://[^/]+)(/.*)").matcher(uriString);
if (m.matches()) {
uri = URI.create(m.group(1)); // Just the scheme and auth parts
uri = new URI(uri.getScheme(), uri.getAuthority(), m.group(2), null, null);
} else {
if (!m.matches()) {
throw e;
}
uri = URI.create(m.group(1)); // Just the scheme and auth parts
uri = new URI(uri.getScheme(), uri.getAuthority(), m.group(2), null, null);
}
final String file = args[argIdx++];
String sequenceSet = argCount > 2 ? args[argIdx++] : "1:*";
@@ -385,22 +384,20 @@ public void protocolReplyReceived(final ProtocolCommandEvent event) {
while (true) {
final boolean ok = imap.fetch(sequenceSet, itemNames);
// If the fetch failed, can we retry?
if (!ok && retryWaitSecs > 0 && mboxListener != null && checkSequence) {
final String replyString = imap.getReplyString(); //includes EOL
if (startsWith(replyString, PATTEMPFAIL)) {
System.err.println("Temporary error detected, will retry in " + retryWaitSecs + "seconds");
sequenceSet = mboxListener.lastSeq+1+":*";
try {
Thread.sleep(retryWaitSecs * 1000);
} catch (final InterruptedException e) {
// ignored
}
} else {
throw new IOException("FETCH " + sequenceSet + " " + itemNames+ " failed with " + replyString);
}
} else {
if (ok || (retryWaitSecs <= 0) || (mboxListener == null) || !checkSequence) {
break;
}
final String replyString = imap.getReplyString(); //includes EOL
if (!startsWith(replyString, PATTEMPFAIL)) {
throw new IOException("FETCH " + sequenceSet + " " + itemNames+ " failed with " + replyString);
}
System.err.println("Temporary error detected, will retry in " + retryWaitSecs + "seconds");
sequenceSet = mboxListener.lastSeq+1+":*";
try {
Thread.sleep(retryWaitSecs * 1000);
} catch (final InterruptedException e) {
// ignored
}
}

} catch (final IOException ioe) {
@@ -54,11 +54,10 @@ public static void main(final String[] args)
int argIdx;
String file = null;
for(argIdx = 0; argIdx < args.length; argIdx++) {
if (args[argIdx].equals("-F")) {
file = args[++argIdx];
} else {
if (!args[argIdx].equals("-F")) {
break;
}
file = args[++argIdx];
}

final int argCount = args.length - argIdx;
@@ -124,7 +124,7 @@ public static void main(final String[] args)
pop3.disconnect();
return;
}
else if (messages.length == 0)
if (messages.length == 0)
{
System.out.println("No messages");
pop3.logout();
@@ -48,12 +48,11 @@ static String getPassword(final String username, String password) throws IOExcep
password = in.readLine();
} else if ("*".equals(password)) { // console
final Console con = System.console(); // Java 1.6
if (con != null) {
final char[] pwd = con.readPassword("Password for " + username + ": ");
password = new String(pwd);
} else {
if (con == null) {
throw new IOException("Cannot access Console");
}
final char[] pwd = con.readPassword("Password for " + username + ": ");
password = new String(pwd);
} else if (password.equals(password.toUpperCase(Locale.ROOT))) { // environment variable name
final String tmp = System.getenv(password);
if (tmp != null) { // don't overwrite if variable does not exist (just in case password is all uppers)
@@ -775,7 +775,8 @@ private int getReply(final boolean reportReply) throws IOException
} else if (isStrictReplyParsing()) {
if (length == REPLY_CODE_LEN + 1) { // expecting some text
throw new MalformedServerReplyException("Truncated server reply: '" + line +"'");
} else if (sep != ' ') {
}
if (sep != ' ') {
throw new MalformedServerReplyException("Invalid server reply: '" + line +"'");
}
}
@@ -2110,11 +2110,10 @@ public String getSystemType() throws IOException
} else {
// Check if the user has provided a default for when the SYST command fails
final String systDefault = System.getProperty(FTP_SYSTEM_TYPE_DEFAULT);
if (systDefault != null) {
systemName = systDefault;
} else {
if (systDefault == null) {
throw new IOException("Unable to determine system type - response: " + getReplyString());
}
systemName = systDefault;
}
}
return systemName;
@@ -294,7 +294,8 @@ public static DateFormatSymbols lookupDateFormatSymbols(final String languageCod
if (lang != null) {
if (lang instanceof Locale) {
return new DateFormatSymbols((Locale) lang);
} else if (lang instanceof String){
}
if (lang instanceof String){
return getDateFormatSymbols((String) lang);
}
}
@@ -220,11 +220,10 @@ private BufferedReader tunnelHandshake(final String host, final int port, final

String code = null;
final String resp = response.get(0);
if (resp.startsWith("HTTP/") && resp.length() >= 12) {
code = resp.substring(9, 12);
} else {
if (!resp.startsWith("HTTP/") || (resp.length() < 12)) {
throw new IOException("Invalid response from proxy: " + resp);
}
code = resp.substring(9, 12);

if (!"200".equals(code)) {
final StringBuilder msg = new StringBuilder();
@@ -741,18 +741,17 @@ public int sendCommand(final String command, final String args) throws IOExcepti
final int repCode = super.sendCommand(command, args);
/* If CCC is issued, restore socket i/o streams to unsecured versions */
if (CMD_CCC.equals(command)) {
if (FTPReply.COMMAND_OK == repCode) {
_socket_.close();
_socket_ = plainSocket;
_controlInput_ = new BufferedReader(
new InputStreamReader(
_socket_ .getInputStream(), getControlEncoding()));
_controlOutput_ = new BufferedWriter(
new OutputStreamWriter(
_socket_.getOutputStream(), getControlEncoding()));
} else {
if (FTPReply.COMMAND_OK != repCode) {
throw new SSLException(getReplyString());
}
_socket_.close();
_socket_ = plainSocket;
_controlInput_ = new BufferedReader(
new InputStreamReader(
_socket_ .getInputStream(), getControlEncoding()));
_controlOutput_ = new BufferedWriter(
new OutputStreamWriter(
_socket_.getOutputStream(), getControlEncoding()));
}
return repCode;
}
@@ -335,14 +335,13 @@ public Calendar parseTimestamp(final String timestampStr, final Calendar serverT
// a valid year (e.g. 22:04 will parse as 22 A.D.)
// so could mistakenly confuse an hour with a year,
// if we don't insist on full length parsing.
if (parsed != null && pp.getIndex() == timestampStr.length()) {
working.setTime(parsed);
} else {
if ((parsed == null) || (pp.getIndex() != timestampStr.length())) {
throw new ParseException(
"Timestamp '"+timestampStr+"' could not be parsed using a server time of "
+serverTime.getTime().toString(),
pp.getErrorIndex());
}
working.setTime(parsed);
setPrecision(defaultDateSmallestUnitIndex, working);
return working;
}
@@ -325,13 +325,17 @@ else if ("PO".equals(dsorg) || "PO-E".equals(dsorg)) {
public FTPFile parseFTPEntry(final String entry) {
if (isType == FILE_LIST_TYPE) {
return parseFileList(entry);
} else if (isType == MEMBER_LIST_TYPE) {
}
if (isType == MEMBER_LIST_TYPE) {
return parseMemberList(entry);
} else if (isType == UNIX_LIST_TYPE) {
}
if (isType == UNIX_LIST_TYPE) {
return unixFTPEntryParser.parseFTPEntry(entry);
} else if (isType == JES_LEVEL_1_LIST_TYPE) {
}
if (isType == JES_LEVEL_1_LIST_TYPE) {
return parseJeslevel1List(entry);
} else if (isType == JES_LEVEL_2_LIST_TYPE) {
}
if (isType == JES_LEVEL_2_LIST_TYPE) {
return parseJeslevel2List(entry);
}

@@ -363,15 +363,11 @@ else if (typeStr.equalsIgnoreCase("*FILE"))
// file.
// Save files are a special type of files which are used
// to save objects, e.g. for backups.
if (name != null && name.toUpperCase(Locale.ROOT).endsWith(".SAVF"))
{
mustScanForPathSeparator = false;
type = FTPFile.FILE_TYPE;
}
else
{
if ((name == null) || !name.toUpperCase(Locale.ROOT).endsWith(".SAVF")) {
return null;
}
mustScanForPathSeparator = false;
type = FTPFile.FILE_TYPE;
}
else if (typeStr.equalsIgnoreCase("*MEM"))
{
@@ -196,20 +196,16 @@ private int readInt() throws IOException
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 != '\n') {
if (ch != -1) {
unread(ch);
}
return '\r';
}
unread(_lineSeparatorBytes);
ch = super.read();
// This is a kluge for read(byte[], ...) to read the right amount
--length;
}

return ch;
@@ -790,11 +790,10 @@ private NewsgroupInfo[] readNewsgroupListing() throws IOException
try (final BufferedReader reader = new DotTerminatedMessageReader(_reader_)) {
while ((line = reader.readLine()) != null) {
final NewsgroupInfo tmp = parseNewsgroupListEntry(line);
if (tmp != null) {
list.addElement(tmp);
} else {
if (tmp == null) {
throw new MalformedServerReplyException(line);
}
list.addElement(tmp);
}
}
final int size;
@@ -39,11 +39,11 @@ class ThreadContainer {
boolean findChild(final ThreadContainer target) {
if (child == null) {
return false;
} else if (child == target) {
}
if (child == target) {
return true;
} else {
return child.findChild(target);
}
return child.findChild(target);
}

// Copy the ThreadContainer tree structure down into the underlying Threadable objects

0 comments on commit 5d5d0c0

Please sign in to comment.