|
56 | 56 | * </pre> |
57 | 57 | */ |
58 | 58 | @SuppressWarnings("WeakerAccess") |
59 | | -public class Bytes implements Comparable<Bytes> { |
| 59 | +public class Bytes extends AbstractBytes implements Comparable<Bytes> { |
60 | 60 |
|
61 | 61 | /* FACTORY ***************************************************************************************************/ |
62 | 62 |
|
@@ -381,42 +381,16 @@ public static Bytes random(int length, Random random) { |
381 | 381 |
|
382 | 382 | private final byte[] byteArray; |
383 | 383 | private final ByteOrder byteOrder; |
384 | | - private final boolean mutable; |
385 | | - private final boolean readonly; |
386 | 384 |
|
387 | 385 | /** |
388 | 386 | * Creates a new immutable instance |
389 | 387 | * |
390 | 388 | * @param byteArray internal byte array |
391 | 389 | * @param byteOrder the internal byte order - this is used to interpret given array, not to change it |
392 | 390 | */ |
393 | | - Bytes(byte[] byteArray, ByteOrder byteOrder) { |
394 | | - this(byteArray, byteOrder, false, false); |
395 | | - } |
396 | | - |
397 | | - /** |
398 | | - * Creates a new instance with given array and copies all attributes from old instance |
399 | | - * |
400 | | - * @param byteArray internal byte array |
401 | | - * @param oldInstance old instance to copy all internal attributes |
402 | | - */ |
403 | | - Bytes(byte[] byteArray, Bytes oldInstance) { |
404 | | - this(byteArray, oldInstance.byteOrder(), oldInstance.mutable, oldInstance.readonly); |
405 | | - } |
406 | | - |
407 | | - /** |
408 | | - * Creates a new instance |
409 | | - * |
410 | | - * @param byteArray internal byte array |
411 | | - * @param byteOrder the internal byte order - this is used to interpret given array, not to change it |
412 | | - * @param mutable if the internal state can be changed |
413 | | - * @param readonly if all getter for internal byte array will fail |
414 | | - */ |
415 | | - Bytes(byte[] byteArray, ByteOrder byteOrder, boolean mutable, boolean readonly) { |
| 391 | + public Bytes(byte[] byteArray, ByteOrder byteOrder) { |
416 | 392 | this.byteArray = byteArray; |
417 | 393 | this.byteOrder = byteOrder; |
418 | | - this.mutable = mutable; |
419 | | - this.readonly = readonly; |
420 | 394 | } |
421 | 395 |
|
422 | 396 | /* TRANSFORMER **********************************************************************************************/ |
@@ -692,7 +666,7 @@ public Bytes shuffle() { |
692 | 666 | * @return the transformed instance (might be the same, or a new one) |
693 | 667 | */ |
694 | 668 | public Bytes transform(BytesTransformer transformer) { |
695 | | - return transformer.transform(this, mutable); |
| 669 | + return transformer.transform(this, isMutable()); |
696 | 670 | } |
697 | 671 |
|
698 | 672 | /** |
@@ -776,8 +750,9 @@ public ByteOrder byteOrder() { |
776 | 750 | * |
777 | 751 | * @return true if read only |
778 | 752 | */ |
| 753 | + @Override |
779 | 754 | public boolean isReadOnly() { |
780 | | - return readonly; |
| 755 | + return false; |
781 | 756 | } |
782 | 757 |
|
783 | 758 | /** |
@@ -904,7 +879,7 @@ public Bytes byteOrder(ByteOrder byteOrder) { |
904 | 879 | * @return a new instance if not already readonly, or "this" otherwise |
905 | 880 | */ |
906 | 881 | public Bytes readOnly() { |
907 | | - if (readonly) { |
| 882 | + if (isReadOnly()) { |
908 | 883 | return this; |
909 | 884 | } else { |
910 | 885 | return new Bytes(internalArray(), byteOrder, false, true); |
@@ -980,7 +955,7 @@ public InputStream inputStream() { |
980 | 955 | * @throws ReadOnlyBufferException if this is a read-only instance |
981 | 956 | */ |
982 | 957 | public byte[] array() { |
983 | | - if (!readonly) { |
| 958 | + if (!isReadOnly()) { |
984 | 959 | return internalArray(); |
985 | 960 | } |
986 | 961 | throw new ReadOnlyBufferException(); |
|
0 commit comments