How to return byte array output from the script into the pipeline

KanikaAg15
New Altair Community Member
Hi,
I have implemented a script for decoding an xlsm file but somehow I am facing issue in using the decoded data into the next operator within a pipeline.
I have used macros to store output but it has capability of storing data in the string format.
It would be great if some alternative can be suggested.
I have implemented a script for decoding an xlsm file but somehow I am facing issue in using the decoded data into the next operator within a pipeline.
I have used macros to store output but it has capability of storing data in the string format.
It would be great if some alternative can be suggested.
Tagged:
0
Best Answer
-
Hi,I think you want to use something like this:
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.commons.codec.binary.Base64;
import com.rapidminer.operator.Operator;
import com.rapidminer.operator.OperatorDescription;
import com.rapidminer.operator.nio.file.SimpleFileObject;
String originalString = "Just a text";
byte[] decodedBytes = Base64.decodeBase64(originalString);
File tempFile = null;
try {
tempFile = File.createTempFile("rm-", ".tempFile");
tempFile.deleteOnExit();
FileOutputStream fos = new FileOutputStream(tempFile);
fos.write(decodedBytes);
fos.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
SimpleFileObject fileObject = new SimpleFileObject(tempFile);
return fileObjectThis give you a purple fileObject which can be used with any other Read operator.Best,Martin
-1
Answers
-
Hi,not sure what "decoded" is, but this is surely a tough one to do with operators. Why can't you just use Read Excel?
If this is a commercial request, please consult support.rapidminer.com so we can assign more resources.Best,Martin0 -
@MartinLiebig
thanks fore revert. we cannot raise any commerical request. My only limitation is the I have a data within byte array which I need as output from the execute script operator. If you can suggest a method around that would be a great help.0 -
What should the output be? a purple file object you can push into Read Excel or so?
0 -
@MartinLiebig I want to use the output as normal exampleset so that the attributes values can be further utilized in the further pipeline.0
-
Can you share an example?
0 -
@MartinLiebig
Please find the below script. The output that is getting stored in byte array i.e decodedByte. I need that as an output from execute operator and dont want to store the file in local repository.import java.util.Base64;
import java.io.FileOutputStream;
import java.io.IOException;
public class ExcelFromBase64 {
public static void writeExcelFromBase64(String base64) throws IOException {
byte[] decodedBytes = Base64.getDecoder().decode(base64);
FileOutputStream fos = new FileOutputStream("%{Path}");
fos.write(decodedBytes);
fos.close();
}
public static void main(String[] args) throws IOException {
String base64 = "%{base64}";
writeExcelFromBase64(base64);
}
}0 -
Hi,I think you want to use something like this:
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.commons.codec.binary.Base64;
import com.rapidminer.operator.Operator;
import com.rapidminer.operator.OperatorDescription;
import com.rapidminer.operator.nio.file.SimpleFileObject;
String originalString = "Just a text";
byte[] decodedBytes = Base64.decodeBase64(originalString);
File tempFile = null;
try {
tempFile = File.createTempFile("rm-", ".tempFile");
tempFile.deleteOnExit();
FileOutputStream fos = new FileOutputStream(tempFile);
fos.write(decodedBytes);
fos.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
SimpleFileObject fileObject = new SimpleFileObject(tempFile);
return fileObjectThis give you a purple fileObject which can be used with any other Read operator.Best,Martin
-1 -
Hi Martin, I cannot thank you enough. This really helped. A big thanks for your help.0