How to read from pipe using a MappedByteBuffer
<p>I want to read a file, which name is passed by command line arguments. I'm concerned about reading speed, so I'm trying to use <code>MappedByteBuffer</code>.</p>

<pre><code>FileInputStream fileStream = new FileInputStream(filename);
System.out.println("fileStream.available(): " + fileStream.available());

FileChannel channel = fileStream.getChannel();
System.out.println("channel.size(): " + channel.size());

MappedByteBuffer buffer =
    channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
System.out.println("buffer.limit(): " + buffer.limit());

for (int i = 0; i &lt; buffer.limit(); i++) {
    // process buffer.get() ...
}
</code></pre>

<p>It works well with regular files, but it doesn't read data from pipes (e.g. from <code>/dev/fd/63</code>). When I run <code>java Program &lt;(perl -0777pe '$_=$_ x 1000' jfdctint.c)</code> I get the following output:</p>

<pre><code>fileStream.available(): 65536
channel.size(): 0
buffer.limit(): 0
</code></pre>

<p>So there is nothing to read from buffer. I'm struggling to find out if <code>MappedByteBuffer</code> is compatible with pipe. How to read the data and does is make sense to map <code>FileChannel</code> onto <code>MappedByteBuffer</code> for a pipe at all?</p>