@Override /* ConfigStore */ public synchronized String read(String name) throws IOException { String s = cache.get(name); if (s != null) return s; dir.mkdirs(); // If file doesn't exist, don't trigger creation. Path p = dir.toPath().resolve(name); if (! Files.exists(p)) return ""; boolean isWritable = isWritable(p); OpenOption[] oo = isWritable ? new OpenOption[]{READ,WRITE,CREATE} : new OpenOption[]{READ}; try (FileChannel fc = FileChannel.open(p, oo)) { try (FileLock lock = isWritable ? fc.lock() : null) { ByteBuffer buf = ByteBuffer.allocate(1024); StringBuilder sb = new StringBuilder(); while (fc.read(buf) != -1) { sb.append(charset.decode((ByteBuffer)(buf.flip()))); buf.clear(); } s = sb.toString(); cache.put(name, s); } } return cache.get(name); }
@Override /* ConfigStore */ public synchronized String read(String name) throws IOException { name = resolveName(name); Path p = resolveFile(name); name = p.getFileName().toString(); String s = cache.get(name); if (s != null) return s; dir.mkdirs(); // If file doesn't exist, don't trigger creation. if (! Files.exists(p)) return ""; boolean isWritable = isWritable(p); OpenOption[] oo = isWritable ? new OpenOption[]{READ,WRITE,CREATE} : new OpenOption[]{READ}; try (FileChannel fc = FileChannel.open(p, oo)) { try (FileLock lock = isWritable ? fc.lock() : null) { ByteBuffer buf = ByteBuffer.allocate(1024); StringBuilder sb = new StringBuilder(); while (fc.read(buf) != -1) { sb.append(charset.decode((ByteBuffer)(buf.flip()))); buf.clear(); } s = sb.toString(); cache.put(name, s); } } return cache.get(name); }
@Override /* ConfigStore */ public synchronized String read(String name) throws IOException { name = resolveName(name); Path p = resolveFile(name); name = p.getFileName().toString(); String s = cache.get(name); if (s != null) return s; dir.mkdirs(); // If file doesn't exist, don't trigger creation. if (! Files.exists(p)) return ""; boolean isWritable = isWritable(p); OpenOption[] oo = isWritable ? new OpenOption[]{READ,WRITE,CREATE} : new OpenOption[]{READ}; try (FileChannel fc = FileChannel.open(p, oo)) { try (FileLock lock = isWritable ? fc.lock() : null) { ByteBuffer buf = ByteBuffer.allocate(1024); StringBuilder sb = new StringBuilder(); while (fc.read(buf) != -1) { sb.append(charset.decode((ByteBuffer)(buf.flip()))); buf.clear(); } s = sb.toString(); cache.put(name, s); } } return cache.get(name); }
return ""; if (isWritable(p)) { if (newContents == null) Files.delete(p);
return ""; if (isWritable(p)) { if (newContents == null) Files.delete(p);
return ""; if (isWritable(p)) { if (newContents == null) Files.delete(p);