|
2 | 2 |
|
3 | 3 | import org.codeoverflow.chatoverflow.api.IsRequirement;
|
4 | 4 |
|
| 5 | +import javax.imageio.ImageIO; |
5 | 6 | import java.awt.image.BufferedImage;
|
6 | 7 |
|
| 8 | +/** |
| 9 | + * Output that allows you to perform file operations that would otherwise be prohibited by the sandbox security manager.<br> |
| 10 | + * It features easy ways to save all kinds of files, creat or delete directories or check if a file exists. |
| 11 | + */ |
7 | 12 | @IsRequirement(requires = "file system access")
|
8 | 13 | public interface FileOutput extends Output {
|
9 | 14 |
|
| 15 | + /** |
| 16 | + * Save a BufferedImage to a file |
| 17 | + * @param image the image that should be saved |
| 18 | + * @param format a string containing the informal name of the format (e.g. PNG / JPG / GIF / BMP)<br> |
| 19 | + * use {@link ImageIO#getWriterFormatNames()} to list all valid ones |
| 20 | + * @param pathInResources the relative path to the file in the data folder |
| 21 | + * @return if the operation was successful |
| 22 | + */ |
10 | 23 | boolean saveImage(BufferedImage image, String format, String pathInResources);
|
11 | 24 |
|
| 25 | + /** |
| 26 | + * Save any byte array to a file. |
| 27 | + * @param bytes raw content that should be saved to the file |
| 28 | + * @param pathInResources the relative path to the file in the data folder |
| 29 | + * @return if the operation was successful |
| 30 | + */ |
12 | 31 | boolean saveBinaryFile(byte[] bytes, String pathInResources);
|
13 | 32 |
|
| 33 | + /** |
| 34 | + * Save a String to a text file |
| 35 | + * @param content the text that should be saved |
| 36 | + * @param pathInResources the relative path to the file in the data folder |
| 37 | + * @return if the operation was successful |
| 38 | + */ |
14 | 39 | boolean saveFile(String content, String pathInResources);
|
15 | 40 |
|
| 41 | + /** |
| 42 | + * Create a new folder inside the data folder |
| 43 | + * @param folderName the relative path to the folder in the data folder |
| 44 | + * @return if the operation was successful |
| 45 | + */ |
16 | 46 | boolean createDirectory(String folderName);
|
17 | 47 |
|
| 48 | + /** |
| 49 | + * Check if a file or folder does exist |
| 50 | + * @param pathInResources the relative path to the file in the data folder |
| 51 | + * @return if the file does exist |
| 52 | + */ |
18 | 53 | boolean exists(String pathInResources);
|
19 | 54 |
|
| 55 | + /** |
| 56 | + * Delete a file or a folder |
| 57 | + * @param pathInResources the relative path to the file in the data folder |
| 58 | + * @return if the operation was successful |
| 59 | + */ |
20 | 60 | boolean delete(String pathInResources);
|
21 | 61 |
|
22 | 62 | }
|
0 commit comments