Class MainframeInput
- java.lang.Object
-
- de.ufinke.cubaja.io.MainframeInput
-
public class MainframeInput extends Object
Reads mainframe data.Method
fillBufferreads an amount of bytes into an internal buffer. The variousreadmethods 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 voidclose()Closes the underlaying stream.booleanfillBuffer(int byteCount)Fills the internal buffer.RandomAccessBuffergetBuffer()Gives access to the internal buffer.intgetPosition()Retrieves the internal buffer's position.intgetRecordCount()Returns the record count.intgetSize()Retrieves the record size.booleannextRecord(int byteCount)Fills the internal buffer and increments record count.bytereadByte()Reads a binary signedbytevalue.byte[]readBytes(int count)Reads a raw byte array.voidreadFully(byte[] b)Fills a byte array.voidreadFully(byte[] b, int off, int len)Fills a portion of a byte array.intreadInt()Reads a binaryintvalue.longreadLong()Reads a binarylongvalue.BigDecimalreadPackedBigDecimal(int integerDigitCount, int fractionalDigitCount)Reads a packedBigDecimalvalue.doublereadPackedDouble(int integerDigitCount, int fractionalDigitCount)Reads a packeddoublevalue.intreadPackedInt(int digitCount)Reads a packedintvalue.longreadPackedLong(int digitCount)Reads a packedlongvalue.shortreadShort()Reads a binaryshortvalue.StringreadString(int charCount)Reads a string.intreadUnsignedByte()Reads a raw byte.BigDecimalreadUnsignedPackedBigDecimal(int integerDigitCount, int fractionalDigitCount)Reads an unsigned packedBigDecimalvalue.doublereadUnsignedPackedDouble(int integerDigitCount, int fractionalDigitCount)Reads an unsigned packeddoublevalue.intreadUnsignedPackedInt(int digitCount)Reads an unsigned packedintvalue.longreadUnsignedPackedLong(int digitCount)Reads an unsigned packedlongvalue.BigDecimalreadZonedBigDecimal(int integerDigitCount, int fractionalDigitCount)Reads a zonedBigDecimalvalue.doublereadZonedDouble(int integerDigitCount, int fractionalDigitCount)Reads a zoneddoublevalue.intreadZonedInt(int digitCount)Reads a zonedintvalue.longreadZonedLong(int digitCount)Reads a zonedlongvalue.voidsetBuffer(RandomAccessBuffer buffer)Replaces the internal buffer.voidsetPosition(int offset)Sets the internal buffer's position.intskipBytes(int n)Advances the buffers position.
-
-
-
Constructor Detail
-
MainframeInput
public MainframeInput(InputStream stream, Charset charset) throws UnsupportedEncodingException
Constructor.The
charsetmay 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
charsetmay 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 IOExceptionCloses the underlaying stream.- Throws:
IOException- when the stream could not be closed
-
fillBuffer
public boolean fillBuffer(int byteCount) throws IOExceptionFills the internal buffer.Returns
trueif the given number of bytes could be read, orfalsewhen there where no more bytes to read. ThrowsEOFExceptionwhen the stream ends before all requested bytes were read.For fixed length records,
byteCountshould 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 IOExceptionFills 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 IOExceptionReads a raw byte.- Returns:
- value
- Throws:
IOException- when the byte could not be read from the buffer
-
readByte
public byte readByte() throws IOExceptionReads a binary signedbytevalue.- Returns:
- value
- Throws:
IOException- when the byte could not be read from the buffer
-
readShort
public short readShort() throws IOExceptionReads a binaryshortvalue.- Returns:
- value
- Throws:
IOException- when the short could not be read from the buffer
-
readInt
public int readInt() throws IOExceptionReads a binaryintvalue.- Returns:
- value
- Throws:
IOException- when the int could not be read from the buffer
-
readLong
public long readLong() throws IOExceptionReads a binarylongvalue.- 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 IOExceptionReads a zonedintvalue.- 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 IOExceptionReads a zonedlongvalue.- 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 IOExceptionReads a zoneddoublevalue.- 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 zonedBigDecimalvalue.- 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 IOExceptionReads a packedintvalue.- 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 IOExceptionReads a packedlongvalue.- 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 IOExceptionReads a packeddoublevalue.- 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 packedBigDecimalvalue.- 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 IOExceptionReads an unsigned packedintvalue.- 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 IOExceptionReads an unsigned packedlongvalue.- 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 IOExceptionReads an unsigned packeddoublevalue.- 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 packedBigDecimalvalue.- 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 IOExceptionAdvances 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 IOExceptionReads 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 IOExceptionFills 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 IOExceptionFills 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
-
-