ByteArray implements Serializable, Cloneable { public ByteArray writeAsPs(String s, int displacement, int length) { s = s.trim(); Matcher matcher = psRegexPattern.matcher(s); if (!matcher.matches()) { throw new IllegalArgumentException("Value:" + s + " has illegal character values for a packed field."); } char sign = 'F'; if (s.length() > 0) { if (s.charAt(s.length() - 1) == '+' || s.charAt(0) == '+') { sign = 'C'; s = s.replaceAll("\\+", ""); } else if (s.charAt(s.length() - 1) == '-' || s.charAt(0) == '-') { sign = 'D'; s = s.replaceAll("-", ""); } } s += sign; writeAsPns(s, displacement, length, '0'); return this; } 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 testWriteAsPs() { byteArray = new ByteArray(10); byteArray.fill((byte) 0xBB); byteArray.writeAsPs("1234+", 0, 3); ByteArrayDumpFormatter.dumpByteArray("testWriteAsPs1234+", byteArray); String value = byteArray.readPns(0, 10, false); assertTrue(value.equals("01234CBBBBBBBBBBBBBB")); byteArray.writeAsPs("+1234", 0, 3); ByteArrayDumpFormatter.dumpByteArray("testWriteAsPs+1234", byteArray); value = byteArray.readPns(0, 10, false); assertTrue(value.equals("01234CBBBBBBBBBBBBBB")); byteArray.writeAsPs("1234-", 1, 4); ByteArrayDumpFormatter.dumpByteArray("testWriteAsPs1234-", byteArray); value = byteArray.readPns(0, 10, false); assertTrue(value.equals("010001234DBBBBBBBBBB")); byteArray.writeAsPs("1234", 0, 3); ByteArrayDumpFormatter.dumpByteArray("testWriteAsPs1234", byteArray); value = byteArray.readPns(0, 10, false); assertTrue(value.equals("01234F234DBBBBBBBBBB")); }