KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * BufferInsertRequest.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 insert request.
34  * @author Slava Pestov
35  * @version $Id: BufferInsertRequest.java 8133 2006-11-25 19:50:58Z ezust $
36  */

37 public class BufferInsertRequest extends BufferIORequest
38 {
39     //{{{ BufferInsertRequest 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 BufferInsertRequest(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         InputStream in = null;
58         try
59         {
60             String JavaDoc[] args = { vfs.getFileName(path) };
61             setStatus(jEdit.getProperty("vfs.status.load",args));
62             setAbortable(true);
63
64             path = vfs._canonPath(session,path,view);
65
66             VFSFile entry = vfs._getFile(
67                 session,path,view);
68             long length;
69             if(entry != null)
70                 length = entry.getLength();
71             else
72                 length = 0L;
73
74             in = vfs._createInputStream(session,path,false,view);
75             if(in == null)
76                 return;
77
78             final SegmentBuffer seg = read(
79                 autodetect(in),length,true);
80
81             /* we don't do this in Buffer.insert() so that
82                we can insert multiple files at once */

83             VFSManager.runInAWTThread(new Runnable JavaDoc()
84             {
85                 public void run()
86                 {
87                     view.getTextArea().setSelectedText(
88                         seg.toString());
89                 }
90             });
91         }
92         catch(IOException io)
93         {
94             Log.log(Log.ERROR,this,io);
95             String JavaDoc[] pp = { io.toString() };
96             VFSManager.error(view,path,"ioerror.read-error",pp);
97
98             buffer.setBooleanProperty(ERROR_OCCURRED,true);
99         }
100         catch(WorkThread.Abort a)
101         {
102             buffer.setBooleanProperty(ERROR_OCCURRED,true);
103         }
104         finally
105         {
106             IOUtilities.closeQuietly(in);
107             try
108             {
109                 vfs._endVFSSession(session,view);
110             }
111             catch(IOException io)
112             {
113                 Log.log(Log.ERROR,this,io);
114                 String JavaDoc[] pp = { io.toString() };
115                 VFSManager.error(view,path,"ioerror.read-error",pp);
116
117                 buffer.setBooleanProperty(ERROR_OCCURRED,true);
118             }
119             catch(WorkThread.Abort a)
120             {
121                 buffer.setBooleanProperty(ERROR_OCCURRED,true);
122             }
123         }
124     } //}}}
125
}
126
Popular Tags