Skip to content

Commit fe1ef60

Browse files
committed
src: use Java17 HexFormat instead of BaseEncoding from guava
Motivation: Java 17 provides native way to encode/decode hex stings, thus, there are no reasons to use an alternative from guava. Modification: replace calls to BaseEncoding.base16() with HexFormat.of() Result: less dependency on external library Acked-by: Dmitry Litvintsev Target: master
1 parent c8d57f2 commit fe1ef60

File tree

11 files changed

+41
-50
lines changed

11 files changed

+41
-50
lines changed

basic-client/src/main/java/org/dcache/nfs/v4/client/Main.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009 - 2021 Deutsches Elektronen-Synchroton,
2+
* Copyright (c) 2009 - 2025 Deutsches Elektronen-Synchroton,
33
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
44
*
55
* This library is free software; you can redistribute it and/or modify
@@ -29,6 +29,7 @@
2929
import java.util.Arrays;
3030
import java.util.Date;
3131
import java.util.HashMap;
32+
import java.util.HexFormat;
3233
import java.util.List;
3334
import java.util.Map;
3435
import java.util.Optional;
@@ -91,7 +92,6 @@
9192
import com.google.common.cache.CacheBuilder;
9293
import com.google.common.cache.CacheLoader;
9394
import com.google.common.cache.LoadingCache;
94-
import com.google.common.io.BaseEncoding;
9595
import com.google.common.net.HostAndPort;
9696

