[jcifs] SmbException while trying to read from SmbFileInputStream

Almog atieb at bmc.com
Sun Jun 3 05:22:05 MDT 2012


Hi,

I am trying to read a file which exists on a remote machine using JCIFS 1.3.17 
using the following code:


   {
      long               fileSize                  = 0;
      long               tmpFileSize               = logFile.getLastFileSize();
      SmbFile            tmpsmbFile                = logFile.getSmbFile();
      SmbFileInputStream tmpsmbInputStream         = new 
SmbFileInputStream(tmpsmbFile);
      long               smbFileLength             = tmpsmbFile.length();
      long               l_Count                   = 0L;
      int                ch                        = 0;
      long               skipCount                 = 0L;
      Reader tmpreader = null;
      BufferedReader tmpbufferedReader = null;


		  if (tmpFileSize != 0 && tmpFileSize < smbFileLength)
		  {
		     fileSize = logFile.getLastFileSizeInChar();
		     skipCount = tmpsmbInputStream.skip(tmpFileSize);
		  }
		  else
		  {
		     fileSize = 0;
		  }
		  tmpreader = new InputStreamReader(tmpsmbInputStream, 
charset_);
		  tmpbufferedReader = new BufferedReader(tmpreader);
		  
		  while ((ch = tmpbufferedReader.read()) > -1)
		  {
		     l_Count++;
		  }


		  fileSize += l_Count;
		  logFile.setLastFileSizeInChar(fileSize);
		  tmpbufferedReader.close();
		  tmpreader.close();
		  tmpsmbInputStream.close();
		  logFile.setLastFileSize(smbFileLength);

      return fileSize;

   }
   

occasionally, one of the commands fails, and throws an SmbException with the 
error: "The handle is invalid".
sometimes the exception is thrown from the read() method, and sometimes from the 
skip() method.

is there something i'm doing wrong?

Thanks,
Almog.



More information about the jCIFS mailing list