// returns the stream of final pig script to be passed to Grunt
private static BufferedReader runParamPreprocessor(BufferedReader origPigScript, ArrayList<String> params,
ArrayList<String> paramFiles, String scriptFile, boolean createFile)
throws org.apache.pig.tools.parameters.ParseException, IOException{
ParameterSubstitutionPreprocessor psp = new ParameterSubstitutionPreprocessor(50);
String[] type1 = new String[1];
String[] type2 = new String[1];
if (createFile){
BufferedWriter fw = new BufferedWriter(new FileWriter(scriptFile));
psp.genSubstitutedFile (origPigScript, fw, params.size() > 0 ? params.toArray(type1) : null,
paramFiles.size() > 0 ? paramFiles.toArray(type2) : null);
return new BufferedReader(new FileReader (scriptFile));
} else {
StringWriter writer = new StringWriter();
psp.genSubstitutedFile (origPigScript, writer, params.size() > 0 ? params.toArray(type1) : null,
paramFiles.size() > 0 ? paramFiles.toArray(type2) : null);
return new BufferedReader(new StringReader(writer.toString()));
}
}