<br><font size=2 face="sans-serif">Hi again</font>
<br>
<br><font size=2 face="sans-serif">I figured out, the problem seems to
occur only on AS400 shares. I did not face it on windows servers.</font>
<br>
<br><font size=2 face="sans-serif">Again, i try to explain the problem.
When i use the "smbFile.listFiles()" method on a file, which
is located inside a AS400 share, the amount of returned files is multiple
times the actual amount it should return.</font>
<br><font size=2 face="sans-serif">For example: 2 Files in the share returns
me 3 Files, where one File is twice in the collection. This would not be
such a big deal, its just getting nasty when you have folders with a lot
of Files inside. </font>
<br><font size=2 face="sans-serif">While i tested, i faced some folders
with arround 5000+ Files. This results in arround 250'000 returned SMBFile
Objects, with a total used amount of like 500+MB of memory and a runtime
out of memory.</font>
<br>
<br><font size=2 face="sans-serif">Heres the full code for my directory
reading method(s):</font>
<br>
<br><font size=2 face="sans-serif"> public
HashSet<String> getFilesList(String relativePath, boolean recursive,
boolean includeFolders) throws MalformedURLException, SmbException, ExsException
{</font>
<br><font size=2 face="sans-serif">
</font>
<br><font size=2 face="sans-serif">
HashSet<String> collection = new HashSet<String>();</font>
<br><font size=2 face="sans-serif">
HashSet<String> unreadable = new HashSet<String>();</font>
<br><font size=2 face="sans-serif">
</font>
<br><font size=2 face="sans-serif">
getFilesList(relativePath,recursive,includeFolders,false,collection,
unreadable); </font>
<br><font size=2 face="sans-serif">
</font>
<br><font size=2 face="sans-serif">
return collection;</font>
<br><font size=2 face="sans-serif">
</font>
<br><font size=2 face="sans-serif"> }</font>
<br><font size=2 face="sans-serif"> </font>
<br><font size=2 face="sans-serif"> private
void getFilesList(String path, boolean recursive, boolean includeFolders,
boolean isFullPath, HashSet<String> collection, HashSet<String>
unreadable) throws MalformedURLException, SmbException, ExsException {</font>
<br>
<br><font size=2 face="sans-serif">
if(path == null) {</font>
<br><font size=2 face="sans-serif">
path =
"";</font>
<br><font size=2 face="sans-serif">
} </font>
<br><font size=2 face="sans-serif">
</font>
<br><font size=2 face="sans-serif">
if(path.trim().length() > 0 &&
(!path.trim().endsWith("/") && !path.trim().endsWith("\\")))
{</font>
<br><font size=2 face="sans-serif">
path =
path + "/";</font>
<br><font size=2 face="sans-serif">
}</font>
<br><font size=2 face="sans-serif">
</font>
<br><font size=2 face="sans-serif">
String url = "";</font>
<br><font size=2 face="sans-serif">
</font>
<br><font size=2 face="sans-serif">
if(isFullPath) {</font>
<br><font size=2 face="sans-serif">
url =
path;</font>
<br><font size=2 face="sans-serif">
} else {</font>
<br><font size=2 face="sans-serif">
url =
generateURLString(path);
</font>
<br><font size=2 face="sans-serif">
}</font>
<br>
<br><font size=2 face="sans-serif">
SmbFile smbFolder = new SmbFile(url);</font>
<br>
<br><font size=2 face="sans-serif">
if(!smbFolder.exists() || !smbFolder.isDirectory())
{</font>
<br><font size=2 face="sans-serif">
throw
new ExsException("Error: Folder cannot be read from smb share: "
+ smbFolder.getPath());</font>
<br><font size=2 face="sans-serif">
}</font>
<br><font size=2 face="sans-serif">
</font>
<br><font size=2 face="sans-serif">
if(!smbFolder.canRead()) {</font>
<br><font size=2 face="sans-serif">
unreadable.add(smbFolder.getPath());</font>
<br><font size=2 face="sans-serif">
return;</font>
<br><font size=2 face="sans-serif">
}</font>
<br>
<br><font size=2 face="sans-serif">
// this helps preventing heap overflows but
it wont prevent it when to many files at once are opend</font>
<br><font size=2 face="sans-serif">
HashSet<SmbFile> uniqueList = new HashSet<SmbFile>();</font>
<br><font size=2 face="sans-serif">
for(SmbFile currentSmbFile : smbFolder.listFiles())
{</font>
<br><font size=2 face="sans-serif">
uniqueList.add(currentSmbFile);</font>
<br><font size=2 face="sans-serif">
}</font>
<br><font size=2 face="sans-serif">
</font>
<br><font size=2 face="sans-serif">
for(SmbFile currentSmbFile : uniqueList) {</font>
<br><font size=2 face="sans-serif">
</font>
<br><font size=2 face="sans-serif">
String
currentPath = currentSmbFile.getPath();</font>
<br><font size=2 face="sans-serif">
</font>
<br><font size=2 face="sans-serif">
if(currentSmbFile.isFile())
{</font>
<br><font size=2 face="sans-serif">
currentSmbFile = null;</font>
<br><font size=2 face="sans-serif">
collection.add(currentPath);</font>
<br><font size=2 face="sans-serif">
</font>
<br><font size=2 face="sans-serif">
} else
if(currentSmbFile.isDirectory()) {</font>
<br><font size=2 face="sans-serif">
int size = 0;</font>
<br><font size=2 face="sans-serif">
try {</font>
<br><font size=2 face="sans-serif">
String[]
list = currentSmbFile.list();</font>
<br><font size=2 face="sans-serif">
size =
list.length;</font>
<br><font size=2 face="sans-serif">
list =
null;</font>
<br><font size=2 face="sans-serif">
} catch(Throwable t) {</font>
<br><font size=2 face="sans-serif">
continue;</font>
<br><font size=2 face="sans-serif">
}</font>
<br><font size=2 face="sans-serif">
</font>
<br><font size=2 face="sans-serif">
currentSmbFile = null;</font>
<br><font size=2 face="sans-serif">
if(includeFolders) {</font>
<br><font size=2 face="sans-serif">
collection.add(currentPath);</font>
<br><font size=2 face="sans-serif">
}</font>
<br><font size=2 face="sans-serif">
if(recursive) {</font>
<br><font size=2 face="sans-serif">
if(size
> 0) {</font>
<br><font size=2 face="sans-serif">
getFilesList(currentPath, recursive, includeFolders,
true, collection, unreadable);</font>
<br><font size=2 face="sans-serif">
}</font>
<br><font size=2 face="sans-serif">
}
</font>
<br><font size=2 face="sans-serif">
}
</font>
<br><font size=2 face="sans-serif">
}</font>
<br><font size=2 face="sans-serif">
</font>
<br><font size=2 face="sans-serif">
uniqueList.clear();</font>
<br><font size=2 face="sans-serif">
uniqueList = null;</font>
<br><font size=2 face="sans-serif"> }</font>
<br>
<br>
<br>