use of org.jaggeryjs.hostobjects.file.FileHostObject in project jaggery by wso2.
the class FeedHostObject method jsFunction_writeTo.
public static Scriptable jsFunction_writeTo(Context cx, Scriptable thisObj, Object[] arguments, Function funObj) throws ScriptException {
FeedHostObject feedObject = (FeedHostObject) thisObj;
FileHostObject fileHostObject;
OutputStreamWriter outputStreamWriter = null;
try {
if (arguments[0] instanceof String) {
fileHostObject = (FileHostObject) cx.newObject(feedObject, "File", arguments);
outputStreamWriter = new OutputStreamWriter(fileHostObject.getOutputStream());
feedObject.feed.writeTo(outputStreamWriter);
outputStreamWriter.flush();
} else if (arguments[0] instanceof FileHostObject) {
fileHostObject = (FileHostObject) arguments[0];
outputStreamWriter = new OutputStreamWriter(fileHostObject.getOutputStream());
feedObject.feed.writeTo(outputStreamWriter);
outputStreamWriter.flush();
} else {
throw new ScriptException("Invalid parameter");
}
return feedObject;
} catch (IOException e) {
throw new ScriptException(e);
} finally {
if (outputStreamWriter != null) {
try {
outputStreamWriter.close();
} catch (IOException e) {
log.warn("Error closing the stream", e);
}
}
}
}
Aggregations