-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathFileClient.java
More file actions
171 lines (152 loc) · 5.64 KB
/
Copy pathFileClient.java
File metadata and controls
171 lines (152 loc) · 5.64 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package org.hiero.base;
import com.hedera.hashgraph.sdk.FileId;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.util.Objects;
import org.jspecify.annotations.NonNull;
/**
* A client for interacting with the file service on a Hiero network. An implementation of this
* interface is using an internal account to interact with a Hiero network. That account is the
* account that is used to pay for the transactions that are sent to a Hiero network and called
* 'operator account'.
*/
public interface FileClient {
/**
* Create a new file with the given contents.
*
* @param contents the contents of the file
* @return the ID of the new file
* @throws HieroException if the file could not be created
*/
@NonNull FileId createFile(@NonNull byte[] contents) throws HieroException;
/**
* Create a new file with the given contents and expiration time.
*
* @param contents the contents of the file
* @param expirationTime the expiration time of the file
* @return the ID of the new file
* @throws HieroException if the file could not be created
*/
@NonNull FileId createFile(@NonNull byte[] contents, @NonNull Instant expirationTime)
throws HieroException;
/**
* Create a new file with the given contents.
*
* @param fileId the ID of the file to update
* @return the ID of the new file
* @throws HieroException if the file could not be created
*/
@NonNull
default byte[] readFile(@NonNull String fileId) throws HieroException {
Objects.requireNonNull(fileId, "fileId must not be null");
return readFile(FileId.fromString(fileId));
}
/**
* Read the contents of a file.
*
* @param fileId the ID of the file to read
* @return the contents of the file
* @throws HieroException if the file could not be read
*/
@NonNull byte[] readFile(@NonNull FileId fileId) throws HieroException;
/**
* Delete a file.
*
* @param fileId the ID of the file to delete
* @throws HieroException if the file could not be deleted
*/
default void deleteFile(@NonNull String fileId) throws HieroException {
deleteFile(FileId.fromString(fileId));
}
/**
* Delete a file.
*
* @param fileId the ID of the file to delete
* @throws HieroException if the file could not be deleted
*/
void deleteFile(@NonNull FileId fileId) throws HieroException;
/**
* Update the contents of a file.
*
* @param fileId the ID of the file to update
* @param content the new contents of the file
* @throws HieroException if the file could not be updated
*/
void updateFile(@NonNull FileId fileId, byte[] content) throws HieroException;
/**
* Update the expiration time of a file.
*
* @param fileId the ID of the file to update
* @param expirationTime the new expiration time of the file
* @throws HieroException if the file could not be updated
*/
void updateExpirationTime(@NonNull FileId fileId, @NonNull Instant expirationTime)
throws HieroException;
/**
* Appends new file content to the end of an existing file.
*
* @param fileId the ID of the file to append
* @param content the content to append
* @throws HieroException if the content could not be appended to the file
*/
default void appendFile(@NonNull String fileId, @NonNull String content) throws HieroException {
Objects.requireNonNull(fileId, "fileId must not be null");
Objects.requireNonNull(content, "content must not be null");
appendFile(FileId.fromString(fileId), content.getBytes(StandardCharsets.UTF_8));
}
/**
* Appends new file content to the end of an existing file.
*
* @param fileId the ID of the file to append
* @param content the content to append
* @throws HieroException if the content could not be appended to the file
*/
default void appendFile(@NonNull FileId fileId, @NonNull String content) throws HieroException {
Objects.requireNonNull(fileId, "fileId must not be null");
Objects.requireNonNull(content, "content must not be null");
appendFile(fileId, content.getBytes(StandardCharsets.UTF_8));
}
/**
* Appends new file content to the end of an existing file.
*
* @param fileId the ID of the file to append
* @param content the byte content to append
* @throws HieroException if the content could not be appended to the file
*/
default void appendFile(@NonNull String fileId, byte[] content) throws HieroException {
Objects.requireNonNull(fileId, "fileId must not be null");
appendFile(FileId.fromString(fileId), content);
}
/**
* Appends new file content to the end of an existing file.
*
* @param fileId the ID of the file to append
* @param content the byte content to append
* @throws HieroException if the content could not be appended to the file
*/
void appendFile(@NonNull FileId fileId, byte[] content) throws HieroException;
/**
* Check if a file is deleted.
*
* @param fileId the ID of the file to check
* @return true if the file is deleted, false otherwise
* @throws HieroException if the file could not be checked
*/
boolean isDeleted(@NonNull FileId fileId) throws HieroException;
/**
* Get the size of a file.
*
* @param fileId the ID of the file to check
* @return the size of the file
* @throws HieroException if the file could not be checked
*/
int getSize(@NonNull FileId fileId) throws HieroException;
/**
* Get the expiration time of a file.
*
* @param fileId the ID of the file to check
* @return the expiration time of the file
* @throws HieroException if the file could not be checked
*/
@NonNull Instant getExpirationTime(@NonNull FileId fileId) throws HieroException;
}