Skip to content

Instantly share code, notes, and snippets.

@SriniBlog
Last active December 16, 2015 07:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SriniBlog/113039b6f0433bee19ae to your computer and use it in GitHub Desktop.
Save SriniBlog/113039b6f0433bee19ae to your computer and use it in GitHub Desktop.
Read file from InputStream in different ways in SAP PI using Java Mapping. Snippets of code(s)
/*
* DIFFERENT WAYS TO READ & WRITE FILE USING JAVA MAPPING (PI)
* CODE SNIPPETS - CHOOSE ANY ONE WAY TO READ FILE
*/
public void transform(TransformationInput arg0, TransformationOutput arg1) throws StreamTransformationException
{
try{
InputStream in = (InputStream) arg0.getInputPayload().getInputStream();
OutputStream out = (OutputStream) arg1.getOutputPayload().getOutputStream();
//CODE SNIPPET 1
int buffer;
while ((buffer = in.read()) != -1)
{
out.write(buffer);
}
out.flush();
//CODE SNIPPET 2
BufferedReader docInput = new BufferedReader(new InputStreamReader(in));
String inputLine = "";
while ((inputLine = docInput.readLine()) != null) {
sourcePayload.append(inputLine);
}
out.write(new String(sourcePayload).getBytes("UTF-8"));
//CODE SNIPPET 3
byte[] bytes = new byte[in.available()];
in.read(bytes);
out.write(bytes);
}catch (Exception ee){
throw new StreamTransformationException("Issue in message parsing".concat(e.getMessage()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment