Java – Very slow read from DVD in Java and .Net


I noticed in two applications to generate hashes of files, one written in Java and the other in C#, that the performance is horrible when reading from a DVD. I'm using Windows XP SP3. I noticed from the noise, that the drive keeps spinning down after reading a bunch of blocks, causing pauses of a couple of seconds between reads.

The strange thing, is that this doesn't happen when I use explorer to copy the files to my hard drive or when using md5sum (a utility written in C). Also. When running in Linux using the same hardware, the Java application works fine.

private static final byte[] m_buf = new byte[1048576*3];
//Using a BufferedInputStream makes no difference
InputStream in = new FileInputStream(file);
while((last_read = != -1){
    update_hash(m_buf, 0, last_read);           

Any hints?


Best Solution

After reducing the size of the buffer to 1024 bytes the problem disappeared. Don't know the exact explanation, but probably because there are more frequent reads the DVD driver doesn't spin down the drive.

Thanks for the comments