Fields Summary |
---|
private List | rawlinesa vector of strings, each representing a possibly valid ftp file
entry |
private FTPFileEntryParser | parserthe parser to which this iterator delegates its parsing duties |
private static final int | UNINITconstant shorthand for the situation where the raw listing has not
yet been scanned |
private static final int | DIREMPTYconstant shorthand for the situation where the raw listing has been
scanned and found to have no valid entry. |
private int | itemptrthis iterator's current position within rawlines . |
private int | firstGoodEntrynumber within rawlines of the first valid file entry. |
private static final FTPFile[] | EMPTYshorthand for an empty return value. |
Methods Summary |
---|
public FTPFile[] | getFiles()Returns a list of FTPFile objects for ALL files listed in the server's
LIST output.
if (this.itemptr != DIREMPTY)
{
init();
}
return getNext(0);
|
private int | getFirstGoodEntry()Skips over any introductory lines and stuff in the listing that does
not represent files, returning the line number of the first entry
that does represent a file.
FTPFile entry = null;
for (int iter = 0; iter < this.rawlines.size(); iter++)
{
String line = (String) this.rawlines.get(iter);
entry = parseFTPEntry(line);
if (null != entry)
{
return iter;
}
}
return DIREMPTY;
|
public FTPFile[] | getNext(int quantityRequested)Returns an array of at most quantityRequested FTPFile
objects starting at this iterator's current position within its
associated list. If fewer than quantityRequested such
elements are available, the returned array will have a length equal
to the number of entries at and after after the current position.
If no such entries are found, this array will have a length of 0.
After this method is called the current position is advanced by
either quantityRequested or the number of entries
available after the iterator, whichever is fewer.
// if we haven't gotten past the initial junk do so.
if (this.firstGoodEntry == UNINIT)
{
this.firstGoodEntry = getFirstGoodEntry();
}
if (this.firstGoodEntry == DIREMPTY)
{
return EMPTY;
}
int max = this.rawlines.size() - this.firstGoodEntry;
// now that we know the maximum we can possibly get,
// resolve a 0 request to ask for that many.
int howMany = (quantityRequested == 0) ? max : quantityRequested;
howMany = (howMany + this.itemptr < this.rawlines.size())
? howMany
: this.rawlines.size() - this.itemptr;
FTPFile[] output = new FTPFile[howMany];
for (int i = 0, e = this.firstGoodEntry + this.itemptr ;
i < howMany; i++, e++)
{
output[i] = parseFTPEntry((String) this.rawlines.get(e));
this.itemptr++;
}
return output;
|
public FTPFile[] | getPrevious(int quantityRequested)Returns an array of at most quantityRequested FTPFile
objects starting at the position preceding this iterator's current
position within its associated list. If fewer than
quantityRequested such elements are available, the
returned array will have a length equal to the number of entries after
the iterator. If no such entries are found, this array will have a
length of 0. The entries will be ordered in the same order as the
list, not reversed.
After this method is called the current position is moved back by
either quantityRequested or the number of entries
available before the current position, whichever is fewer.
int howMany = quantityRequested;
// can't retreat further than we've previously advanced
if (howMany > this.itemptr)
{
howMany = this.itemptr;
}
FTPFile[] output = new FTPFile[howMany];
for (int i = howMany, e = this.firstGoodEntry + this.itemptr; i > 0;)
{
output[--i] = parseFTPEntry((String) this.rawlines.get(--e));
this.itemptr--;
}
return output;
|
public boolean | hasNext()Method for determining whether getNext() will successfully return a
non-null value.
int fge = this.firstGoodEntry;
if (fge == DIREMPTY)
{
//directory previously found empty - return false
return false;
}
else if (fge < 0)
{
// we haven't scanned the list yet so do it first
fge = getFirstGoodEntry();
}
return fge + this.itemptr < this.rawlines.size();
|
public boolean | hasPrevious()Method for determining whether getPrevious() will successfully return a
non-null value.
int fge = this.firstGoodEntry;
if (fge == DIREMPTY)
{
//directory previously found empty - return false
return false;
}
else if (fge < 0)
{
// we haven't scanned the list yet so do it first
fge = getFirstGoodEntry();
}
return this.itemptr > fge;
|
private void | init()resets iterator to the beginning of the list.
this.itemptr = 0;
this.firstGoodEntry = UNINIT;
|
public FTPFile | next()Returns a single parsed FTPFile object corresponding to the raw input
line at this iterator's current position.
After this method is called the internal iterator is advanced by one
element (unless already at end of list).
FTPFile[] file = getNext(1);
if (file.length > 0)
{
return file[0];
}
else
{
return null;
}
|
private FTPFile | parseFTPEntry(java.lang.String entry)Delegates to this object's parser member the job of parsing an
entry.
return this.parser.parseFTPEntry(entry);
|
public FTPFile | previous()Returns a single parsed FTPFile object corresponding to the raw input
line at the position preceding that of the internal iterator over
the list of raw lines maintained by this object
After this method is called the internal iterator is retreated by one
element (unless it is already at beginning of list).
FTPFile[] file = getPrevious(1);
if (file.length > 0)
{
return file[0];
}
else
{
return null;
}
|