on 08-19-2010 5:24 AM
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
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
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
He,
one thing we can do this,,
tell me your requirement and i will help you.
Regards,
Raj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.