From 581ddc54bb9b3ed089e9c53741c6274803525026 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 27 Jul 2012 07:48:37 +0200 Subject: [PATCH] Add data directory helper. --- .../demoscenemusic/core/DataDirectory.java | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/main/java/net/pterodactylus/demoscenemusic/core/DataDirectory.java diff --git a/src/main/java/net/pterodactylus/demoscenemusic/core/DataDirectory.java b/src/main/java/net/pterodactylus/demoscenemusic/core/DataDirectory.java new file mode 100644 index 0000000..63c2933 --- /dev/null +++ b/src/main/java/net/pterodactylus/demoscenemusic/core/DataDirectory.java @@ -0,0 +1,67 @@ +/* + * DemosceneMusic - DataDirectory.java - Copyright © 2012 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.demoscenemusic.core; + +import java.io.File; + +/** + * Helper for managing the data directory. + * + * @author David ‘Bombe’ Roden + */ +public class DataDirectory { + + /** The path of the data directory. */ + private final String dataDirectory; + + /** + * Creates a new data directory helper. + * + * @param dataDirectory + * The path of the data directory + */ + public DataDirectory(String dataDirectory) { + this.dataDirectory = dataDirectory; + } + + /** + * Returns the absolute path of the file with the given ID. + * + * @param id + * The ID of the file + * @return The absolute path of the file + */ + public String getPath(String id) { + return new File(dataDirectory, id.toLowerCase().replace('-', '/')).getAbsolutePath(); + } + + /** + * Returns the file for the given ID. The returned {@link File} is ready to + * be read from or written to, all necessary directories have been created. + * + * @param id + * The ID of the file + * @return The file + */ + public File getFile(String id) { + File file = new File(dataDirectory, id.toLowerCase().replace('-', '/')); + file.mkdirs(); + return file; + } + +} -- 2.7.4