-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTinExample.java
More file actions
65 lines (43 loc) · 1.57 KB
/
TinExample.java
File metadata and controls
65 lines (43 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package apis;
import com.github.artbits.quickio.api.JTin;
import com.github.artbits.quickio.core.Config;
import com.github.artbits.quickio.core.QuickIO;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.List;
final class TinExample {
//A static Tin object. When the program ends running, the JVM automatically closes the object.
private final static JTin tin = QuickIO.tin("example_tin");
@Test
void config() {
Config config = Config.of(c -> {
c.name("example_tin");
c.path("/usr/qio"); //Custom base path.
});
try (JTin tin1 = QuickIO.tin(config)) {
//DB operation.
}
}
@Test
void apis() throws IOException {
//Storage network file stream.
InputStream inputStream = Files.newInputStream(new File("...").toPath());
byte[] bytes = new byte[inputStream.available()];
inputStream.read(bytes);
inputStream.close();
tin.put("photo.png", bytes);
tin.put("photo.png", new File("..."));
//Storing files through network URL
tin.put("baidu_image.png", "https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png");
File file = tin.get("photo.png");
tin.remove("photo.png");
List<File> files = tin.list();
tin.foreach(f -> {
QuickIO.println(f.getPath());
return true; //True is to continue, false is to break.
});
}
}