001/**
002 * Copyright (c) 2025-2026, Michael Yang 杨福海 (fuhai999@gmail.com).
003 * <p>
004 * Licensed under the GNU Lesser General Public License (LGPL) ,Version 3.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 * <p>
008 * http://www.gnu.org/licenses/lgpl-3.0.txt
009 * <p>
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package dev.tinyflow.core.filestoreage;
017
018import java.util.ArrayList;
019import java.util.List;
020
021public class FileStorageManager {
022
023    public List<FileStorageProvider> providers = new ArrayList<>();
024
025    private static class ManagerHolder {
026        private static final FileStorageManager INSTANCE = new FileStorageManager();
027    }
028
029    private FileStorageManager() {
030    }
031
032    public static FileStorageManager getInstance() {
033        return ManagerHolder.INSTANCE;
034    }
035
036    public void registerProvider(FileStorageProvider provider) {
037        providers.add(provider);
038    }
039
040    public void removeProvider(FileStorageProvider provider) {
041        providers.remove(provider);
042    }
043
044    public FileStorage getFileStorage() {
045        for (FileStorageProvider provider : providers) {
046            FileStorage fileStorage = provider.getFileStorage();
047            if (fileStorage != null) {
048                return fileStorage;
049            }
050        }
051        return null;
052    }
053}