PageRenderTime 80ms CodeModel.GetById 76ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/org/gjt/sp/jedit/buffer/BufferAutosaveRequest.java

#
Java | 97 lines | 41 code | 10 blank | 46 comment | 3 complexity | 9a14d16b04061ffc29f68ac7123991de MD5 | raw file
 1/*
 2 * BufferAutosaveRequest.java - I/O request
 3 * :tabSize=8:indentSize=8:noTabs=false:
 4 * :folding=explicit:collapseFolds=1:
 5 *
 6 * Copyright (C) 2000, 2005 Slava Pestov
 7 *
 8 * This program is free software; you can redistribute it and/or
 9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21 */
22
23package org.gjt.sp.jedit.buffer;
24
25//{{{ Imports
26import java.io.*;
27import org.gjt.sp.jedit.io.*;
28import org.gjt.sp.jedit.*;
29import org.gjt.sp.util.*;
30//}}}
31
32/**
33 * A buffer autosave request.
34 * @author Slava Pestov
35 * @version $Id: BufferAutosaveRequest.java 5486 2006-06-23 22:31:58Z kpouer $
36 */
37public class BufferAutosaveRequest extends BufferIORequest
38{
39	//{{{ BufferAutosaveRequest constructor
40	/**
41	 * Creates a new buffer I/O request.
42	 * @param view The view
43	 * @param buffer The buffer
44	 * @param session The VFS session
45	 * @param vfs The VFS
46	 * @param path The path
47	 */
48	public BufferAutosaveRequest(View view, Buffer buffer,
49		Object session, VFS vfs, String path)
50	{
51		super(view,buffer,session,vfs,path);
52	} //}}}
53
54	//{{{ run() method
55	public void run()
56	{
57		OutputStream out = null;
58
59		try
60		{
61			String[] args = { vfs.getFileName(path) };
62			setStatus(jEdit.getProperty("vfs.status.autosave",args));
63
64			// the entire save operation can be aborted...
65			setAbortable(true);
66
67			try
68			{
69				//buffer.readLock();
70
71				if(!buffer.isDirty())
72				{
73					// buffer has been saved while we
74					// were waiting.
75					return;
76				}
77
78				out = vfs._createOutputStream(session,path,view);
79				if(out == null)
80					return;
81
82				write(buffer,out);
83			}
84			catch(Exception e)
85			{
86			}
87			//finally
88			//{
89				//buffer.readUnlock();
90			//}
91		}
92		catch(WorkThread.Abort a)
93		{
94			IOUtilities.closeQuietly(out);
95		}
96	} //}}}
97}