[tcljava-dev] Bug in FileCmd.java
Brought to you by:
mdejong
From: Raffaele S. <ra...@ar...> - 2001-12-08 00:25:39
|
I just found a small bug in FileCmd.java (small, but very bad ): Don't know why, but the copy loop in copyRenameFile() is wrong and doesn't work at all. The "offset" parameters in reader.read and writer.write are referred to the offset in the buffer NOT in the file. So in this case the value should always be 0 (write at the beginning of the buffer) or you get an IndexOutOfBound exception. Here is the fix: Index: FileCmd.java =================================================================== RCS file: /cvsroot/tcljava/tcljava/src/jacl/tcl/lang/FileCmd.java,v retrieving revision 1.5 diff -b -r1.5 FileCmd.java 1122d1121 < int currentIndex = 0; 1125,1127c1124,1125 < writer.write(cbuf, currentIndex, numChars); < currentIndex += 256; < numChars = reader.read(cbuf, currentIndex, 256); --- > writer.write(cbuf, 0, numChars); > numChars = reader.read(cbuf, 0, 256); Also, since "file copy" can be used to copy big binary files, wouldn't something that works with bytes be better than chars (just to avoid the possibility that Java would do something strange with character encoding). The classes BufferedInputStream/BufferedOutputStream work like BufferedReader and BufferedWriter, but on a stream of bytes instead of chars. One more thing: maybe the buffer size can be increased to something like 4Kb, to limit the number of calls. Another problem I found in the "file copy" is that copying of directories is not implemented. I am working on it. I'll send in the changes once I am done. -- Raffaele ----------------------------------------------------- ra...@ar... (::) http://www.aromatic.org/~raff/ When I say artist I mean the man who is building things -- creating molding the earth -- whether it be the plains of the west -- or the iron ore of Penn. It's all a big game of construction -- some with a brush -- some with a shovel -- some choose a pen. Jackson Pollock |