cancel
Showing results for 
Search instead for 
Did you mean: 

How to read inputstream twice in XI java mapping?

Former Member
0 Kudos

Hi,

I need to read input stream twice in my javamapping , it thowing null exeption.

SO please guid me with psedo code , to read input stream twice in java mapping xi.

Regards

Krishna

Accepted Solutions (0)

Answers (3)

Answers (3)

former_member181985
Active Contributor
0 Kudos

Hi,

try this snippet

public void execute(InputStream inputstream, OutputStream outputstream)
    {
			int len = 0;
			int BUFFER = 2048;
			byte buf[] = new byte[BUFFER];

			try
			{
				ByteArrayOutputStream byteArrayOut1 = new ByteArrayOutputStream();
				ByteArrayOutputStream byteArrayOut2 = new ByteArrayOutputStream();

				while ((len = inputstream.read(buf)) != -1)
					{
						byteArrayOut1.write(buf, 0, len);
						byteArrayOut2.write(buf, 0, len);
					}				
				excuteNew(byteArrayOut1.toByteArray(), byteArrayOut2.toByteArray(), outputstream);
			}
			catch (Exception e)
			{
				e.printStackTrace();
			}

    }

	public OutputStream excuteNew(byte[] is1, byte[] is2, OutputStream os)
	{				
				ByteArrayInputStream byteArrayInput1 = new ByteArrayInputStream(is1);
				ByteArrayInputStream byteArrayInput2 = new ByteArrayInputStream(is2);
				//YOUR CODE
	}

Former Member
0 Kudos

Thanks with the above code we are able to succeed.

former_member181985
Active Contributor
0 Kudos

Try this as well, instead of two copies:

BufferedInputStream bis = new BufferedInputStream(inputstream);//Wrapper
bis.mark(0);
//FIRST TIME: read input stream(bis) & YOUR LOGIC
bis.reset(); //Reset stream
//SECOND TIME: read input stream(bis) & YOUR LOGIC

Lets know the outcome......

Regards,

Praveen Gujjeti

rajasekhar_reddy14
Active Contributor
0 Kudos

He,

one thing we can do this,,

tell me your requirement and i will help you.

Regards,

Raj

Former Member
0 Kudos

I need to read the payload and accordingly write the label in the header area

Former Member
0 Kudos

Hi Krishna,

I think its not possible to do it, i also tried before and could not achieve.

There is a work around.

Why cannot u store the details of incoming payload in ArrayList or Array of Strings, and reuse them, where ever u want.

Babu

Former Member
0 Kudos

Hi

Can u please tell me how to do thsi store the details of incoming payload in ArrayList or Array of Strings, and reuse them, where ever u want. ???

Former Member
0 Kudos

Hi,

Go for a SAX or DOM Parser, based on ur req, and access the details u want only , and store them in the ArrayList.

Once done, now u have all the contents in the ArrayList, access them, and put them where ever u want, for u in the Header.

Babu