views:

140

answers:

2

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 = in.read(m_buf)) != -1){
    update_hash(m_buf, 0, last_read);     
}
in.close();

Any hints?

Thanks.

A: 

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

jassuncao
A: 

I'm guessing that Java code treats the DVD as a regular file on the filesystem, while Windows probably optimizes read/write.

Since the Java IO calls go to the native/OS calls, I'm guessing that the linux OS is smarter when making the IO calls to read the DVD.

Miguel Ping