| | |
| | | package de.uhilger.httpserver.cm; |
| | | |
| | | import java.io.File; |
| | | import java.util.logging.Logger; |
| | | |
| | | /** |
| | | * FileTransporter |
| | |
| | | * @version 1, 04.07.2021 |
| | | */ |
| | | public class FileTransporter { |
| | | |
| | | private static final Logger logger = Logger.getLogger(FileTransporter.class.getName()); |
| | | |
| | | /** |
| | | * Einen Namen fuer eine Datei erzeugen, der noch nicht existiert. |
| | |
| | | public File getNewFileName(File file) { |
| | | File dir = file.getParentFile(); |
| | | String targetName = file.getName(); |
| | | logger.fine("targetName: " + targetName); |
| | | //logger.fine("targetName: " + targetName); |
| | | String ext = ""; |
| | | int dotpos = targetName.indexOf("."); |
| | | if (dotpos > -1) { |
| | | ext = targetName.substring(dotpos); |
| | | targetName = targetName.substring(0, dotpos); |
| | | } |
| | | logger.fine("targetName: " + targetName + ", ext: " + ext); |
| | | //logger.fine("targetName: " + targetName + ", ext: " + ext); |
| | | int i = 1; |
| | | while (file.exists()) { |
| | | StringBuffer buf = new StringBuffer(); |
| | |
| | | file = new File(dir, buf.toString()); |
| | | i++; |
| | | } |
| | | logger.fine("new file: " + file.getName()); |
| | | //logger.fine("new file: " + file.getName()); |
| | | return file; |
| | | } |
| | | |