// returns the stream of final pig script to be passed to Grunt
private static BufferedReader runParamPreprocessor(PigContext context, BufferedReader origPigScript,
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, context.getParams().size() > 0 ? context.getParams().toArray(type1) : null,
context.getParamFiles().size() > 0 ? context.getParamFiles().toArray(type2) : null);
return new BufferedReader(new FileReader (scriptFile));
} else {
StringWriter writer = new StringWriter();
psp.genSubstitutedFile (origPigScript, writer, context.getParams().size() > 0 ? context.getParams().toArray(type1) : null,
context.getParamFiles().size() > 0 ? context.getParamFiles().toArray(type2) : null);
return new BufferedReader(new StringReader(writer.toString()));
}
}