Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 93cccba

Browse files
committed
Add javadoc for FileInput and FileOutput
1 parent 0858434 commit 93cccba

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

Diff for: src/main/java/org/codeoverflow/chatoverflow/api/io/input/FileInput.java

+19
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,32 @@
55
import java.awt.image.BufferedImage;
66
import java.util.Optional;
77

8+
/**
9+
* Input that allows you to perform file operations that would otherwise be prohibited by the sandbox security manager.<br>
10+
* It features easy ways to read different types of files
11+
*/
812
@IsRequirement(requires = "file system access")
913
public interface FileInput extends Input {
1014

15+
/**
16+
* Load a text file and return the content as string
17+
* @param pathInResources the relative path to the file in the data folder
18+
* @return the content of the file or an empty optional if the operation failed
19+
*/
1120
Optional<String> getFile(String pathInResources);
1221

22+
/**
23+
* Load an image from a file and return it as BufferedImage
24+
* @param pathInResources the relative path to the file in the data folder
25+
* @return the image or an empty optional if the operation failed
26+
*/
1327
Optional<BufferedImage> getImage(String pathInResources);
1428

29+
/**
30+
* Load any file into a byte array
31+
* @param pathInResources the relative path to the file in the data folder
32+
* @return a byte array that contains all data from the file or an empty optional if the operation failed
33+
*/
1534
Optional<byte[]> getBinaryFile(String pathInResources);
1635

1736
}

Diff for: src/main/java/org/codeoverflow/chatoverflow/api/io/output/FileOutput.java

+40
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,61 @@
22

33
import org.codeoverflow.chatoverflow.api.IsRequirement;
44

5+
import javax.imageio.ImageIO;
56
import java.awt.image.BufferedImage;
67

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+
*/
712
@IsRequirement(requires = "file system access")
813
public interface FileOutput extends Output {
914

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+
*/
1023
boolean saveImage(BufferedImage image, String format, String pathInResources);
1124

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+
*/
1231
boolean saveBinaryFile(byte[] bytes, String pathInResources);
1332

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+
*/
1439
boolean saveFile(String content, String pathInResources);
1540

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+
*/
1646
boolean createDirectory(String folderName);
1747

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+
*/
1853
boolean exists(String pathInResources);
1954

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+
*/
2060
boolean delete(String pathInResources);
2161

2262
}

0 commit comments

Comments
 (0)