Class MainframeInput
- java.lang.Object
-
- de.ufinke.cubaja.io.MainframeInput
-
public class MainframeInput extends Object
Reads mainframe data.Method
fillBuffer
reads an amount of bytes into an internal buffer. The variousread
methods retrieve data from the buffer. The position advances automatically.- Author:
- Uwe Finke
-
-
Constructor Summary
Constructors Constructor Description MainframeInput(InputStream stream, String charset)
Constructor.MainframeInput(InputStream stream, Charset charset)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes the underlaying stream.boolean
fillBuffer(int byteCount)
Fills the internal buffer.RandomAccessBuffer
getBuffer()
Gives access to the internal buffer.int
getPosition()
Retrieves the internal buffer's position.int
getRecordCount()
Returns the record count.int
getSize()
Retrieves the record size.boolean
nextRecord(int byteCount)
Fills the internal buffer and increments record count.byte
readByte()
Reads a binary signedbyte
value.byte[]
readBytes(int count)
Reads a raw byte array.void
readFully(byte[] b)
Fills a byte array.void
readFully(byte[] b, int off, int len)
Fills a portion of a byte array.int
readInt()
Reads a binaryint
value.long
readLong()
Reads a binarylong
value.BigDecimal
readPackedBigDecimal(int integerDigitCount, int fractionalDigitCount)
Reads a packedBigDecimal
value.double
readPackedDouble(int integerDigitCount, int fractionalDigitCount)
Reads a packeddouble
value.int
readPackedInt(int digitCount)
Reads a packedint
value.long
readPackedLong(int digitCount)
Reads a packedlong
value.short
readShort()
Reads a binaryshort
value.String
readString(int charCount)
Reads a string.int
readUnsignedByte()
Reads a raw byte.BigDecimal
readUnsignedPackedBigDecimal(int integerDigitCount, int fractionalDigitCount)
Reads an unsigned packedBigDecimal
value.double
readUnsignedPackedDouble(int integerDigitCount, int fractionalDigitCount)
Reads an unsigned packeddouble
value.int
readUnsignedPackedInt(int digitCount)
Reads an unsigned packedint
value.long
readUnsignedPackedLong(int digitCount)
Reads an unsigned packedlong
value.BigDecimal
readZonedBigDecimal(int integerDigitCount, int fractionalDigitCount)
Reads a zonedBigDecimal
value.double
readZonedDouble(int integerDigitCount, int fractionalDigitCount)
Reads a zoneddouble
value.int
readZonedInt(int digitCount)
Reads a zonedint
value.long
readZonedLong(int digitCount)
Reads a zonedlong
value.void
setBuffer(RandomAccessBuffer buffer)
Replaces the internal buffer.void
setPosition(int offset)
Sets the internal buffer's position.int
skipBytes(int n)
Advances the buffers position.
-
-
-
Constructor Detail
-
MainframeInput
public MainframeInput(InputStream stream, Charset charset) throws UnsupportedEncodingException
Constructor.The
charset
may be either a single byte or a double byte character set. Do not use a character set with a variant number of bytes for a single character (such as UTF-8)!- Parameters:
stream
- input streamcharset
- character set- Throws:
UnsupportedEncodingException
- when the character set is not supported in the runtime environment
-
MainframeInput
public MainframeInput(InputStream stream, String charset) throws UnsupportedEncodingException
Constructor.The
charset
may be either a single byte or a double byte character set. Do not use a character set with a variant number of bytes for a single character (such as UTF-8)!- Parameters:
stream
- input streamcharset
- name of character set- Throws:
UnsupportedEncodingException
- when the character set does not exist or ist not supported in the runtime environment
-
-
Method Detail
-
close
public void close() throws IOException
Closes the underlaying stream.- Throws:
IOException
- when the stream could not be closed
-
fillBuffer
public boolean fillBuffer(int byteCount) throws IOException
Fills the internal buffer.Returns
true
if the given number of bytes could be read, orfalse
when there where no more bytes to read. ThrowsEOFException
when the stream ends before all requested bytes were read.For fixed length records,
byteCount
should be the record length. For variable records, the record length must be retrieved by a separate call before the rest of the record can be read.The internal buffer position is set to
0
.- Parameters:
byteCount
- number of bytes to pass into the buffer- Returns:
- EOF flag
- Throws:
IOException
- when the number of requested bytes could not be read from the input stream
-
nextRecord
public boolean nextRecord(int byteCount) throws IOException
Fills the internal buffer and increments record count. CallsfillBuffer
.- Parameters:
byteCount
- number of bytes to pass into the buffer- Returns:
- EOF flag
- Throws:
IOException
- when the number of requested bytes could not be read from the input stream
-
getRecordCount
public int getRecordCount()
Returns the record count. The record count is incremented bynextRecord
.- Returns:
- record count
-
setPosition
public void setPosition(int offset)
Sets the internal buffer's position.- Parameters:
offset
- position within the buffer, fist byte position is 0
-
getPosition
public int getPosition()
Retrieves the internal buffer's position.- Returns:
- current position
-
getSize
public int getSize()
Retrieves the record size. This is the maximum buffer position.- Returns:
- record size
-
readUnsignedByte
public int readUnsignedByte() throws IOException
Reads a raw byte.- Returns:
- value
- Throws:
IOException
- when the byte could not be read from the buffer
-
readByte
public byte readByte() throws IOException
Reads a binary signedbyte
value.- Returns:
- value
- Throws:
IOException
- when the byte could not be read from the buffer
-
readShort
public short readShort() throws IOException
Reads a binaryshort
value.- Returns:
- value
- Throws:
IOException
- when the short could not be read from the buffer
-
readInt
public int readInt() throws IOException
Reads a binaryint
value.- Returns:
- value
- Throws:
IOException
- when the int could not be read from the buffer
-
readLong
public long readLong() throws IOException
Reads a binarylong
value.- Returns:
- value
- Throws:
IOException
- when the long could not be read from the buffer
-
readString
public String readString(int charCount) throws IOException
Reads a string.- Parameters:
charCount
- number of characters- Returns:
- value
- Throws:
IOException
- when the requested number of characters could not be read from the buffer
-
readZonedInt
public int readZonedInt(int digitCount) throws IOException
Reads a zonedint
value.- Parameters:
digitCount
- number of digits- Returns:
- value
- Throws:
IOException
- when the requested number of digits could not be read from the buffer
-
readZonedLong
public long readZonedLong(int digitCount) throws IOException
Reads a zonedlong
value.- Parameters:
digitCount
- number of digits- Returns:
- value
- Throws:
IOException
- when the requested number of digits could not be read from the buffer
-
readZonedDouble
public double readZonedDouble(int integerDigitCount, int fractionalDigitCount) throws IOException
Reads a zoneddouble
value.- Parameters:
integerDigitCount
- number of digits before imaginary decimal pointfractionalDigitCount
- number of digits after imaginary decimal point- Returns:
- value
- Throws:
IOException
- when the requested number of digits (sum of integer an fractional part) could not be read from the buffer
-
readZonedBigDecimal
public BigDecimal readZonedBigDecimal(int integerDigitCount, int fractionalDigitCount) throws IOException
Reads a zonedBigDecimal
value.- Parameters:
integerDigitCount
- number of digits before imaginary decimal pointfractionalDigitCount
- number of digits after imaginary decimal point- Returns:
- value
- Throws:
IOException
- when the requested number of digits (sum of integer an fractional part) could not be read from the buffer
-
readPackedInt
public int readPackedInt(int digitCount) throws IOException
Reads a packedint
value.- Parameters:
digitCount
- number of digits- Returns:
- value
- Throws:
IOException
- when the requested number of digits could not be read from the buffer
-
readPackedLong
public long readPackedLong(int digitCount) throws IOException
Reads a packedlong
value.- Parameters:
digitCount
- number of digits- Returns:
- value
- Throws:
IOException
- when the requested number of digits could not be read from the buffer
-
readPackedDouble
public double readPackedDouble(int integerDigitCount, int fractionalDigitCount) throws IOException
Reads a packeddouble
value.- Parameters:
integerDigitCount
- number of digits before imaginary decimal pointfractionalDigitCount
- number of digits after imaginary decimal point- Returns:
- value
- Throws:
IOException
- when the requested number of digits (integer plus fractional part) could not be read from the buffer
-
readPackedBigDecimal
public BigDecimal readPackedBigDecimal(int integerDigitCount, int fractionalDigitCount) throws IOException
Reads a packedBigDecimal
value.- Parameters:
integerDigitCount
- number of digits before imaginary decimal pointfractionalDigitCount
- number of digits after imaginary decimal point- Returns:
- value
- Throws:
IOException
- when the requested number of digits (integer plus fractional part) could not be read from the buffer
-
readUnsignedPackedInt
public int readUnsignedPackedInt(int digitCount) throws IOException
Reads an unsigned packedint
value.- Parameters:
digitCount
- number of digits- Returns:
- value
- Throws:
IOException
- when the requested number of digits could not be read from the buffer
-
readUnsignedPackedLong
public long readUnsignedPackedLong(int digitCount) throws IOException
Reads an unsigned packedlong
value.- Parameters:
digitCount
- number of digits- Returns:
- value
- Throws:
IOException
- when the requested number of digits could not be read from the buffer
-
readUnsignedPackedDouble
public double readUnsignedPackedDouble(int integerDigitCount, int fractionalDigitCount) throws IOException
Reads an unsigned packeddouble
value.- Parameters:
integerDigitCount
- number of digits before imaginary decimal pointfractionalDigitCount
- number of digits after imaginary decimal point- Returns:
- value
- Throws:
IOException
- when the requested number of digits (integer plus fractional part) could not be read from the buffer
-
readUnsignedPackedBigDecimal
public BigDecimal readUnsignedPackedBigDecimal(int integerDigitCount, int fractionalDigitCount) throws IOException
Reads an unsigned packedBigDecimal
value.- Parameters:
integerDigitCount
- number of digits before imaginary decimal pointfractionalDigitCount
- number of digits after imaginary decimal point- Returns:
- value
- Throws:
IOException
- when the requested number of digits (integer plus fractional part) could not be read from the buffer
-
skipBytes
public int skipBytes(int n) throws IOException
Advances the buffers position.- Parameters:
n
- number of bytes to skip- Returns:
- number of skipped bytes
- Throws:
IOException
- when the requested number of bytes could not be skipped
-
readBytes
public byte[] readBytes(int count) throws IOException
Reads a raw byte array.- Parameters:
count
- number of bytes to read- Returns:
- byte array
- Throws:
IOException
- when the requested number of bytes could not be read from the buffer
-
readFully
public void readFully(byte[] b) throws IOException
Fills a byte array.- Parameters:
b
- array- Throws:
IOException
- when the array could not be filled from the buffer
-
readFully
public void readFully(byte[] b, int off, int len) throws IOException
Fills a portion of a byte array.- Parameters:
b
- arrayoff
- offset in the arraylen
- number of bytes- Throws:
IOException
- when the requested number of bytes could not be read from the buffer
-
getBuffer
public RandomAccessBuffer getBuffer()
Gives access to the internal buffer. Use the buffer only if you know what you're doing.- Returns:
- the buffer
-
setBuffer
public void setBuffer(RandomAccessBuffer buffer)
Replaces the internal buffer. May be useful to share the buffer with other instances.- Parameters:
buffer
- the new buffer instance
-
-