java.lang.Object
com.ibm.jzos.fields.StringField
- All Implemented Interfaces:
Field
A String
Field.
- Since:
- 2.1.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final charThe Unicode character that translates to EBCDIC 0xFF using Cp1047 -
Constructor Summary
ConstructorsConstructorDescriptionStringField(int offset, int length) Construct an instance with trim=true, padLeft=false, and allowTruncation=true.StringField(int offset, int length, boolean trim) Construct an instance with padLeft=false and allowTruncation=true.StringField(int offset, int length, boolean trim, boolean padLeft) Construct an instance with allowTruncation=true.StringField(int offset, int length, boolean trim, boolean padLeft, boolean allowTruncation) Construct an instance.StringField(int offset, int length, boolean trim, boolean padLeft, boolean allowTruncation, String encoding) Construct an instance. -
Method Summary
Modifier and TypeMethodDescriptionbooleanCompare two Strings, possible null, for equality.intAnswer the length of the field described by the receivergetCobolString(byte[] bytes) Return a String from the given byte array buffer, at the offset of this field, trimming only EBCDIC_SPACE (0x40).getCobolString(byte[] bytes, int bufOffset) Return a String from the given byte array buffer, at the bufOffset + offset of this field, trimming only EBCDIC_SPACE (0x40).Return the configured (EBCDIC variant) encoding for this field.intAnswer the offset of this field into some array of bytesgetString(byte[] bytes) Return a String from the given byte array buffer, at the offset of this field.getString(byte[] bytes, int bufOffset) Return a String from the given byte array buffer, at the bufOffset + offset of this field.booleanbooleanbooleanisTrim()static StringmakeString(int len, char ch) A static helper method which answers a new String of a given size and filled with a given character.voidPut a String into the given byte array buffer, at the offset of this field.voidPut a String into the given byte array buffer, at the bufOffset + offset of this field.voidsetAllowTruncation(boolean allowTruncation) Set whether or not to allow truncation of String values larger than the underlying byte length.voidsetByteLength(int len) Sets the byte length of the fieldvoidsetEncoding(String encoding) Set the (EBCDIC variant) encoding for this field.voidsetOffset(int offset) voidsetPadLeft(boolean padLeft) Set to true if the field will right-justify String values that are shorter than the underlying field length.voidsetTrim(boolean trim) Set to true if the String value obtained from the underlying byte array are to be blank trimmed.
-
Field Details
-
HIGH_VALUE
public static final char HIGH_VALUEThe Unicode character that translates to EBCDIC 0xFF using Cp1047- See Also:
-
DEFAULT_ENCODING
- See Also:
-
-
Constructor Details
-
StringField
public StringField(int offset, int length) Construct an instance with trim=true, padLeft=false, and allowTruncation=true.- Parameters:
offset- int the offset in some byte array to the start of this fieldlength- int the size of the field in bytes
-
StringField
public StringField(int offset, int length, boolean trim) Construct an instance with padLeft=false and allowTruncation=true.- Parameters:
offset- int the offset in some byte array to the start of this fieldlength- int the size of the field in bytestrim- true if the String returned from the underlying byte array is to be trimmed of leading (padLeft == true) or trailing (padLeft == false) blanks.
-
StringField
public StringField(int offset, int length, boolean trim, boolean padLeft) Construct an instance with allowTruncation=true.- Parameters:
offset- int the offset in some byte array to the start of this fieldlength- int the size of the field in bytestrim- true if the String returned from the underlying byte array is to be trimmed of leading (padLeft == true) or trailing (padLeft == false) blanks.padLeft- true if small values are to be left padded with blanks
-
StringField
public StringField(int offset, int length, boolean trim, boolean padLeft, boolean allowTruncation) Construct an instance.- Parameters:
offset- int the offset in some byte array to the start of this fieldlength- int the size of the field in bytestrim- true if the String returned from the underlying byte array is to be trimmed of leading (padLeft == true) or trailing (padLeft == false) blanks.padLeft- true if small values are to be left padded with blanksallowTruncation- true if large Strings are to be right-truncated. If false an IllegalArgumentException will be thrown.
-
StringField
public StringField(int offset, int length, boolean trim, boolean padLeft, boolean allowTruncation, String encoding) Construct an instance.- Parameters:
offset- int the offset in some byte array to the start of this fieldlength- int the size of the field in bytestrim- true if the String returned from the underlying byte array is to be trimmed of leading (padLeft == true) or trailing (padLeft == false) blanks.padLeft- true if small values are to be left padded with blanksallowTruncation- true if large Strings are to be right-truncated. If false an IllegalArgumentException will be thrown.encoding- the character set encoding. This is assumed to be an EBCDIC variant.
-
-
Method Details
-
makeString
A static helper method which answers a new String of a given size and filled with a given character.- Parameters:
len- the length of the String to createch- the character which will fill the String
-
getByteLength
public int getByteLength()Description copied from interface:FieldAnswer the length of the field described by the receiver- Specified by:
getByteLengthin interfaceField- Returns:
- int
- See Also:
-
setByteLength
public void setByteLength(int len) Sets the byte length of the field -
getOffset
public int getOffset()Description copied from interface:FieldAnswer the offset of this field into some array of bytes -
setOffset
public void setOffset(int offset) -
getString
Return a String from the given byte array buffer, at the offset of this field.- Parameters:
bytes- the byte array- Returns:
- String
-
getString
Return a String from the given byte array buffer, at the bufOffset + offset of this field.- Parameters:
bytes- the byte arraybufOffset- the additional offset into the byte array- Returns:
- String
-
getCobolString
Return a String from the given byte array buffer, at the offset of this field, trimming only EBCDIC_SPACE (0x40).- Parameters:
bytes- the byte array- Returns:
- String
-
getCobolString
Return a String from the given byte array buffer, at the bufOffset + offset of this field, trimming only EBCDIC_SPACE (0x40).- Parameters:
bytes- the byte arraybufOffset- the additional offset into the byte array- Returns:
- String
-
putString
Put a String into the given byte array buffer, at the offset of this field.- Parameters:
string- the String valuebytes- the byte array- Throws:
IllegalArgumentException- if the String value is too long to fit into the buffer and allowTruncation == false.RuntimeException- if the configured encoding is not supported
-
putString
Put a String into the given byte array buffer, at the bufOffset + offset of this field.- Parameters:
string- the String valuebytes- the byte arraybufOffset- the additional offset into the byte array- Throws:
IllegalArgumentException- if the String value is too long to fit into the buffer and allowTruncation == false.RuntimeException- if the configured encoding is not supported
-
getEncoding
Return the configured (EBCDIC variant) encoding for this field. If the field encoding is null, check to see if the jzos.fields.string.encoding property is set. If not, use the default encoding (Cp1047).- Returns:
- String encoding
-
setEncoding
Set the (EBCDIC variant) encoding for this field.- Parameters:
encoding- the EBCDIC encoding
-
isAllowTruncation
public boolean isAllowTruncation()- Returns:
- true if this field allows truncation of String values larger than the underlying byte length.
-
setAllowTruncation
public void setAllowTruncation(boolean allowTruncation) Set whether or not to allow truncation of String values larger than the underlying byte length. If set to false and an oversized String is supplied, an IllegalArgumentException will be thrown. If true, the String will be right-truncated to fit.- Parameters:
allowTruncation-
-
isPadLeft
public boolean isPadLeft()- Returns:
- true if the field will right-justify String values that are shorter than the underlying field length.
-
setPadLeft
public void setPadLeft(boolean padLeft) Set to true if the field will right-justify String values that are shorter than the underlying field length. If false, short String values are left justfied. -
isTrim
public boolean isTrim()- Returns:
- true if the String value obtained from the underlying byte array is blank trimmed. The trimming will occur on the left if padLeft == true, otherwise the trimming will occur on the right.
-
setTrim
public void setTrim(boolean trim) Set to true if the String value obtained from the underlying byte array are to be blank trimmed. The trimming will occur on the left if padLeft == true, otherwise the trimming will occur on the right. -
equals
Compare two Strings, possible null, for equality.- Parameters:
aString1-aString2-- Returns:
- boolean true if equal, false otherwise
-