Skip to main content
Announcements
A fresh, new look for the Data Integration & Quality forums and navigation! Read more about what's changed.
cancel
Showing results for 
Search instead for 
Did you mean: 
MStuparu-Ionica
Contributor

Decode base64 with tJava component

Hello,

Based on this thread: https://community.talend.com/s/feed/0D73p000004kDc1CAE, I try to use a tJava component to decode a base64 encoded very large text. The text looks like below:

"

77u/VVNFUk5BTUUsREVQQVJUTUVOVF9JRCxERVBBUlRNRU5UX05BTUUsRklSU1RfTkFNRSxQRVJT

T05fSUQsTEFTVF9OQU1FLEVOVEVSUFJJU0VfU1RBUlRfREFURSxBU1NJR05NRU5UX1NUQVRVUyxK

T0JfSUQsSk9CX05BTUUsTE9DQVRJT05fSUQsTE9DQVRJT05fTkFNRSxMRUdBTF9FTlRJVFlfSUQs

TEVHQUxfRU5USVRZX05BTUUsVEVSTUlOQVRJT05fREFURSxPRkZCT0FSRElOR19QVUJMSVNIX0RB

....

....

.....

....

....

....

....

....

....

....==

"

I add it as a String body in the tJava component, but I see in the code the following error messages.

1) For the first row, containing the "77u\":

a) syntax error on token "u", delete this token

b) <rest of the string, after \ character": cannot be resolved to a variable

2) Next rows, have these errors, one by one:

a) syntax error on token <string>, ; expected

b) <string> cannot be resolved to a type.

Can anyone help me and tell me what am I doing wrong.

The encoded text I got after calling an Oracle API.

Kind regards,

Mihai Stuparu

Labels (3)
1 Solution

Accepted Solutions
Anonymous
Not applicable

@Mihai Stuparu-Ionica​, you should use tJavaRow instead of tJava in your case, pass the result extracted from tExtractXMLField to body like:

String body=input_row.ColumnName;

//then, decode the body string with your Java code

output_row.columnName=yourDecodeFunction(body);

 

 

View solution in original post

8 Replies
Anonymous
Not applicable

You've not really given enough information here. We'd need to see your job layout and the code you have used.

 

Is there a way you can share a complete base64 encoded String that fails (of something that is not private and can be shared freely)?

Anonymous
Not applicable

Before calling java function to decode the string, print the string text on the console to see what you have from the API.

MStuparu-Ionica
Contributor
Author

Hello @Richard Hall​ , @Shicong Hong​ : sorry for answering late, I had an unexpected holiday week... I restarted working on this topic, I can provide you more detail: in fact, my question must be pretty simple for you, hopefully: how can I pass the string I have from the API to Java component.

 

Here it is my full block:

 

0695b00000OAwe5AAD.pngAfter I call the API I receive a XML file, I extract only the field that I need and the result must be fine (if the same string I use on an online decoder, it will give me the correct .csv file).

 

The string is something like:

"77u/VVNFUk5BTUUsREVQQVJUTUVOVF9JRCxERVBBUlRNRU5UX05BTUUsRklSU1RfTkFNRSxQRVJT

....

....

....

....

eSBNYW5hZ2VyIiwzMDAwMDAwMjAxNDY2NzIsIlNvY2lhbCBDYXNpbm8gR2FtZXMiCg==

"

 

Now, once again, I try to use the same code from here: https://community.talend.com/s/feed/0D73p000004kDc1CAE?language=en_US.

 

But I don't really know how to fill the

String body = "....." part with the result I got.

 

I'm new to Talend, just started working on it 3 weeks ago, I'm doing my best to watch videos, read the community and the documentation.

 

Thank you and once again I'm sorry for answering late, the topic still interest me a lot.

Anonymous
Not applicable

@Mihai Stuparu-Ionica​, you should use tJavaRow instead of tJava in your case, pass the result extracted from tExtractXMLField to body like:

String body=input_row.ColumnName;

//then, decode the body string with your Java code

output_row.columnName=yourDecodeFunction(body);

 

 

MStuparu-Ionica
Contributor
Author

Hello,

Sorry for bothering, I've been able to solve the problem myself, I told you am still learning.

I used a tJava_Row instead of tJava, like this. I had to replace as well the new lines.

 

String body = input_row.ns2reportBytes;

body = body.replace("\n","");

java.util.Base64.Decoder decoder = java.util.Base64.getDecoder();

byte[] buf = decoder.decode(body.getBytes(java.nio.charset.StandardCharsets.UTF_8));

String str = new String(buf, java.nio.charset.StandardCharsets.UTF_8);

System.out.println(str);

MStuparu-Ionica
Contributor
Author

Thank you, @Shicong Hong​ : this is exactly what I've done, I posted another comment.

Thank you once more.

Anonymous
Not applicable

Great, glad to hear that!

 

Regards

Shong

SK1694344715
Contributor

@Shicong Hong​ please provide steps once again to convertbase 64 to csv file,

new to talend..