cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

JavaMapping: Convert String to OutputStream?

Former Member
0 Likes
958

Hi everybody,

how can I convert a String to OutputStream?

Thanks, Regards Mario

Accepted Solutions (0)

Answers (3)

Answers (3)

GabrielSagaya
Active Contributor

You have to convert String to OutputStream by means of using getBytes() method..

See the example

public void execute(InputStream inputstream, OutputStream outputstream) throws StreamTransformationException {

outputstream.write("<?xml version = '1.0' encoding = 'utf-8'>".getBytes());

outputstream.write(<ns0:outputinfo ns0=\urn:xyz\File_File\>".getBytes());

String newline=null;

BufferedReader br = new BufferedReader(new InputStreamReader(inputstream));

StringBuffer sb = new StringBuffer();

while(newline = br.readLine())!=null)

{

String empno=null;

String empname=null;

String native=null;

char[] chr = new char[100];

chr = newline.toCharArray();

String[] data = new String[10];

int a = 0;

int b = 2;

for(int i=0;i<newline.length(); i++)

{

if(chr<i>==',')

{

data[a]=newline.substring(b,i);

a=a+1;

b=i+1; }

empno=data[0];

empname=data[1];

native=data[2];

outputstream.write("<Data>".getBytes());

outputstream.write("<Record>".getBytes());

outputstream.write(("<EmpNo>"empno"</Empno>").getBytes());

outputstream.write(("<EmpName>"empname"</Empname>").getBytes());

outputstream.write(("<Native>"native"</Native>").getBytes());

outputstream.write(("</Record>".getBytes());

outputstream.write("</Data>".getBytes());

}

outputstream.write("</ns0:outputinfo>".getBytes());

}

br.close();

inputstream.close();

outputstream.close();

}

Former Member
Former Member
0 Likes

hi

check this thread

regards

krishna