Skip to content

Commit e74c087

Browse files
committed
core, dlm: Opaque: rename methods to properly indicate conversion step
Converting an Opaque to a byte[] or Base64-string may involve an allocation, not just a mere cast/dereference. Therefore, call these methods "toBytes" and toBase64". Related: #149 Signed-off-by: Christian Kohlschütter <[email protected]>
1 parent 957551f commit e74c087

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

core/src/main/java/org/dcache/nfs/util/Opaque.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ public static Opaque forBytes(byte[] bytes) {
3131
return new OpaqueImpl(bytes.clone());
3232
}
3333

34-
byte[] asBytes();
34+
byte[] toBytes();
3535

36-
String getBase64();
36+
String toBase64();
3737

3838
@Override
3939
int hashCode();
@@ -50,12 +50,12 @@ private OpaqueImpl(byte[] opaque) {
5050
}
5151

5252
@Override
53-
public byte[] asBytes() {
53+
public byte[] toBytes() {
5454
return _opaque.clone();
5555
}
5656

5757
@Override
58-
public String getBase64() {
58+
public String toBase64() {
5959
if (base64 == null) {
6060
base64 = Base64.getEncoder().withoutPadding().encodeToString(_opaque);
6161
}
@@ -79,18 +79,18 @@ public boolean equals(Object o) {
7979
if (o instanceof OpaqueImpl) {
8080
return Arrays.equals(_opaque, ((OpaqueImpl) o)._opaque);
8181
} else {
82-
return Arrays.equals(_opaque, ((Opaque) o).asBytes());
82+
return Arrays.equals(_opaque, ((Opaque) o).toBytes());
8383
}
8484
}
8585

8686
/**
8787
* Returns a (potentially non-stable) debug string.
8888
*
89-
* @see #getBase64()
89+
* @see #toBase64()
9090
*/
9191
@Override
9292
public String toString() {
93-
return super.toString() + "[" + getBase64() + "]";
93+
return super.toString() + "[" + toBase64() + "]";
9494
}
9595
}
9696
}

core/src/main/java/org/dcache/nfs/v4/nlm/SimpleLm.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ protected void removeAll(Opaque objId, Collection<NlmLock> locks) {
113113
}
114114

115115
private final String toKey(Opaque objId) {
116-
return objId.getBase64();
116+
return objId.toBase64();
117117
}
118118

119119
}

core/src/main/java/org/dcache/nfs/vfs/FsCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ private static class FileChannelSupplier extends CacheLoader<Inode, FileChannel>
5252

5353
@Override
5454
public FileChannel load(Inode inode) throws IOException {
55-
String id = inode.getLockKey().getBase64();
55+
String id = inode.getLockKey().toBase64();
5656
File dir = getAndCreateDirectory(id);
5757
File f = new File(dir, id);
5858
return new RandomAccessFile(f, "rw").getChannel();

core/src/main/java/org/dcache/nfs/vfs/Inode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,12 @@ public static Inode forFile(byte[] bytes) {
145145
}
146146

147147
public static Inode forFileIdKey(Opaque key) {
148-
return forFile(key.asBytes());
148+
return forFile(key.toBytes());
149149
}
150150

151151
@Deprecated(forRemoval = true)
152152
public byte[] getFileId() {
153-
return opaqueKey.asBytes();
153+
return opaqueKey.toBytes();
154154
}
155155

156156
/**

dlm/src/main/java/org/dcache/nfs/v4/nlm/DistributedLockManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ protected void removeAll(Opaque objId, Collection<NlmLock> locks) {
134134
}
135135

136136
private static String objIdToKey(Opaque objId) {
137-
return objId.getBase64();
137+
return objId.toBase64();
138138
}
139139

140140
}

0 commit comments

Comments
 (0)