]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.api.uuid/src/org/argeo/api/uuid/BinaryNameUuid.java
Improve build and local deployment
[lgpl/argeo-commons.git] / org.argeo.api.uuid / src / org / argeo / api / uuid / BinaryNameUuid.java
1 package org.argeo.api.uuid;
2
3 import java.util.UUID;
4
5 /**
6 * A name UUID whose binary data used for its construction is known. A new byte
7 * array is created and it is copied when retrieved, so this would be
8 * inefficient and memory consuming for big data amounts. This rather meant to
9 * be used for small binary data, such as certificates, etc.
10 */
11 public class BinaryNameUuid extends BasicNameUuid {
12 private static final long serialVersionUID = APM.SERIAL;
13
14 protected final TypedUuid namespace;
15 protected final byte[] bytes;
16
17 /** Static builder (a {@link TypedUuidFactory} may be more efficient). */
18 public BinaryNameUuid(TypedUuid namespace, byte[] bytes, boolean sha1) {
19 this(sha1 ? AbstractUuidFactory.createNameUUIDv5Static(namespace.uuid, bytes)
20 : AbstractUuidFactory.createNameUUIDv5Static(namespace.uuid, bytes), namespace, bytes);
21 }
22
23 /**
24 * Since no check is performed, the constructor is protected so that the object
25 * can only be built by the default methods of {@link TypedUuidFactory} (in this
26 * package) or by extending the class.
27 */
28 protected BinaryNameUuid(UUID uuid, TypedUuid namespace, byte[] bytes) {
29 super(uuid);
30 this.namespace = namespace;
31 this.bytes = new byte[bytes.length];
32 System.arraycopy(bytes, 0, this.bytes, 0, bytes.length);
33 }
34
35 /** The namespace used to build this UUID. */
36 public final TypedUuid getNamespace() {
37 return namespace;
38 }
39
40 /**
41 * A <strong>copy</strong> of the bytes which have been hashed. In order to
42 * access the byte array directly, the class must be extended.
43 */
44 public final byte[] getBytes() {
45 byte[] bytes = new byte[this.bytes.length];
46 System.arraycopy(this.bytes, 0, bytes, 0, this.bytes.length);
47 return bytes;
48 }
49
50 /** Always returns <code>false</code> since the construction value is known. */
51 @Override
52 public final boolean isOpaque() {
53 return false;
54 }
55
56 }