KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > sp > jedit > bufferio > BufferAutosaveRequest


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
23 package org.gjt.sp.jedit.bufferio;
24
25 //{{{ Imports
26
import java.io.*;
27 import org.gjt.sp.jedit.io.*;
28 import org.gjt.sp.jedit.*;
29 import org.gjt.sp.util.*;
30 //}}}
31

32 /**
33  * A buffer autosave request.
34  * @author Slava Pestov
35  * @version $Id: BufferAutosaveRequest.java 8133 2006-11-25 19:50:58Z ezust $
36  */

37 public 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 JavaDoc session, VFS vfs, String JavaDoc 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 JavaDoc[] 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 JavaDoc e)
85             {
86             }
87             //finally
88
//{
89
//buffer.readUnlock();
90
//}
91
}
92         catch(WorkThread.Abort a)
93         {
94         }
95         finally
96         {
97             IOUtilities.closeQuietly(out);
98         }
99     } //}}}
100
}
101
Popular Tags