ByteArray implements Serializable, Cloneable { public Object clone() throws CloneNotSupportedException { if (value.isDirect()) { throw new CloneNotSupportedException("Can't clone a direct buffer"); } ByteArray object = (ByteArray) super.clone(); value.clear(); byte[] bytes = new byte[value.remaining()]; value.get(bytes); object.value = ByteBuffer.wrap(bytes); object.value.order(value.order()); return object; } ByteArray(int size);  ByteArray(int size, String encoding);  ByteArray(int size, ByteOrder order);  ByteArray(int size, String encoding, ByteOrder order);  ByteArray(byte[] array);  ByteArray(byte[] array, ByteOrder order);  ByteArray(byte[] array, String encoding);  ByteArray(byte[] array, String encoding, ByteOrder order);  ByteArray(ByteArray byteArray);  ByteArray(ByteBuffer buffer);  ByteArray(ByteBuffer buffer, String encoding); Object clone(); ByteArray slice(int displacement, int length); ByteArray duplicate(); boolean testBit(int displacement, byte mask); ByteArray setBit(int displacement, byte mask); ByteArray setBit(int displacement, byte mask, boolean b); ByteArray clearBit(int displacement, byte mask); byte[] read(int displacement, int length); int read(int displacement, byte[] bytes); int read(int displacement, byte[] bytes, int offset, int length); byte readAsByte(int displacement); ByteArray readAsByteArray(int displacement, int length); char readAsChar(int displacement); char[] readAsCharArray(int displacement, int length); int read(int displacement, char[] chars); int read(int displacement, char[] chars, int offset, int length); String readAsString(); String readAsString(int displacement); String readAsString(int displacement, int length); String readAsString(int displacement, int length, boolean nts); float readAsFloat(int displacement); double readAsDouble(int displacement); short readAsShort(int displacement); int readAsInt(int displacement); long readAsLong(int displacement); String readPns(int displacement, int length); String readPns(int displacement, int length, boolean convertAtoF); ByteArray fill(); ByteArray fill(byte filler); ByteArray fill(byte filler, int displacement, int length); ByteArray write(char[] chars, int displacement); ByteArray write(char[] chars, int offset, int length, int displacement); ByteArray write(ByteArray byteArray, int displacement, int length); ByteArray write(ByteArray byteArray, int displacement); ByteArray write(byte[] bytes, int displacement); ByteArray write(byte[] bytes, int offset, int length, int displacement); ByteArray write(String s, int displacement); ByteArray write(String s, int displacement, int length); ByteArray write(String s, int displacement, int length, boolean nts); ByteArray write(short s, int displacement); ByteArray write(char c, int displacement); ByteArray write(byte b, int displacement); ByteArray write(int i, int displacement); ByteArray write(long i, int displacement); ByteArray write(float f, int displacement); ByteArray write(double d, int displacement); ByteArray writeAsPs(String s, int displacement, int length); ByteArray writeAsPns(String s, int displacement, int length); ByteArray writeAsPns(String s, int displacement, int length,
                                char filler); static byte getSpaceFiller(String encoding); static ByteArray valueOf(String string); @Override boolean equals(Object anObject); static boolean equalTo(ByteArray a, ByteArray b); boolean equalSame(byte b); boolean equalSame(byte b, int displacement, int length); int getLength(); boolean hasArray(); UnderlyingArray getArray(); byte[] getBytes(); @Deprecated byte[] getByteArray(); ByteArray setEncoding(String encoding); String getEncoding(); ByteArray setOrder(ByteOrder order); ByteOrder getOrder(); ByteBuffer getBuffer(); static final String ASCII_CHARSET_NAME; static final String EBCDIC_CHARSET_NAME; }
@Test public void testClone() throws CloneNotSupportedException { byteArray = new ByteArray(200, ByteArray.EBCDIC_CHARSET_NAME); byteArray.write((int) 10, 0); byteArray.write((long) 33333, 4); byteArray.write("TESTTESTTEST", 12); ByteArray byteArrayClone = (ByteArray) byteArray.clone(); assertTrue(byteArray.equals(byteArrayClone)); assertTrue(byteArray.getArray().value!= byteArrayClone.getArray().value); assertTrue(byteArray.getLength() == byteArrayClone.getLength()); assertTrue(byteArray.getEncoding().equals(byteArrayClone.getEncoding())); assertTrue(byteArray.getOrder() == byteArrayClone.getOrder()); String s1 = byteArray.readPns(0, 200); String s2 = byteArrayClone.readPns(0, 200); assertTrue(s1.equals(s2)); }