9797
public class Main {
@@ -656,7 +656,7 @@ private void getRootFh(String path) throws OncRpcException, IOException {
656656

657657
_rootFh = compound4res.resarray.get(compound4res.resarray.size() - 1).opgetfh.resok4.object;
658658
_cwd = _rootFh;
659-
System.out.println("root fh = " + BaseEncoding.base16().lowerCase().encode(_rootFh.value));
659+
System.out.println("root fh = " + HexFormat.of().formatHex(_rootFh.value));
660660
}
661661

662662
public void readdir() throws OncRpcException, IOException {
@@ -787,7 +787,7 @@ nfs_fh4 cwd(String path) throws OncRpcException, IOException {
787787
COMPOUND4res compound4res = sendCompoundInSession(args);
788788

789789
_cwd = compound4res.resarray.get(compound4res.resarray.size() - 1).opgetfh.resok4.object;
790-
System.out.println("CWD fh = " + BaseEncoding.base16().lowerCase().encode(_cwd.value));
790+
System.out.println("CWD fh = " + HexFormat.of().formatHex(_cwd.value));
791791
return new nfs_fh4(_cwd.value);
792792
}
793793

@@ -942,7 +942,7 @@ private OpenReply open(String path) throws OncRpcException, IOException {
942942

943943
nfs_fh4 fh = compound4res.resarray.get(opCount - 1).opgetfh.resok4.object;
944944
stateid4 stateid = compound4res.resarray.get(opCount - 2).opopen.resok4.stateid;
945-
System.out.println("open_read fh = " + BaseEncoding.base16().lowerCase().encode(fh.value));
945+
System.out.println("open_read fh = " + HexFormat.of().formatHex(fh.value));
946946

947947
return new OpenReply(fh, stateid);
948948
}
@@ -961,7 +961,7 @@ private OpenReply create(String path) throws OncRpcException, IOException {
961961
int opCount = compound4res.resarray.size();
962962
nfs_fh4 fh = compound4res.resarray.get(opCount - 1).opgetfh.resok4.object;
963963
stateid4 stateid = compound4res.resarray.get(opCount - 2).opopen.resok4.stateid;
964-
System.out.println("open_read fh = " + BaseEncoding.base16().lowerCase().encode(fh.value));
964+
System.out.println("open_read fh = " + HexFormat.of().formatHex(fh.value));
965965

966966
return new OpenReply(fh, stateid);
967967
}
@@ -990,7 +990,7 @@ private StripeMap layoutget(nfs_fh4 fh, stateid4 stateid, int layoutiomode) thro
990990
COMPOUND4res compound4res = sendCompoundInSession(args);
991991

992992
layout4[] layout = compound4res.resarray.get(2).oplayoutget.logr_resok4.logr_layout;
993-
System.out.println("Layoutget for fh: " + BaseEncoding.base16().lowerCase().encode(fh.value));
993+
System.out.println("Layoutget for fh: " + HexFormat.of().formatHex(fh.value));
994994
System.out.println(" roc : " + compound4res.resarray.get(2).oplayoutget.logr_resok4.logr_return_on_close);
995995

996996
StripeMap stripeMap = new StripeMap(compound4res.resarray.get(2).oplayoutget.logr_resok4.logr_stateid);
@@ -1002,7 +1002,7 @@ private StripeMap layoutget(nfs_fh4 fh, stateid4 stateid, int layoutiomode) thro
10021002
+ fileDevice.nfl_deviceid.value.length);
10031003

10041004
_ioFH = fileDevice.nfl_fh_list[0];
1005-
System.out.println(" io fh: " + BaseEncoding.base16().lowerCase().encode(_ioFH.value));
1005+
System.out.println(" io fh: " + HexFormat.of().formatHex(_ioFH.value));
10061006
System.out.println(" length: " + l.lo_length.value);
10071007
System.out.println(" offset: " + l.lo_offset.value);
10081008
System.out.println(" type : " + l.lo_content.loc_type);
@@ -1313,7 +1313,7 @@ private void lookup(String fh, String path) throws OncRpcException, IOException
13131313
.build();
13141314

13151315
COMPOUND4res compound4res = sendCompoundInSession(args);
1316-
System.out.println("fh = " + BaseEncoding.base16().lowerCase().encode(compound4res.resarray.get(
1316+
System.out.println("fh = " + HexFormat.of().formatHex(compound4res.resarray.get(
13171317
compound4res.resarray.size() - 1).opgetfh.resok4.object.value));
13181318
}
13191319

core/src/main/java/org/dcache/nfs/v4/NFS4Client.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.Arrays;
2929
import java.util.Collection;
3030
import java.util.HashMap;
31+
import java.util.HexFormat;
3132
import java.util.Iterator;
3233
import java.util.List;
3334
import java.util.Map;
@@ -55,10 +56,9 @@
5556
import org.slf4j.Logger;
5657
import org.slf4j.LoggerFactory;
5758

58-
/**
59+
/*
5960
* with great help of William A.(Andy) Adamson
6061
*/
61-
import com.google.common.io.BaseEncoding;
6262

6363
public class NFS4Client {
6464

@@ -285,8 +285,7 @@ public void updateLeaseTime() throws ChimeraNFSException {
285285
Instant curentTime = _clock.instant();
286286
var delta = Duration.between(_lastLeaseUpdate, curentTime);
287287
if (delta.compareTo(_leaseTime) > 0) {
288-
throw new ExpiredException("lease time expired: (" + delta + "): " + BaseEncoding.base16().lowerCase()
289-
.encode(_ownerId) +
288+
throw new ExpiredException("lease time expired: (" + delta + "): " + HexFormat.of().formatHex(_ownerId) +
290289
" (" + _clientId + ").");
291290
}
292291
_lastLeaseUpdate = curentTime;
@@ -441,7 +440,7 @@ public NFS4State state(stateid4 stateid) throws ChimeraNFSException {
441440
public String toString() {
442441
StringBuilder sb = new StringBuilder();
443442
sb.append(_clientAddress).append(":")
444-
.append(BaseEncoding.base16().lowerCase().encode(_ownerId))
443+
.append(HexFormat.of().formatHex(_ownerId))
445444
.append("@")
446445
.append(_clientId)
447446
.append(":v4.").append(getMinorVersion());

core/src/main/java/org/dcache/nfs/v4/NFSv41Session.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009 - 2020 Deutsches Elektronen-Synchroton,
2+
* Copyright (c) 2009 - 2025 Deutsches Elektronen-Synchroton,
33
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
44
*
55
* This library is free software; you can redistribute it and/or modify
@@ -20,6 +20,7 @@
2020
package org.dcache.nfs.v4;
2121

2222
import java.util.HashSet;
23+
import java.util.HexFormat;
2324
import java.util.List;
2425
import java.util.Set;
2526

@@ -28,8 +29,6 @@
2829
import org.dcache.nfs.v4.xdr.nfs_resop4;
2930
import org.dcache.nfs.v4.xdr.sessionid4;
3031

31-
import com.google.common.io.BaseEncoding;
32-
3332
public class NFSv41Session {
3433

3534
private final sessionid4 _session;
@@ -146,7 +145,7 @@ public int getMaxCbOps() {
146145

147146
@Override
148147
public String toString() {
149-
return _client.getRemoteAddress() + " : " + BaseEncoding.base16().lowerCase().encode(_session.value);
148+
return _client.getRemoteAddress() + " : " + HexFormat.of().formatHex(_session.value);
150149
}
151150

152151
/**

core/src/main/java/org/dcache/nfs/v4/xdr/deviceid4.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
2+
* Copyright (c) 2009 - 2025 Deutsches Elektronen-Synchroton,
33
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
44
*
55
* This library is free software; you can redistribute it and/or modify
@@ -21,14 +21,13 @@
2121

2222
import java.io.IOException;
2323
import java.util.Arrays;
24+
import java.util.HexFormat;
2425

2526
import org.dcache.oncrpc4j.rpc.OncRpcException;
2627
import org.dcache.oncrpc4j.xdr.XdrAble;
2728
import org.dcache.oncrpc4j.xdr.XdrDecodingStream;
2829
import org.dcache.oncrpc4j.xdr.XdrEncodingStream;
2930

30-
import com.google.common.io.BaseEncoding;
31-
3231
public class deviceid4 implements XdrAble {
3332

3433
public byte[] value;
@@ -73,7 +72,7 @@ public boolean equals(Object obj) {
7372

7473
@Override
7574
public String toString() {
76-
return BaseEncoding.base16().lowerCase().encode(value);
75+
return HexFormat.of().formatHex(value);
7776
}
7877
}
7978
// End of deviceid4.java

core/src/main/java/org/dcache/nfs/v4/xdr/nfs_fh4.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,13 @@
2121

2222
import java.io.IOException;
2323
import java.util.Arrays;
24-
import java.util.Objects;
24+
import java.util.HexFormat;
2525

2626
import org.dcache.oncrpc4j.rpc.OncRpcException;
2727
import org.dcache.oncrpc4j.xdr.XdrAble;
2828
import org.dcache.oncrpc4j.xdr.XdrDecodingStream;
2929
import org.dcache.oncrpc4j.xdr.XdrEncodingStream;
3030

31-
import com.google.common.io.BaseEncoding;
32-
3331
public class nfs_fh4 implements XdrAble {
3432

3533
public byte[] value;
@@ -58,7 +56,7 @@ public void xdrDecode(XdrDecodingStream xdr)
5856

5957
@Override
6058
public String toString() {
61-
return BaseEncoding.base16().lowerCase().encode(value);
59+
return HexFormat.of().formatHex(value);
6260
}
6361

6462
@Override

core/src/main/java/org/dcache/nfs/v4/xdr/sessionid4.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
2+
* Copyright (c) 2009 - 2025 Deutsches Elektronen-Synchroton,
33
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
44
*
55
* This library is free software; you can redistribute it and/or modify
@@ -21,14 +21,13 @@
2121

2222
import java.io.IOException;
2323
import java.util.Arrays;
24+
import java.util.HexFormat;
2425

2526
import org.dcache.oncrpc4j.rpc.OncRpcException;
2627
import org.dcache.oncrpc4j.xdr.XdrAble;
2728
import org.dcache.oncrpc4j.xdr.XdrDecodingStream;
2829
import org.dcache.oncrpc4j.xdr.XdrEncodingStream;
2930

30-
import com.google.common.io.BaseEncoding;
31-
3231
public class sessionid4 implements XdrAble {
3332

3433
public byte[] value;
@@ -76,7 +75,7 @@ public int hashCode() {
7675

7776
@Override
7877
public String toString() {
79-
return BaseEncoding.base16().lowerCase().encode(value);
78+
return HexFormat.of().formatHex(value);
8079
}
8180
}
8281
// End of sessionid4.java

core/src/main/java/org/dcache/nfs/v4/xdr/state_owner4.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009 - 2015 Deutsches Elektronen-Synchroton,
2+
* Copyright (c) 2009 - 2025 Deutsches Elektronen-Synchroton,
33
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
44
*
55
* This library is free software; you can redistribute it and/or modify
@@ -22,6 +22,7 @@
2222
import java.io.IOException;
2323
import java.io.Serializable;
2424
import java.util.Arrays;
25+
import java.util.HexFormat;
2526
import java.util.Objects;
2627

2728
import org.dcache.oncrpc4j.rpc.OncRpcException;
@@ -30,7 +31,6 @@
3031
import org.dcache.oncrpc4j.xdr.XdrEncodingStream;
3132

3233
import com.google.common.base.MoreObjects;
33-
import com.google.common.io.BaseEncoding;
3434

3535
public class state_owner4 implements XdrAble, Serializable {
3636

@@ -91,7 +91,7 @@ public boolean equals(Object obj) {
9191
public String toString() {
9292
return MoreObjects.toStringHelper(this.getClass().getSimpleName())
9393
.add("clientid", Long.toString(clientid.value, 16))
94-
.add("ownerid", BaseEncoding.base16().lowerCase().encode(owner))
94+
.add("ownerid", HexFormat.of().formatHex(owner))
9595
.toString();
9696
}
9797
}

core/src/main/java/org/dcache/nfs/v4/xdr/stateid4.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009 - 2020 Deutsches Elektronen-Synchroton,
2+
* Copyright (c) 2009 - 2025 Deutsches Elektronen-Synchroton,
33
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
44
*
55
* This library is free software; you can redistribute it and/or modify
@@ -22,14 +22,13 @@
2222
import java.io.IOException;
2323
import java.io.Serializable;
2424
import java.util.Arrays;
25+
import java.util.HexFormat;
2526

2627
import org.dcache.oncrpc4j.rpc.OncRpcException;
2728
import org.dcache.oncrpc4j.xdr.XdrAble;
2829
import org.dcache.oncrpc4j.xdr.XdrDecodingStream;
2930
import org.dcache.oncrpc4j.xdr.XdrEncodingStream;
3031

31-
import com.google.common.io.BaseEncoding;
32-
3332
public class stateid4 implements XdrAble, Serializable {
3433

3534
static final long serialVersionUID = -6677150504723505919L;
@@ -100,7 +99,7 @@ public String toString() {
10099
StringBuilder sb = new StringBuilder();
101100

102101
sb.append("[");
103-
sb.append(BaseEncoding.base16().lowerCase().encode(other));
102+
sb.append(HexFormat.of().formatHex(other));
104103
sb.append(", seq: ").append(seqid).append("]");
105104
return sb.toString();
106105
}

core/src/main/java/org/dcache/nfs/v4/xdr/verifier4.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
2+
* Copyright (c) 2009 - 2025 Deutsches Elektronen-Synchroton,
33
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
44
*
55
* This library is free software; you can redistribute it and/or modify
@@ -21,15 +21,14 @@
2121

2222
import java.io.IOException;
2323
import java.util.Arrays;
24+
import java.util.HexFormat;
2425

2526
import org.dcache.oncrpc4j.rpc.OncRpcException;
2627
import org.dcache.oncrpc4j.util.Bytes;
2728
import org.dcache.oncrpc4j.xdr.XdrAble;
2829
import org.dcache.oncrpc4j.xdr.XdrDecodingStream;
2930
import org.dcache.oncrpc4j.xdr.XdrEncodingStream;
3031

31-
import com.google.common.io.BaseEncoding;
32-
3332
public class verifier4 implements XdrAble {
3433

3534
public byte[] value;
@@ -77,7 +76,7 @@ public boolean equals(Object o) {
7776
@Override
7877
public String toString() {
7978
StringBuilder sb = new StringBuilder();
80-
sb.append('[').append(BaseEncoding.base16().lowerCase().encode(value)).append(']');
79+
sb.append('[').append(HexFormat.of().formatHex(value)).append(']');
8180
return sb.toString();
8281
}
8382

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@
2222
import java.nio.ByteBuffer;
2323
import java.nio.ByteOrder;
2424
import java.util.Arrays;
25+
import java.util.HexFormat;
2526

2627
import org.dcache.nfs.util.Opaque;
2728

28-
import com.google.common.io.BaseEncoding;
29-
3029
/**
3130
* NFS file handle on wire representation format v1.
3231
*
@@ -135,7 +134,7 @@ protected int getType() {
135134

136135
@Override
137136
public String toString() {
138-
return BaseEncoding.base16().lowerCase().encode(nfsHandle);
137+
return HexFormat.of().formatHex(nfsHandle);
139138
}
140139

141140
public static Inode forNfsHandle(byte[] bytes) {

0 commit comments

Comments
 (0)