Package com.solab.iso8583
Class IsoValue<T>
- java.lang.Object
-
- com.solab.iso8583.IsoValue<T>
-
- All Implemented Interfaces:
java.lang.Cloneable
public class IsoValue<T> extends java.lang.Object implements java.lang.Cloneable
Represents a value that is stored in a field inside an ISO8583 message. It can format the value when the message is generated. Some values have a fixed length, other values require a length to be specified so that the value can be padded to the specified length. LLVAR and LLLVAR values do not need a length specification because the length is calculated from the stored value.
-
-
Constructor Summary
Constructors Constructor Description IsoValue(IsoType t, T value)
IsoValue(IsoType t, T val, int len)
IsoValue(IsoType t, T val, int len, boolean hexa)
IsoValue(IsoType t, T val, int len, boolean hexa, CustomFieldEncoder<T> custom)
Creates a new instance that stores the specified value as the specified type.IsoValue(IsoType t, T val, int len, CustomFieldEncoder<T> custom)
IsoValue(IsoType t, T value, CustomFieldEncoder<T> custom)
Creates a new instance that stores the specified value as the specified type.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description IsoValue<T>
clone()
Returns a copy of the receiver that references the same value object.boolean
equals(java.lang.Object other)
Returns true of the other object is also an IsoValue and has the same type and length, and if other.getValue().equals(getValue()) returns true.java.lang.String
getCharacterEncoding()
CustomFieldEncoder<T>
getEncoder()
Returns the CustomFieldEncoder for this value.int
getLength()
Returns the length of the stored value, of the length of the formatted value in case of NUMERIC or ALPHA.java.util.TimeZone
getTimeZone()
IsoType
getType()
Returns the ISO type to which the value must be formatted.T
getValue()
Returns the stored value without any conversion or formatting.int
hashCode()
void
setCharacterEncoding(java.lang.String value)
void
setTimeZone(java.util.TimeZone value)
Sets the timezone, useful for date fields.java.lang.String
toString()
Returns the formatted value as a String.void
write(java.io.OutputStream outs, boolean binary, boolean forceStringEncoding)
void
write(java.io.OutputStream outs, boolean binary, boolean forceStringEncoding, boolean forceHexadecimalLength)
Writes the formatted value to a stream, with the length header if it's a variable length type.protected void
writeLengthHeader(int l, java.io.OutputStream outs, IsoType type, boolean binary, boolean forceStringEncoding, boolean forceHexadecimalLength)
-
-
-
Constructor Detail
-
IsoValue
public IsoValue(IsoType t, T value, CustomFieldEncoder<T> custom)
Creates a new instance that stores the specified value as the specified type. Useful for storing LLVAR or LLLVAR types, as well as fixed-length value types like DATE10, DATE4, AMOUNT, etc.- Parameters:
t
- the ISO type.value
- The value to be stored.custom
- An optional CustomFieldEncoder for the value.
-
IsoValue
public IsoValue(IsoType t, T val, int len, CustomFieldEncoder<T> custom)
-
IsoValue
public IsoValue(IsoType t, T val, int len, boolean hexa, CustomFieldEncoder<T> custom)
Creates a new instance that stores the specified value as the specified type. Useful for storing fixed-length value types.- Parameters:
t
- The ISO8583 type for this field.val
- The value to store in the field.len
- The length for the value.hexa
- Flag if length is encoded as hexadecimal valuecustom
- An optional CustomFieldEncoder for the value.
-
-
Method Detail
-
getType
public IsoType getType()
Returns the ISO type to which the value must be formatted.
-
getLength
public int getLength()
Returns the length of the stored value, of the length of the formatted value in case of NUMERIC or ALPHA. It doesn't include the field length header in case of LLVAR or LLLVAR.
-
getValue
public T getValue()
Returns the stored value without any conversion or formatting.
-
setCharacterEncoding
public void setCharacterEncoding(java.lang.String value)
-
getCharacterEncoding
public java.lang.String getCharacterEncoding()
-
setTimeZone
public void setTimeZone(java.util.TimeZone value)
Sets the timezone, useful for date fields.
-
getTimeZone
public java.util.TimeZone getTimeZone()
-
toString
public java.lang.String toString()
Returns the formatted value as a String. The formatting depends on the type of the receiver.- Overrides:
toString
in classjava.lang.Object
-
clone
public IsoValue<T> clone()
Returns a copy of the receiver that references the same value object.- Overrides:
clone
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object other)
Returns true of the other object is also an IsoValue and has the same type and length, and if other.getValue().equals(getValue()) returns true.- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
getEncoder
public CustomFieldEncoder<T> getEncoder()
Returns the CustomFieldEncoder for this value.
-
writeLengthHeader
protected void writeLengthHeader(int l, java.io.OutputStream outs, IsoType type, boolean binary, boolean forceStringEncoding, boolean forceHexadecimalLength) throws java.io.IOException
- Throws:
java.io.IOException
-
write
public void write(java.io.OutputStream outs, boolean binary, boolean forceStringEncoding) throws java.io.IOException
- Throws:
java.io.IOException
-
write
public void write(java.io.OutputStream outs, boolean binary, boolean forceStringEncoding, boolean forceHexadecimalLength) throws java.io.IOException
Writes the formatted value to a stream, with the length header if it's a variable length type.- Parameters:
outs
- The stream to which the value will be written.binary
- Specifies whether the value should be written in binary or text format.forceStringEncoding
- When using text format, force the encoding of length headers for variable-length fields to be done with the proper character encoding. When false, the length headers are encoded as ASCII; this used to be the only behavior.- Throws:
java.io.IOException
-
-