Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;

import java.io.*;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

@Component
Expand Down Expand Up @@ -39,18 +43,22 @@ public File create( final InputStream inputStream ) throws IOException {
}

@Override
public void delete( final File file ) {
this.files.stream().filter( target -> target.getAbsolutePath().equals( file.getAbsolutePath() ) )
.findFirst()
.ifPresent( target -> {
this.files.remove( target );
if( target.exists() ) target.delete();
});
public void delete( final File file ) throws IOException {
final Optional<File> result = this.files.stream()
.filter( target -> target.getAbsolutePath().equals( file.getAbsolutePath() ) )
.findFirst();
if( result.isPresent() ){
final File target = result.get();
this.files.remove( target );
if( target.exists() ) Files.delete( target.toPath() );
}
}

@PreDestroy
@Override
public void cleanUp() {
this.files.forEach( file -> { if( file.exists() ) file.delete(); });
public void cleanUp() throws IOException {
for( final File file : this.files ){
if( file.exists() ) Files.delete( file.toPath() );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public interface TemporalFileManager {

File create( InputStream inputStream ) throws IOException;
File create( String name, InputStream inputStream ) throws IOException;
void delete( File file );
void cleanUp();
void delete( File file ) throws IOException;
void cleanUp() throws IOException;
}