|
18 | 18 |
|
19 | 19 | package org.apache.zookeeper; |
20 | 20 |
|
21 | | -import java.io.File; |
22 | 21 | import java.util.ArrayDeque; |
23 | 22 | import java.util.ArrayList; |
24 | 23 | import java.util.Collections; |
25 | 24 | import java.util.List; |
26 | | -import java.util.Map; |
27 | 25 | import java.util.Queue; |
28 | | -import java.util.concurrent.ConcurrentHashMap; |
29 | 26 | import java.util.concurrent.Semaphore; |
30 | 27 | import java.util.concurrent.atomic.AtomicBoolean; |
31 | 28 | import org.apache.zookeeper.AsyncCallback.MultiCallback; |
32 | 29 | import org.apache.zookeeper.AsyncCallback.StringCallback; |
33 | 30 | import org.apache.zookeeper.AsyncCallback.VoidCallback; |
34 | 31 | import org.apache.zookeeper.KeeperException.Code; |
35 | 32 | import org.apache.zookeeper.common.PathUtils; |
36 | | -import org.apache.zookeeper.data.ACL; |
37 | 33 | import org.slf4j.Logger; |
38 | 34 | import org.slf4j.LoggerFactory; |
39 | 35 |
|
40 | | -public class ZKUtil { |
| 36 | +public class ZKUtil extends ZKCommonUtil { |
41 | 37 |
|
42 | 38 | private static final Logger LOG = LoggerFactory.getLogger(ZKUtil.class); |
43 | | - private static final Map<Integer, String> permCache = new ConcurrentHashMap<>(); |
44 | 39 | /** |
45 | 40 | * Recursively delete the node with the given path. |
46 | 41 | * <p> |
@@ -166,24 +161,6 @@ public static void deleteRecursive( |
166 | 161 | } |
167 | 162 | } |
168 | 163 |
|
169 | | - /** |
170 | | - * @param filePath the file path to be validated |
171 | | - * @return Returns null if valid otherwise error message |
172 | | - */ |
173 | | - public static String validateFileInput(String filePath) { |
174 | | - File file = new File(filePath); |
175 | | - if (!file.exists()) { |
176 | | - return "File '" + file.getAbsolutePath() + "' does not exist."; |
177 | | - } |
178 | | - if (!file.canRead()) { |
179 | | - return "Read permission is denied on the file '" + file.getAbsolutePath() + "'"; |
180 | | - } |
181 | | - if (file.isDirectory()) { |
182 | | - return "'" + file.getAbsolutePath() + "' is a directory. it must be a file."; |
183 | | - } |
184 | | - return null; |
185 | | - } |
186 | | - |
187 | 164 | /** |
188 | 165 | * BFS Traversal of the system under pathRoot, with the entries in the list, in the |
189 | 166 | * same order as that of the traversal. |
@@ -266,45 +243,4 @@ private static void visitSubTreeDFSHelper( |
266 | 243 | return; // ignore |
267 | 244 | } |
268 | 245 | } |
269 | | - |
270 | | - /** |
271 | | - * @param perms |
272 | | - * ACL permissions |
273 | | - * @return string representation of permissions |
274 | | - */ |
275 | | - public static String getPermString(int perms) { |
276 | | - return permCache.computeIfAbsent(perms, k -> constructPermString(k)); |
277 | | - } |
278 | | - |
279 | | - private static String constructPermString(int perms) { |
280 | | - StringBuilder p = new StringBuilder(); |
281 | | - if ((perms & ZooDefs.Perms.CREATE) != 0) { |
282 | | - p.append('c'); |
283 | | - } |
284 | | - if ((perms & ZooDefs.Perms.DELETE) != 0) { |
285 | | - p.append('d'); |
286 | | - } |
287 | | - if ((perms & ZooDefs.Perms.READ) != 0) { |
288 | | - p.append('r'); |
289 | | - } |
290 | | - if ((perms & ZooDefs.Perms.WRITE) != 0) { |
291 | | - p.append('w'); |
292 | | - } |
293 | | - if ((perms & ZooDefs.Perms.ADMIN) != 0) { |
294 | | - p.append('a'); |
295 | | - } |
296 | | - return p.toString(); |
297 | | - } |
298 | | - |
299 | | - public static String aclToString(List<ACL> acls) { |
300 | | - StringBuilder sb = new StringBuilder(); |
301 | | - for (ACL acl : acls) { |
302 | | - sb.append(acl.getId().getScheme()); |
303 | | - sb.append(":"); |
304 | | - sb.append(acl.getId().getId()); |
305 | | - sb.append(":"); |
306 | | - sb.append(getPermString(acl.getPerms())); |
307 | | - } |
308 | | - return sb.toString(); |
309 | | - } |
310 | 246 | } |
0 commit comments