-3

I read from an input stream and in my finally block try to close it by calling in.close(); However the execution of main gets blocked . What is the way out ?

On suggestion , the code I used is ,

if (!processed) {
                System.out.println("in processed");
                byte[] contents = new byte[(int) fileSplit.getLength()];
                Path file = fileSplit.getPath();
                FileSystem fs = file.getFileSystem(conf);
                FSDataInputStream in = null;
                try {
                    in = fs.open(file);
                    IOUtils.readFully(in, contents, 0, contents.length);

                    value.set(contents, 0, contents.length);
                } finally {
                    System.out.println("before close stream");
                    IOUtils.closeStream(in);
                }
                processed = true;
                return true;
            }
            System.out.println("out of processed");
            return false;
        }
Laurent Etiemble
  • 27,111
  • 5
  • 56
  • 81
RadAl
  • 404
  • 5
  • 23

1 Answers1

-1

java.io.InputStream.close is not blocking, at least API never says that. Compare InputStream.read

 Reads the next byte of data from the input stream. The value byte is
 returned as an <code>int</code> in the range <code>0</code> to
 <code>255</code>. If no byte is available because the end of the stream
 has been reached, the value <code>-1</code> is returned. This method
 blocks until input data is available, the end of the stream is detected,
 or an exception is thrown.

and InputStream.close

  Closes this file input stream and releases any system resources
  associated with the stream.

As for solving your problem I would suggest to use Java 7 Files.readAllBytes and forget about your puzzle.

Evgeniy Dorofeev
  • 133,369
  • 30
  • 199
  • 275