| 10 | 10 | import org.w3c.dom.Document; |
| 11 | 11 | |
| 12 | import java.io.File; |
| 12 | 13 | import java.io.FileNotFoundException; |
| 13 | 14 | import java.nio.file.Path; |
| ... |
| 169 | 170 | */ |
| 170 | 171 | private Path downloadImage( final String src ) throws Exception { |
| 171 | | final Path imageFile; |
| 172 | final Path imagePath; |
| 173 | final File imageFile; |
| 172 | 174 | final var cachesPath = getCachesPath(); |
| 173 | 175 | |
| ... |
| 181 | 183 | final var id = hash.toLowerCase(); |
| 182 | 184 | |
| 183 | | imageFile = cachesPath.resolve( APP_TITLE_ABBR + id + '.' + ext ); |
| 185 | imagePath = cachesPath.resolve( APP_TITLE_ABBR + id + '.' + ext ); |
| 186 | imageFile = toFile( imagePath ); |
| 184 | 187 | |
| 185 | 188 | // Preserve image files if auto-remove is turned off. |
| 186 | 189 | if( autoRemove() ) { |
| 187 | | toFile( imageFile ).deleteOnExit(); |
| 190 | imageFile.deleteOnExit(); |
| 188 | 191 | } |
| 189 | 192 | |
| 190 | 193 | try( final var image = response.getInputStream() ) { |
| 191 | | copy( image, imageFile, REPLACE_EXISTING ); |
| 194 | copy( image, imagePath, REPLACE_EXISTING ); |
| 192 | 195 | } |
| 193 | 196 | |
| 194 | 197 | if( mediaType.isSvg() ) { |
| 195 | | sanitize( imageFile ); |
| 198 | sanitize( imagePath ); |
| 196 | 199 | } |
| 197 | 200 | } |
| 198 | 201 | |
| 199 | | return imageFile; |
| 202 | final var key = imageFile.exists() |
| 203 | ? "Main.status.image.xhtml.image.saved" |
| 204 | : "Main.status.image.xhtml.image.failed"; |
| 205 | clue( key, imageFile ); |
| 206 | |
| 207 | return imagePath; |
| 200 | 208 | } |
| 201 | 209 | |