Name: rmT116609 Date: 10/15/2003
FULL PRODUCT VERSION :
java version "1.4.2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)
FULL OS VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
File copy to Windows share and SAMBA share using NIO FileChannels fails with large file sizes (+100MB).
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Map a shared directory on a remote machine. The directory should be either a SAMBA share or an NT share.
2. Run the attached NIOCopy.java class providing a large file (+100MB) as the first parameter.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The file should be copied.
ACTUAL -
An exception is thrown.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.io.IOException: Insufficient system resources exist to complete the request
ed service
at sun.nio.ch.FileDispatcher.write0(Native Method)
at sun.nio.ch.FileDispatcher.write(FileDispatcher.java:44)
at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:104)
at sun.nio.ch.IOUtil.write(IOUtil.java:60)
at sun.nio.ch.FileChannelImpl.write(FileChannelImpl.java:202)
at sun.nio.ch.FileChannelImpl.transferToTrustedChannel(FileChannelImpl.j
ava:420)
at sun.nio.ch.FileChannelImpl.transferTo(FileChannelImpl.java:491)
at NIOCopy.<init>(NIOCopy.java:40)
at NIOCopy.main(NIOCopy.java:60)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.IOException;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.File;
import java.nio.channels.FileChannel;
public class NIOCopy {
public NIOCopy(File sourceFile, File destinationFile) {
try {
if(!destinationFile.exists()) {
destinationFile.createNewFile();
}
FileChannel in = new FileInputStream(sourceFile).getChannel();
FileChannel out = new FileOutputStream(destinationFile, true).getChannel();
//transferTo copy
in.transferTo(0, in.size(), out);
in.close();
out.close();
}
catch(IOException io) {
io.printStackTrace();
}
}
/**
* The main method.
*
* @param args An array of command line arguments.
*/
public static void main(String args[]) {
File in = new File(args[0]);
File out = new File(args[1]);
NIOCopy demo = new NIOCopy(in, out);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Copy one file to another, one buffer at a time using the ByteBuffer class.
(Incident Review ID: 190939)
======================================================================