Skip to content

Commit ce9c875

Browse files
committed
always use cleanupFileName(name) to download remote files
1 parent be4701e commit ce9c875

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

src/main/java/fr/jmmc/oitools/util/FileUtils.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package fr.jmmc.oitools.util;
2121

2222
import fr.jmmc.jmcs.network.NetworkSettings;
23+
import fr.jmmc.jmcs.util.StringUtils;
2324
import fr.nom.tam.fits.FitsUtil;
2425
import java.io.BufferedOutputStream;
2526
import java.io.BufferedReader;
@@ -87,7 +88,7 @@ public static String download(final String urlLocation) throws MalformedURLExcep
8788
final InputStream in = FitsUtil.getURLStream(url, 0);
8889

8990
/* 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);
9192

9293
final String absFilePath = outFile.getCanonicalPath();
9394

@@ -261,4 +262,24 @@ public static Writer closeFile(final Writer w) {
261262
}
262263
return null;
263264
}
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+
}
264285
}

0 commit comments

Comments
 (0)