File tree Expand file tree Collapse file tree 3 files changed +10
-18
lines changed
main/java/org/codehaus/plexus/util/io
test/java/org/codehaus/plexus/util/io Expand file tree Collapse file tree 3 files changed +10
-18
lines changed Original file line number Diff line number Diff line change @@ -153,19 +153,17 @@ private void flushBuffer( ByteBuffer writeBuffer ) throws IOException
153153 @ Override
154154 public void close () throws IOException
155155 {
156- flush ();
157- long position = channel .position ();
158- if ( position != channel .size () )
156+ if ( channel .isOpen () )
159157 {
160- if ( !modified )
158+ flush ();
159+ long position = channel .position ();
160+ if ( position != channel .size () )
161161 {
162- FileTime now = FileTime .from ( Instant .now () );
163- Files .setLastModifiedTime ( path , now );
164162 modified = true ;
163+ channel .truncate ( position );
165164 }
166- channel .truncate ( position );
165+ channel .close ( );
167166 }
168- channel .close ();
169167 }
170168
171169 public boolean isModified ()
Original file line number Diff line number Diff line change 1717 */
1818
1919import java .io .IOException ;
20- import java .io .OutputStream ;
2120import java .nio .charset .StandardCharsets ;
2221import java .nio .file .Files ;
2322import java .nio .file .Path ;
@@ -39,7 +38,6 @@ public class CachingOutputStreamTest
3938
4039 Path tempDir ;
4140 Path checkLastModified ;
42- FileTime lm ;
4341
4442 @ Before
4543 public void setup () throws IOException
@@ -48,19 +46,18 @@ public void setup() throws IOException
4846 Files .createDirectories ( dir );
4947 tempDir = Files .createTempDirectory ( dir , "temp-" );
5048 checkLastModified = tempDir .resolve ( ".check" );
51- Files .newOutputStream ( checkLastModified ).close ();
52- lm = Files .getLastModifiedTime ( checkLastModified );
5349 }
5450
5551 private void waitLastModified () throws IOException , InterruptedException
5652 {
53+ Files .newOutputStream ( checkLastModified ).close ();
54+ FileTime lm = Files .getLastModifiedTime ( checkLastModified );
5755 while ( true )
5856 {
5957 Files .newOutputStream ( checkLastModified ).close ();
6058 FileTime nlm = Files .getLastModifiedTime ( checkLastModified );
6159 if ( !Objects .equals ( nlm , lm ) )
6260 {
63- lm = nlm ;
6461 break ;
6562 }
6663 Thread .sleep ( 10 );
Original file line number Diff line number Diff line change 2727import org .junit .Before ;
2828import org .junit .Test ;
2929
30- import static org .junit .Assert .assertArrayEquals ;
3130import static org .junit .Assert .assertEquals ;
3231import static org .junit .Assert .assertFalse ;
3332import static org .junit .Assert .assertNotEquals ;
@@ -38,7 +37,6 @@ public class CachingWriterTest
3837
3938 Path tempDir ;
4039 Path checkLastModified ;
41- FileTime lm ;
4240
4341 @ Before
4442 public void setup () throws IOException
@@ -47,19 +45,18 @@ public void setup() throws IOException
4745 Files .createDirectories ( dir );
4846 tempDir = Files .createTempDirectory ( dir , "temp-" );
4947 checkLastModified = tempDir .resolve ( ".check" );
50- Files .newOutputStream ( checkLastModified ).close ();
51- lm = Files .getLastModifiedTime ( checkLastModified );
5248 }
5349
5450 private void waitLastModified () throws IOException , InterruptedException
5551 {
52+ Files .newOutputStream ( checkLastModified ).close ();
53+ FileTime lm = Files .getLastModifiedTime ( checkLastModified );
5654 while ( true )
5755 {
5856 Files .newOutputStream ( checkLastModified ).close ();
5957 FileTime nlm = Files .getLastModifiedTime ( checkLastModified );
6058 if ( !Objects .equals ( nlm , lm ) )
6159 {
62- lm = nlm ;
6360 break ;
6461 }
6562 Thread .sleep ( 10 );
You can’t perform that action at this time.
0 commit comments