|
| 1 | +/* |
| 2 | + * Copyright (c) 2025, FusionAuth, All Rights Reserved |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, |
| 11 | + * software distributed under the License is distributed on an |
| 12 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
| 13 | + * either express or implied. See the License for the specific |
| 14 | + * language governing permissions and limitations under the License. |
| 15 | + */ |
| 16 | +package io.fusionauth.http.io; |
| 17 | + |
| 18 | +import java.io.IOException; |
| 19 | +import java.nio.file.Files; |
| 20 | +import java.nio.file.Path; |
| 21 | +import java.util.ArrayList; |
| 22 | +import java.util.List; |
| 23 | + |
| 24 | +/** |
| 25 | + * Manage file creation for multipart streams. |
| 26 | + * |
| 27 | + * @author Daniel DeGroff |
| 28 | + */ |
| 29 | +public class DefaultMultipartFileManager implements MultipartFileManager { |
| 30 | + private final String optionalPrefix; |
| 31 | + |
| 32 | + private final String optionalSuffix; |
| 33 | + |
| 34 | + private final Path tempDir; |
| 35 | + |
| 36 | + private final List<Path> tempFiles = new ArrayList<>(0); |
| 37 | + |
| 38 | + public DefaultMultipartFileManager(Path tempDir, String optionalPrefix, String optionalSuffix) { |
| 39 | + this.tempDir = tempDir; |
| 40 | + this.optionalPrefix = optionalPrefix; |
| 41 | + this.optionalSuffix = optionalSuffix; |
| 42 | + } |
| 43 | + |
| 44 | + public Path createTemporaryFile() throws IOException { |
| 45 | + Path tempFile = Files.createTempFile(tempDir, optionalPrefix, optionalSuffix); |
| 46 | + tempFiles.add(tempFile); |
| 47 | + return tempFile; |
| 48 | + } |
| 49 | + |
| 50 | + public List<Path> getTemporaryFiles() { |
| 51 | + return List.copyOf(tempFiles); |
| 52 | + } |
| 53 | +} |
0 commit comments