|
20 | 20 | package fr.jmmc.oitools.util; |
21 | 21 |
|
22 | 22 | import fr.jmmc.jmcs.network.NetworkSettings; |
| 23 | +import fr.jmmc.jmcs.util.StringUtils; |
23 | 24 | import fr.nom.tam.fits.FitsUtil; |
24 | 25 | import java.io.BufferedOutputStream; |
25 | 26 | import java.io.BufferedReader; |
@@ -87,7 +88,7 @@ public static String download(final String urlLocation) throws MalformedURLExcep |
87 | 88 | final InputStream in = FitsUtil.getURLStream(url, 0); |
88 | 89 |
|
89 | 90 | /* Generating temporary file relative to input parameter */ |
90 | | - final File outFile = File.createTempFile(new File(url.getFile()).getName(), null); |
| 91 | + final File outFile = File.createTempFile(cleanupFileName(new File(url.getFile()).getName()), null); |
91 | 92 |
|
92 | 93 | final String absFilePath = outFile.getCanonicalPath(); |
93 | 94 |
|
@@ -261,4 +262,24 @@ public static Writer closeFile(final Writer w) { |
261 | 262 | } |
262 | 263 | return null; |
263 | 264 | } |
| 265 | + |
| 266 | + /** |
| 267 | + * Remove accents from characters and replace wild chars with '_'. |
| 268 | + * @param fileName the string to clean up |
| 269 | + * @return cleaned up file name |
| 270 | + */ |
| 271 | + public static String cleanupFileName(final String fileName) { |
| 272 | + // Remove accent from characters (if any) (Java 1.6) |
| 273 | + final String removed = StringUtils.removeAccents(fileName); |
| 274 | + |
| 275 | + // Replace wild characters with '_' |
| 276 | + final String cleaned = StringUtils.replaceNonFileNameCharsByUnderscore(removed); |
| 277 | + |
| 278 | + if (logger.isLoggable(Level.FINE) && !cleaned.equals(fileName)) { |
| 279 | + logger.log(Level.FINE, "Had to clean up file name (was '{0}', became '{1}').", |
| 280 | + new Object[]{fileName, cleaned}); |
| 281 | + } |
| 282 | + |
| 283 | + return cleaned; |
| 284 | + } |
264 | 285 | } |
0 commit comments