Code example for FileWriter

Methods: closeflushwrite, write

0
		this.developmentMode = developmentMode;
	} 
 
	private void openFileLogIfPossible() { 
		try { 
			fileLog = new FileWriter(new File(this.projectLocation, "log.roo"), true);
			// first write, so let's record the date and time of the first user 
			// command 
			fileLog.write("// Spring Roo " + versionInfo() + " log opened at " + df.format(new Date()) + "\n");
			fileLog.flush();
		} 
		catch (IOException ignoreIt) {
		} 
	} 
 
	protected void activate(ComponentContext context) {
		this.context = context;
	} 
 
	protected void deactivate(ComponentContext context) {
		close(); 
		this.context = null;
	} 
 
	@Override 
	protected boolean executeScriptLine(String line) {
		if (line != null && line.startsWith("project")) {
			return true; 
		} 
		return super.executeScriptLine(line);
	} 
	 
	@Override 
	protected Collection<URL> findResources(String path) {
		return OSGiUtils.findEntriesByPath(context.getBundleContext(), OSGiUtils.ROOT_PATH + path);
	} 
 
	@Override 
	protected ExecutionStrategy getExecutionStrategy() { 
		return executionStrategy;
	} 
 
	@Override 
	protected String getHomeAsString() {
		return this.rooHome;
	} 
 
	@Override 
	protected Parser getParser() {
		return parser;
	} 
 
	@Override 
	protected void logCommandToOutput(String processedLine) {
		if (fileLog == null) {
			openFileLogIfPossible(); 
			if (fileLog == null) {
				// still failing, so give up 
				return; 
			} 
		} 
		try { 
			fileLog.write(processedLine + "\n"); // unix line endings only from
			// Roo 
			fileLog.flush(); // so tail -f will show it's working
			if (getExitShellRequest() != null) { 
				// shutting down, so close our file (we can always reopen it 
				// later if needed) 
				fileLog.write("// Spring Roo " + versionInfo() + " log closed at " + df.format(new Date()) + "\n");
				fileLog.flush();
				fileLog.close();
				fileLog = null;
			} 
		} 
		catch (IOException ignoreIt) {
		}