Last active
December 16, 2015 07:31
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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