-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAIOFileReader.java
More file actions
60 lines (46 loc) · 1.71 KB
/
AIOFileReader.java
File metadata and controls
60 lines (46 loc) · 1.71 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
package io.github.kavahub.file.reader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import io.github.kavahub.file.Consts;
import io.github.kavahub.file.query.Query;
import lombok.experimental.UtilityClass;
@UtilityClass
public class AIOFileReader {
public Query<String> line(Path file) {
return line(file, Consts.BUFFER_SIZE);
}
public Query<String> line(Path file, int bufferSize) {
if (bufferSize <= 0) {
throw new IllegalArgumentException("bufferSize");
}
return new QueryLine(new FileByteReaderQuery(file, bufferSize));
}
public Query<String> allLines(Path file) {
return allLines(file, Consts.BUFFER_SIZE);
}
public Query<String> allLines(Path file, int bufferSize) {
if (bufferSize <= 0) {
throw new IllegalArgumentException("bufferSize");
}
return new QueryAllBytes(new FileByteReaderQuery(file, bufferSize))
.map(bytes -> new String(bytes, StandardCharsets.UTF_8));
}
public Query<byte[]> bytes(Path file) {
return new FileByteReaderQuery(file, Consts.BUFFER_SIZE);
}
public Query<byte[]> bytes(Path file, int bufferSize) {
if (bufferSize <= 0) {
throw new IllegalArgumentException("bufferSize");
}
return new FileByteReaderQuery(file, bufferSize);
}
public Query<byte[]> allBytes(Path file) {
return allBytes(file, Consts.BUFFER_SIZE);
}
public Query<byte[]> allBytes(Path file, int bufferSize) {
if (bufferSize <= 0) {
throw new IllegalArgumentException("bufferSize");
}
return new QueryAllBytes(new FileByteReaderQuery(file, bufferSize));
}
}