@@ -93,6 +93,19 @@ public void testContentEquals(final int bufferSize) throws IOException {
9393 try (FileChannel fc1 = FileChannel .open (bigFile1 ); FileChannel fc3 = FileChannel .open (bigFile3 )) {
9494 assertFalse (FileChannels .contentEquals (fc1 , fc3 , bufferSize ));
9595 assertFalse (FileChannels .contentEquals (reset (fc3 ), reset (fc1 ), bufferSize ));
96+ // Test just the last byte
97+ fc1 .position (last );
98+ fc3 .position (last );
99+ assertFalse (FileChannels .contentEquals (fc1 , fc3 , bufferSize ));
100+ }
101+ // Make the LAST byte equal.
102+ bytes3 = bytes1 .clone ();
103+ Files .write (bigFile3 , bytes3 );
104+ try (FileChannel fc1 = FileChannel .open (bigFile1 ); FileChannel fc3 = FileChannel .open (bigFile3 )) {
105+ // Test just the last byte
106+ fc1 .position (last );
107+ fc3 .position (last );
108+ assertTrue (FileChannels .contentEquals (fc1 , fc3 , bufferSize ));
96109 }
97110 // Make a byte in the middle different
98111 bytes3 = bytes1 .clone ();
@@ -121,16 +134,16 @@ private void testContentEquals(final String content1, final String content2, fin
121134 FileUtils .writeStringToFile (file2 , content2 , US_ASCII );
122135 // File checksums are different
123136 assertNotEquals (FileUtils .checksumCRC32 (file1 ), FileUtils .checksumCRC32 (file2 ));
124- try (FileInputStream stream1 = new FileInputStream (file1 );
125- FileInputStream stream2 = new FileInputStream (file2 );
126- FileChannel channel1 = stream1 .getChannel ();
127- FileChannel channel2 = stream2 .getChannel ()) {
137+ try (FileInputStream in1 = new FileInputStream (file1 );
138+ FileInputStream in2 = new FileInputStream (file2 );
139+ FileChannel channel1 = in1 .getChannel ();
140+ FileChannel channel2 = in2 .getChannel ()) {
128141 assertFalse (FileChannels .contentEquals (channel1 , channel2 , bufferSize ));
129142 }
130- try (FileInputStream stream1 = new FileInputStream (file1 );
131- FileInputStream stream2 = new FileInputStream (file2 );
132- FileChannel channel1 = stream1 .getChannel ();
133- FileChannel channel2 = stream2 .getChannel ()) {
143+ try (FileInputStream in1 = new FileInputStream (file1 );
144+ FileInputStream in2 = new FileInputStream (file2 );
145+ FileChannel channel1 = in1 .getChannel ();
146+ FileChannel channel2 = in2 .getChannel ()) {
134147 assertTrue (FileChannels .contentEquals (channel1 , channel1 , bufferSize ));
135148 assertTrue (FileChannels .contentEquals (channel2 , channel2 , bufferSize ));
136149 }
@@ -161,10 +174,10 @@ public void testContentEqualsEmpty(final int bufferSize) throws IOException {
161174 assertFalse (isEmpty (notEmpty ));
162175 // File checksums are different
163176 assertNotEquals (FileUtils .checksumCRC32 (empty ), FileUtils .checksumCRC32 (notEmpty ));
164- try (FileInputStream streamEmpty = new FileInputStream (empty );
165- FileInputStream streamNotEmpty = new FileInputStream (notEmpty );
166- FileChannel channelEmpty = streamEmpty .getChannel ();
167- FileChannel channelNotEmpty = streamNotEmpty .getChannel ()) {
177+ try (FileInputStream inEmpty = new FileInputStream (empty );
178+ FileInputStream inNotEmpty = new FileInputStream (notEmpty );
179+ FileChannel channelEmpty = inEmpty .getChannel ();
180+ FileChannel channelNotEmpty = inNotEmpty .getChannel ()) {
168181 assertFalse (FileChannels .contentEquals (channelEmpty , channelNotEmpty , bufferSize ));
169182 assertFalse (FileChannels .contentEquals (null , channelNotEmpty , bufferSize ));
170183 assertFalse (FileChannels .contentEquals (channelNotEmpty , null , bufferSize ));
0 commit comments