on 08-28-2015 7:11 AM
Hi,
I have an inbound text file (can contain any data in any format in a .txt file). This file needs to be Base64Encoded and put in the field on target XML:
<Target>
<Field>BASE64_Encoded_String</Field>
</Target>
I am using a JAVA Mapping with below related code:
import sun.misc.BASE64Encoder;
public void execute(InputStream inputstream,OutputStream outputstream) throws StreamTransformationException, SAXException, IOException {
try
{
.......some logic for other processing.....
................
BASE64Encoder encoder = new BASE64Encoder();
String encoded = ?? // What should be the logic written here to convert the inputstream into Base64
}
catch(Exception e) {
throw new StreamTransformationException(e.toString());
}
}
Can you please help me with what should be the statement that will encode the input file and put it in the variable?
Referred threads:
Thank you!
First of all, which PI version do you use? If you use PI 7.1 or later, then you will notice that sun.misc.BASE64Encoder is deprecated. You can use javax.xml.bind.DatatypeConverter instead
The logic could be like this:
byte input[] = new byte[inputstream.available()]; in.read(input); String encoded = DatatypeConverter.printBase64Binary(input); |
with sun encoder it would be:
byte input[] = new byte[inputstream.available()]; in.read(input); BASE64Encoder encoder = new BASE64Encoder(); String encoded = encoder.encode(input); |
The ouput can be done like this:
String output = "<Target><field>" + encoded + ">/Target></field>"; outputstream.write(output.getbytes()); |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for the reply!
Unfortunately i cannot use an UDF (infact cant use Message Mapping) as I do not know what will be there in the incoming file. So i prefer JAVA mapping as it can consume any stream and generate output structure as required.
I used the above statement earlier in the JAVA mapping and it failed with below error. So i assume that the statement i am using is wrong
Hi Abhisek,
If you check your own help your need to set an OutputStream variable. Later, you can convert it to String if you want: http://stackoverflow.com/questions/216894/get-an-outputstream-into-a-string
Regards.
Abhishek,
do you want encode only perticular field then i would suggest to go for UDF , watever data comes from source, it will encode that data.
if you want encode everything data which you need to send to receiver then,, why dont you go for custome module , there is code vailable in below link..which u also posted in first post
also while do use that code , you suppose to be used jars related to that code.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.