001: /*
002: * BufferAutosaveRequest.java - I/O request
003: * :tabSize=8:indentSize=8:noTabs=false:
004: * :folding=explicit:collapseFolds=1:
005: *
006: * Copyright (C) 2000, 2005 Slava Pestov
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public License
010: * as published by the Free Software Foundation; either version 2
011: * of the License, or any later version.
012: *
013: * This program is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
021: */
022:
023: package org.gjt.sp.jedit.bufferio;
024:
025: //{{{ Imports
026: import java.io.*;
027: import org.gjt.sp.jedit.io.*;
028: import org.gjt.sp.jedit.*;
029: import org.gjt.sp.util.*;
030:
031: //}}}
032:
033: /**
034: * A buffer autosave request.
035: * @author Slava Pestov
036: * @version $Id: BufferAutosaveRequest.java 10432 2007-08-23 20:55:36Z k_satoda $
037: */
038: public class BufferAutosaveRequest extends BufferIORequest {
039: //{{{ BufferAutosaveRequest constructor
040: /**
041: * Creates a new buffer I/O request.
042: * @param view The view
043: * @param buffer The buffer
044: * @param session The VFS session
045: * @param vfs The VFS
046: * @param path The path
047: */
048: public BufferAutosaveRequest(View view, Buffer buffer,
049: Object session, VFS vfs, String path) {
050: super (view, buffer, session, vfs, path);
051: } //}}}
052:
053: //{{{ run() method
054: public void run() {
055: OutputStream out = null;
056:
057: try {
058: String[] args = { vfs.getFileName(path) };
059: setStatus(jEdit.getProperty("vfs.status.autosave", args));
060:
061: // the entire save operation can be aborted...
062: setAbortable(true);
063:
064: try {
065: //buffer.readLock();
066:
067: if (!buffer.isDirty()) {
068: // buffer has been saved while we
069: // were waiting.
070: return;
071: }
072:
073: out = vfs._createOutputStream(session, path, view);
074: if (out == null)
075: return;
076:
077: write(buffer, out);
078: } catch (Exception e) {
079: Log.log(Log.ERROR, this , e);
080: String[] pp = { e.toString() };
081: VFSManager.error(view, path, "ioerror.write-error", pp);
082:
083: // Incomplete autosave file should not exist.
084: if (out != null) {
085: try {
086: out.close();
087: out = null;
088: vfs._delete(session, path, view);
089: } catch (IOException ioe) {
090: Log.log(Log.ERROR, this , ioe);
091: }
092: }
093: }
094: //finally
095: //{
096: //buffer.readUnlock();
097: //}
098: } catch (WorkThread.Abort a) {
099: } finally {
100: IOUtilities.closeQuietly(out);
101: }
102: } //}}}
103: }
|