How to check if a stream from an SmbFile is ready to be read?

311 views Asked by At

what would be the equivalent of this code:

    FileReader reader = null;
    try
    {
        reader = new FileReader( file);
        return reader.ready();
    }
    catch( IOException ex)
    {
        return false;
    }

For SmbFile ? I tried that:

    BufferedReader reader = null;
    try
    {
        SmbFileInputStream fstream = new SmbFileInputStream( file);
        reader = new BufferedReader( new InputStreamReader( fstream));
        return reader.ready();
    }
    catch( IOException ex)
    {
        return false;
    }

but then I always get "false" as result.

1

There are 1 answers

0
Jorge Chavez On BEST ANSWER

Based on the documentation looks that there's no guarantee that this flag assure it cannot be read, Note that returning false does not guarantee that the next read will block.

You can try this way to avoid null values,

String line;
while((line = br.readLine()) != null) {
  System.out.println(line);
}

You can look at this post too, bufferedreader-not-stating-ready-when-it-should

Hope this helps