Added new file detection in FilesLineIterator.
This commit is contained in:
parent
d453979eef
commit
1253e22ce1
1 changed files with 49 additions and 5 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2022 Christian Pierre MOMON <christian@momon.org>
|
* Copyright (C) 2022-2024 Christian Pierre MOMON <christian@momon.org>
|
||||||
*
|
*
|
||||||
* This file is part of StatoolInfos, simple service statistics tool.
|
* This file is part of StatoolInfos, simple service statistics tool.
|
||||||
*
|
*
|
||||||
|
@ -34,6 +34,7 @@ public class FilesLineIterator implements Iterator<String>
|
||||||
|
|
||||||
private Iterator<File> fileIterator;
|
private Iterator<File> fileIterator;
|
||||||
private LineIterator lineIterator;
|
private LineIterator lineIterator;
|
||||||
|
private boolean newFile;
|
||||||
private boolean print;
|
private boolean print;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,9 +45,7 @@ public class FilesLineIterator implements Iterator<String>
|
||||||
*/
|
*/
|
||||||
public FilesLineIterator(final File source)
|
public FilesLineIterator(final File source)
|
||||||
{
|
{
|
||||||
this.fileIterator = new Files(source).iterator();
|
this(new Files(source));
|
||||||
this.lineIterator = null;
|
|
||||||
setPrintOn();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -59,9 +58,21 @@ public class FilesLineIterator implements Iterator<String>
|
||||||
{
|
{
|
||||||
this.fileIterator = source.iterator();
|
this.fileIterator = source.iterator();
|
||||||
this.lineIterator = null;
|
this.lineIterator = null;
|
||||||
|
this.newFile = true;
|
||||||
setPrintOn();
|
setPrintOn();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close.
|
||||||
|
*/
|
||||||
|
public void close()
|
||||||
|
{
|
||||||
|
if (this.lineIterator != null)
|
||||||
|
{
|
||||||
|
this.lineIterator.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forward.
|
* Forward.
|
||||||
*/
|
*/
|
||||||
|
@ -82,6 +93,7 @@ public class FilesLineIterator implements Iterator<String>
|
||||||
System.out.println("Iterating file [" + file.getAbsolutePath() + "]");
|
System.out.println("Iterating file [" + file.getAbsolutePath() + "]");
|
||||||
}
|
}
|
||||||
this.lineIterator = new LineIterator(file);
|
this.lineIterator = new LineIterator(file);
|
||||||
|
this.newFile = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -103,6 +115,7 @@ public class FilesLineIterator implements Iterator<String>
|
||||||
System.out.println("Iterating file [" + file.getAbsolutePath() + "]");
|
System.out.println("Iterating file [" + file.getAbsolutePath() + "]");
|
||||||
}
|
}
|
||||||
this.lineIterator = new LineIterator(file);
|
this.lineIterator = new LineIterator(file);
|
||||||
|
this.newFile = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -123,6 +136,22 @@ public class FilesLineIterator implements Iterator<String>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the current file.
|
||||||
|
*
|
||||||
|
* @return the current file
|
||||||
|
*/
|
||||||
|
public File getCurrentFile()
|
||||||
|
{
|
||||||
|
File result;
|
||||||
|
|
||||||
|
forward();
|
||||||
|
result = this.lineIterator.getFile();
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see java.util.Iterator#hasNext()
|
* @see java.util.Iterator#hasNext()
|
||||||
*/
|
*/
|
||||||
|
@ -146,6 +175,21 @@ public class FilesLineIterator implements Iterator<String>
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if is new file.
|
||||||
|
*
|
||||||
|
* @return true, if is new file
|
||||||
|
*/
|
||||||
|
public boolean isNewFile()
|
||||||
|
{
|
||||||
|
boolean result;
|
||||||
|
|
||||||
|
result = this.newFile;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see java.util.Iterator#next()
|
* @see java.util.Iterator#next()
|
||||||
*/
|
*/
|
||||||
|
@ -156,7 +200,6 @@ public class FilesLineIterator implements Iterator<String>
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
forward();
|
forward();
|
||||||
|
|
||||||
if (this.lineIterator == null)
|
if (this.lineIterator == null)
|
||||||
|
@ -166,6 +209,7 @@ public class FilesLineIterator implements Iterator<String>
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result = this.lineIterator.next();
|
result = this.lineIterator.next();
|
||||||
|
this.newFile = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IOException exception)
|
catch (IOException exception)
|
||||||
|
|
Loading…
Reference in a new issue