0

I have ISO packaged file contains all its records on single line. File contents like MTI1XXXXXXMTI2XXXXMTI1XXXXX So here total 3 rows which are on single line.

ISOMsg isoMsg = new ISOMsg(); 
isoMsg.setPackager(packager); 
isoMsg.unpack(filedata);`

isoMsg only able to unpack first record MTI1XXXXXX

Here MTI1, MTI2, MTI3 are Message Type Indicator (MTI) which is of 4 digits.

If I separate those records(3 lines) in file and read line by line like below

MTI1XXXXXX
MTI2XXXX
MTI1XXXXX

It returns me all the records. Is there any way to read all records which are on single line using JPOS ISO8583 packager or with generic packager?

adding my sample code snippet:

InputStream lis = null;
    try {
        GenericPackager packager;
        packager = new GenericPackager("src/main/resources/BitMapConfig.xml");
        lis = new FileInputStream("src/test/resources/isoTestFile");
        ISOMsg isoMsg = new ISOMsg();
        isoMsg.setPackager(packager);
        isoMsg.unpack(lis);
        ISOBitMap bitmap = (ISOBitMap) isoMsg.getComponent(-1);
        System.out.println("bitmap.getValue::" + bitmap.getValue()); //returns only first records bitmap whoever file contains 3 MTI on single line
    } catch (Exception e) {
        e.printStackTrace();
    } 

I want to read all of those and separate those in different files.

Andrés Alcarraz
  • 1,570
  • 1
  • 12
  • 21
Krishna
  • 1
  • 5

1 Answers1

0

You can try something like this:

InputStream lis = null;
    try {
        GenericPackager packager;
        packager = new GenericPackager("src/main/resources/BitMapConfig.xml");
        lis = new FileInputStream("src/test/resources/isoTestFile");
        while (true) {
            ISOMsg isoMsg = new ISOMsg();
            isoMsg.setPackager(packager);
            isoMsg.unpack(lis);
            ISOBitMap bitmap = (ISOBitMap) isoMsg.getComponent(-1);
            System.out.println("bitmap.getValue::" + bitmap.getValue()); 
            //or isoMsg.dump(System.out,"");
        }
    } catch (EOFException e) {
        //assume we just ended the stream
    } catch (Exception e) {
        e.printStackTrace();
    } 


Andrés Alcarraz
  • 1,570
  • 1
  • 12
  • 21
  • This I already tried :) it returns only the first record only :( it is a case like JPos API ignores the next MTI which found on same line. – Krishna Jun 07 '19 at 22:03
  • Can you put the exact code you already tried? jpos api itself does not ignore anything. Is up to you to read the next bytes, which this answer does It reads one message, and then pass the next message will parse starting where the previous ended. Notice this is using input stream not file content. – Andrés Alcarraz Jun 07 '19 at 23:02
  • Hi Andres, I have attached the snippet in description – Krishna Jun 08 '19 at 11:42
  • you don't have the while there, you are just reading the firrst message from the input stream, you need to continue reading, thats the purpose of the while in this answer – Andrés Alcarraz Jun 08 '19 at 14:34
  • I've just modified my answer to include a modification of the code you provided, with the while in place – Andrés Alcarraz Jun 08 '19 at 15:47
  • Hi Andres, this will work but Available Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking. So this method could return 0 in the middle of the file – Krishna Jun 12 '19 at 14:04
  • @Krishna I know, this is just an example, other option is keep reading until EOFException, I just modified the answer to do that – Andrés Alcarraz Jun 13 '19 at 00:53