1 22 23 package org.gjt.sp.jedit.bufferio; 24 25 import java.io.*; 27 import java.nio.charset.*; 28 import org.gjt.sp.jedit.io.*; 29 import org.gjt.sp.jedit.*; 30 import org.gjt.sp.jedit.buffer.JEditBuffer; 31 import org.gjt.sp.util.*; 32 34 39 public class BufferLoadRequest extends BufferIORequest 40 { 41 50 public BufferLoadRequest(View view, Buffer buffer, 51 Object session, VFS vfs, String path) 52 { 53 super(view,buffer,session,vfs,path); 54 } 56 public void run() 58 { 59 try 60 { 61 InputStream contents = null; 62 try 63 { 64 String [] args = { vfs.getFileName(path) }; 65 setAbortable(true); 66 if(!buffer.isTemporary()) 67 { 68 setStatus(jEdit.getProperty("vfs.status.load",args)); 69 setValue(0L); 70 } 71 72 path = vfs._canonPath(session,path,view); 73 74 VFSFile entry = vfs._getFile( 75 session,path,view); 76 long length; 77 if(entry != null) 78 length = entry.getLength(); 79 else 80 length = 0L; 81 82 contents = vfs._createInputStream(session,path, 83 false,view); 84 if(contents == null) 85 { 86 buffer.setBooleanProperty(ERROR_OCCURRED,true); 87 return; 88 } 89 90 read(autodetect(contents),length,false); 91 buffer.setNewFile(false); 92 } 93 catch(CharConversionException e) 94 { 95 handleEncodingError(e); 96 } 97 catch(CharacterCodingException e) 98 { 99 handleEncodingError(e); 100 } 101 catch(UnsupportedEncodingException e) 102 { 103 handleEncodingError(e); 104 } 105 catch(UnsupportedCharsetException e) 106 { 107 handleEncodingError(e); 108 } 109 catch(IOException io) 110 { 111 Log.log(Log.ERROR,this,io); 112 Object [] pp = { io.toString() }; 113 VFSManager.error(view,path,"ioerror.read-error",pp); 114 115 buffer.setBooleanProperty(ERROR_OCCURRED,true); 116 } 117 catch(OutOfMemoryError oom) 118 { 119 Log.log(Log.ERROR,this,oom); 120 VFSManager.error(view,path,"out-of-memory-error",null); 121 122 buffer.setBooleanProperty(ERROR_OCCURRED,true); 123 } 124 finally 125 { 126 IOUtilities.closeQuietly(contents); 127 } 128 129 if(jEdit.getBooleanProperty("persistentMarkers")) 130 { 131 InputStream markers = null; 132 try 133 { 134 String [] args = { vfs.getFileName(path) }; 135 if(!buffer.isTemporary()) 136 setStatus(jEdit.getProperty("vfs.status.load-markers",args)); 137 setAbortable(true); 138 139 markers = vfs._createInputStream(session,markersPath,true,view); 140 if(markers != null) 141 readMarkers(buffer,markers); 142 } 143 catch(IOException io) 144 { 145 } 147 finally 148 { 149 IOUtilities.closeQuietly(markers); 150 } 151 } 152 } 153 catch(WorkThread.Abort a) 154 { 155 buffer.setBooleanProperty(ERROR_OCCURRED,true); 156 } 157 finally 158 { 159 try 160 { 161 vfs._endVFSSession(session,view); 162 } 163 catch(IOException io) 164 { 165 Log.log(Log.ERROR,this,io); 166 String [] pp = { io.toString() }; 167 VFSManager.error(view,path,"ioerror.read-error",pp); 168 169 buffer.setBooleanProperty(ERROR_OCCURRED,true); 170 } 171 catch(WorkThread.Abort a) 172 { 173 buffer.setBooleanProperty(ERROR_OCCURRED,true); 174 } 175 } 176 } 178 private void handleEncodingError(Exception e) 180 { 181 Log.log(Log.ERROR,this,e); 182 Object [] pp = { buffer.getProperty(JEditBuffer.ENCODING), 183 e.toString() }; 184 VFSManager.error(view,path,"ioerror.encoding-error",pp); 185 186 buffer.setBooleanProperty(ERROR_OCCURRED,true); 187 } 189 private static void readMarkers(Buffer buffer, InputStream _in) 191 throws IOException 192 { 193 buffer.removeAllMarkers(); 195 196 BufferedReader in = new BufferedReader(new InputStreamReader(_in)); 197 198 try 199 { 200 String line; 201 while((line = in.readLine()) != null) 202 { 203 if(line.length() == 0) 205 continue; 206 207 if(line.charAt(0) != '!') 209 continue; 210 211 212 char shortcut = line.charAt(1); 213 int start = line.indexOf(';'); 214 int end = line.indexOf(';',start + 1); 215 int position = Integer.parseInt(line.substring(start + 1,end)); 216 buffer.addMarker(shortcut,position); 217 } 218 buffer.setMarkersChanged(false); 219 } 220 finally 221 { 222 in.close(); 223 } 224 } } 226 | Popular Tags |