PageRenderTime 54ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre4/org/gjt/sp/jedit/buffer/BufferIORequest.java

#
Java | 875 lines | 606 code | 108 blank | 161 comment | 102 complexity | 3bc4df5c4d243dcd5e5bea527bbffbfb MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*
  2. * BufferIORequest.java - I/O request
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2000, 2003 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. package org.gjt.sp.jedit.buffer;
  23. //{{{ Imports
  24. import javax.swing.text.Segment;
  25. import java.io.*;
  26. import java.util.zip.*;
  27. import java.util.Vector;
  28. import org.gjt.sp.jedit.io.*;
  29. import org.gjt.sp.jedit.*;
  30. import org.gjt.sp.util.*;
  31. //}}}
  32. /**
  33. * A buffer I/O request.
  34. * @author Slava Pestov
  35. * @version $Id: BufferIORequest.java 4761 2003-06-05 00:44:54Z spestov $
  36. */
  37. public class BufferIORequest extends WorkRequest
  38. {
  39. //{{{ Constants
  40. /**
  41. * Size of I/O buffers.
  42. */
  43. public static final int IOBUFSIZE = 32768;
  44. /**
  45. * Number of lines per progress increment.
  46. */
  47. public static final int PROGRESS_INTERVAL = 300;
  48. public static final String LOAD_DATA = "BufferIORequest__loadData";
  49. public static final String END_OFFSETS = "BufferIORequest__endOffsets";
  50. public static final String NEW_PATH = "BufferIORequest__newPath";
  51. /**
  52. * Buffer boolean property set when an error occurs.
  53. */
  54. public static final String ERROR_OCCURRED = "BufferIORequest__error";
  55. /**
  56. * A file load request.
  57. */
  58. public static final int LOAD = 0;
  59. /**
  60. * A file save request.
  61. */
  62. public static final int SAVE = 1;
  63. /**
  64. * An autosave request. Only supported for local files.
  65. */
  66. public static final int AUTOSAVE = 2;
  67. /**
  68. * An insert file request.
  69. */
  70. public static final int INSERT = 3;
  71. /**
  72. * Magic numbers used for auto-detecting Unicode and GZIP files.
  73. */
  74. public static final int GZIP_MAGIC_1 = 0x1f;
  75. public static final int GZIP_MAGIC_2 = 0x8b;
  76. public static final int UNICODE_MAGIC_1 = 0xfe;
  77. public static final int UNICODE_MAGIC_2 = 0xff;
  78. //}}}
  79. //{{{ BufferIORequest constructor
  80. /**
  81. * Creates a new buffer I/O request.
  82. * @param type The request type
  83. * @param view The view
  84. * @param buffer The buffer
  85. * @param session The VFS session
  86. * @param vfs The VFS
  87. * @param path The path
  88. */
  89. public BufferIORequest(int type, View view, Buffer buffer,
  90. Object session, VFS vfs, String path)
  91. {
  92. this.type = type;
  93. this.view = view;
  94. this.buffer = buffer;
  95. this.session = session;
  96. this.vfs = vfs;
  97. this.path = path;
  98. markersPath = vfs.getParentOfPath(path)
  99. + '.' + vfs.getFileName(path)
  100. + ".marks";
  101. } //}}}
  102. //{{{ run() method
  103. public void run()
  104. {
  105. switch(type)
  106. {
  107. case LOAD:
  108. load();
  109. break;
  110. case SAVE:
  111. save();
  112. break;
  113. case AUTOSAVE:
  114. autosave();
  115. break;
  116. case INSERT:
  117. insert();
  118. break;
  119. }
  120. } //}}}
  121. //{{{ toString() method
  122. public String toString()
  123. {
  124. String typeString;
  125. switch(type)
  126. {
  127. case LOAD:
  128. typeString = "LOAD";
  129. break;
  130. case SAVE:
  131. typeString = "SAVE";
  132. break;
  133. case AUTOSAVE:
  134. typeString = "AUTOSAVE";
  135. break;
  136. default:
  137. typeString = "UNKNOWN!!!";
  138. }
  139. return getClass().getName() + "[type=" + typeString
  140. + ",buffer=" + buffer + "]";
  141. } //}}}
  142. //{{{ Private members
  143. //{{{ Instance variables
  144. private int type;
  145. private View view;
  146. private Buffer buffer;
  147. private Object session;
  148. private VFS vfs;
  149. private String path;
  150. private String markersPath;
  151. //}}}
  152. //{{{ load() method
  153. private void load()
  154. {
  155. InputStream in = null;
  156. try
  157. {
  158. try
  159. {
  160. String[] args = { vfs.getFileName(path) };
  161. setAbortable(true);
  162. if(!buffer.isTemporary())
  163. {
  164. setStatus(jEdit.getProperty("vfs.status.load",args));
  165. setProgressValue(0);
  166. }
  167. path = vfs._canonPath(session,path,view);
  168. VFS.DirectoryEntry entry = vfs._getDirectoryEntry(
  169. session,path,view);
  170. long length;
  171. if(entry != null)
  172. length = entry.length;
  173. else
  174. length = 0L;
  175. in = vfs._createInputStream(session,path,false,view);
  176. if(in == null)
  177. return;
  178. in = new BufferedInputStream(in);
  179. if(in.markSupported())
  180. {
  181. in.mark(2);
  182. int b1 = in.read();
  183. int b2 = in.read();
  184. in.reset();
  185. if(b1 == GZIP_MAGIC_1 && b2 == GZIP_MAGIC_2)
  186. {
  187. in = new GZIPInputStream(in);
  188. buffer.setBooleanProperty(Buffer.GZIPPED,true);
  189. }
  190. else if((b1 == UNICODE_MAGIC_1 && b2 == UNICODE_MAGIC_2)
  191. || (b1 == UNICODE_MAGIC_2 && b2 == UNICODE_MAGIC_1))
  192. {
  193. buffer.setProperty(Buffer.ENCODING,"Unicode");
  194. }
  195. }
  196. else if(path.toLowerCase().endsWith(".gz"))
  197. in = new GZIPInputStream(in);
  198. read(buffer,in,length);
  199. buffer.setNewFile(false);
  200. }
  201. catch(CharConversionException ch)
  202. {
  203. Log.log(Log.ERROR,this,ch);
  204. Object[] pp = { buffer.getProperty(Buffer.ENCODING),
  205. ch.toString() };
  206. VFSManager.error(view,path,"ioerror.encoding-error",pp);
  207. buffer.setBooleanProperty(ERROR_OCCURRED,true);
  208. }
  209. catch(UnsupportedEncodingException uu)
  210. {
  211. Log.log(Log.ERROR,this,uu);
  212. Object[] pp = { buffer.getProperty(Buffer.ENCODING),
  213. uu.toString() };
  214. VFSManager.error(view,path,"ioerror.encoding-error",pp);
  215. buffer.setBooleanProperty(ERROR_OCCURRED,true);
  216. }
  217. catch(IOException io)
  218. {
  219. Log.log(Log.ERROR,this,io);
  220. Object[] pp = { io.toString() };
  221. VFSManager.error(view,path,"ioerror.read-error",pp);
  222. buffer.setBooleanProperty(ERROR_OCCURRED,true);
  223. }
  224. catch(OutOfMemoryError oom)
  225. {
  226. Log.log(Log.ERROR,this,oom);
  227. VFSManager.error(view,path,"out-of-memory-error",null);
  228. buffer.setBooleanProperty(ERROR_OCCURRED,true);
  229. }
  230. if(jEdit.getBooleanProperty("persistentMarkers"))
  231. {
  232. try
  233. {
  234. String[] args = { vfs.getFileName(path) };
  235. if(!buffer.isTemporary())
  236. setStatus(jEdit.getProperty("vfs.status.load-markers",args));
  237. setAbortable(true);
  238. in = vfs._createInputStream(session,markersPath,true,view);
  239. if(in != null)
  240. readMarkers(buffer,in);
  241. }
  242. catch(IOException io)
  243. {
  244. // ignore
  245. }
  246. }
  247. }
  248. catch(WorkThread.Abort a)
  249. {
  250. if(in != null)
  251. {
  252. try
  253. {
  254. in.close();
  255. }
  256. catch(IOException io)
  257. {
  258. }
  259. }
  260. buffer.setBooleanProperty(ERROR_OCCURRED,true);
  261. }
  262. finally
  263. {
  264. try
  265. {
  266. vfs._endVFSSession(session,view);
  267. }
  268. catch(IOException io)
  269. {
  270. Log.log(Log.ERROR,this,io);
  271. String[] pp = { io.toString() };
  272. VFSManager.error(view,path,"ioerror.read-error",pp);
  273. buffer.setBooleanProperty(ERROR_OCCURRED,true);
  274. }
  275. catch(WorkThread.Abort a)
  276. {
  277. buffer.setBooleanProperty(ERROR_OCCURRED,true);
  278. }
  279. }
  280. } //}}}
  281. //{{{ read() method
  282. private void read(Buffer buffer, InputStream _in, long length)
  283. throws IOException
  284. {
  285. /* we guess an initial size for the array */
  286. IntegerArray endOffsets = new IntegerArray(
  287. Math.max(1,(int)(length / 50)));
  288. // only true if the file size is known
  289. boolean trackProgress = (!buffer.isTemporary() && length != 0);
  290. if(trackProgress)
  291. {
  292. setProgressValue(0);
  293. setProgressMaximum((int)length);
  294. }
  295. // if the file size is not known, start with a resonable
  296. // default buffer size
  297. if(length == 0)
  298. length = IOBUFSIZE;
  299. SegmentBuffer seg = new SegmentBuffer((int)length + 1);
  300. InputStreamReader in = new InputStreamReader(_in,
  301. buffer.getStringProperty(Buffer.ENCODING));
  302. char[] buf = new char[IOBUFSIZE];
  303. // Number of characters in 'buf' array.
  304. // InputStream.read() doesn't always fill the
  305. // array (eg, the file size is not a multiple of
  306. // IOBUFSIZE, or it is a GZipped file, etc)
  307. int len;
  308. // True if a \n was read after a \r. Usually
  309. // means this is a DOS/Windows file
  310. boolean CRLF = false;
  311. // A \r was read, hence a MacOS file
  312. boolean CROnly = false;
  313. // Was the previous read character a \r?
  314. // If we read a \n and this is true, we assume
  315. // we have a DOS/Windows file
  316. boolean lastWasCR = false;
  317. // Number of lines read. Every 100 lines, we update the
  318. // progress bar
  319. int lineCount = 0;
  320. while((len = in.read(buf,0,buf.length)) != -1)
  321. {
  322. // Offset of previous line, relative to
  323. // the start of the I/O buffer (NOT
  324. // relative to the start of the document)
  325. int lastLine = 0;
  326. for(int i = 0; i < len; i++)
  327. {
  328. // Look for line endings.
  329. switch(buf[i])
  330. {
  331. case '\r':
  332. // If we read a \r and
  333. // lastWasCR is also true,
  334. // it is probably a Mac file
  335. // (\r\r in stream)
  336. if(lastWasCR)
  337. {
  338. CROnly = true;
  339. CRLF = false;
  340. }
  341. // Otherwise set a flag,
  342. // so that \n knows that last
  343. // was a \r
  344. else
  345. {
  346. lastWasCR = true;
  347. }
  348. // Insert a line
  349. seg.append(buf,lastLine,i -
  350. lastLine);
  351. seg.append('\n');
  352. endOffsets.add(seg.count);
  353. if(trackProgress && lineCount++ % PROGRESS_INTERVAL == 0)
  354. setProgressValue(seg.count);
  355. // This is i+1 to take the
  356. // trailing \n into account
  357. lastLine = i + 1;
  358. break;
  359. case '\n':
  360. // If lastWasCR is true,
  361. // we just read a \r followed
  362. // by a \n. We specify that
  363. // this is a Windows file,
  364. // but take no further
  365. // action and just ignore
  366. // the \r.
  367. if(lastWasCR)
  368. {
  369. CROnly = false;
  370. CRLF = true;
  371. lastWasCR = false;
  372. // Bump lastLine so
  373. // that the next line
  374. // doesn't erronously
  375. // pick up the \r
  376. lastLine = i + 1;
  377. }
  378. // Otherwise, we found a \n
  379. // that follows some other
  380. // character, hence we have
  381. // a Unix file
  382. else
  383. {
  384. CROnly = false;
  385. CRLF = false;
  386. seg.append(buf,lastLine,
  387. i - lastLine);
  388. seg.append('\n');
  389. endOffsets.add(seg.count);
  390. if(trackProgress && lineCount++ % PROGRESS_INTERVAL == 0)
  391. setProgressValue(seg.count);
  392. lastLine = i + 1;
  393. }
  394. break;
  395. default:
  396. // If we find some other
  397. // character that follows
  398. // a \r, so it is not a
  399. // Windows file, and probably
  400. // a Mac file
  401. if(lastWasCR)
  402. {
  403. CROnly = true;
  404. CRLF = false;
  405. lastWasCR = false;
  406. }
  407. break;
  408. }
  409. }
  410. if(trackProgress)
  411. setProgressValue(seg.count);
  412. // Add remaining stuff from buffer
  413. seg.append(buf,lastLine,len - lastLine);
  414. }
  415. setAbortable(false);
  416. String lineSeparator;
  417. if(CRLF)
  418. lineSeparator = "\r\n";
  419. else if(CROnly)
  420. lineSeparator = "\r";
  421. else
  422. lineSeparator = "\n";
  423. in.close();
  424. // Chop trailing newline and/or ^Z (if any)
  425. int bufferLength = seg.count;
  426. if(bufferLength != 0)
  427. {
  428. char ch = seg.array[bufferLength - 1];
  429. if(ch == 0x1a /* DOS ^Z */)
  430. seg.count--;
  431. }
  432. buffer.setBooleanProperty(Buffer.TRAILING_EOL,false);
  433. if(bufferLength != 0 && jEdit.getBooleanProperty("stripTrailingEOL"))
  434. {
  435. char ch = seg.array[bufferLength - 1];
  436. if(ch == '\n')
  437. {
  438. buffer.setBooleanProperty(Buffer.TRAILING_EOL,true);
  439. seg.count--;
  440. endOffsets.setSize(endOffsets.getSize() - 1);
  441. }
  442. }
  443. // add a line marker at the end for proper offset manager
  444. // operation
  445. endOffsets.add(seg.count + 1);
  446. // to avoid having to deal with read/write locks and such,
  447. // we insert the loaded data into the buffer in the
  448. // post-load cleanup runnable, which runs in the AWT thread.
  449. buffer.setProperty(LOAD_DATA,seg);
  450. buffer.setProperty(END_OFFSETS,endOffsets);
  451. buffer.setProperty(NEW_PATH,path);
  452. buffer.setProperty(Buffer.LINESEP,lineSeparator);
  453. } //}}}
  454. //{{{ readMarkers() method
  455. private void readMarkers(Buffer buffer, InputStream _in)
  456. throws IOException
  457. {
  458. // For `reload' command
  459. buffer.removeAllMarkers();
  460. BufferedReader in = new BufferedReader(new InputStreamReader(_in));
  461. String line;
  462. while((line = in.readLine()) != null)
  463. {
  464. // compatibility kludge for jEdit 3.1 and earlier
  465. if(!line.startsWith("!"))
  466. continue;
  467. char shortcut = line.charAt(1);
  468. int start = line.indexOf(';');
  469. int end = line.indexOf(';',start + 1);
  470. int position = Integer.parseInt(line.substring(start + 1,end));
  471. buffer.addMarker(shortcut,position);
  472. }
  473. in.close();
  474. } //}}}
  475. //{{{ save() method
  476. private void save()
  477. {
  478. OutputStream out = null;
  479. try
  480. {
  481. String[] args = { vfs.getFileName(path) };
  482. setStatus(jEdit.getProperty("vfs.status.save",args));
  483. // the entire save operation can be aborted...
  484. setAbortable(true);
  485. path = vfs._canonPath(session,path,view); if(!MiscUtilities.isURL(path))
  486. path = MiscUtilities.resolveSymlinks(path);
  487. // Only backup once per session
  488. if(buffer.getProperty(Buffer.BACKED_UP) == null
  489. || jEdit.getBooleanProperty("backupEverySave"))
  490. {
  491. vfs._backup(session,path,view);
  492. buffer.setBooleanProperty(Buffer.BACKED_UP,true);
  493. }
  494. /* if the VFS supports renaming files, we first
  495. * save to #<filename>#save#, then rename that
  496. * to <filename>, so that if the save fails,
  497. * data will not be lost.
  498. *
  499. * as of 4.1pre7 we now call vfs.getTwoStageSaveName()
  500. * instead of constructing the path directly
  501. * since some VFS's might not allow # in filenames.
  502. */
  503. String savePath;
  504. boolean twoStageSave = (vfs.getCapabilities() & VFS.RENAME_CAP) != 0
  505. && jEdit.getBooleanProperty("twoStageSave");
  506. if(twoStageSave)
  507. savePath = vfs.getTwoStageSaveName(path);
  508. else
  509. savePath = path;
  510. out = vfs._createOutputStream(session,savePath,view);
  511. try
  512. {
  513. // this must be after the stream is created or
  514. // we deadlock with SSHTools.
  515. buffer.readLock();
  516. if(out != null)
  517. {
  518. // Can't use buffer.getName() here because
  519. // it is not changed until the save is
  520. // complete
  521. if(savePath.endsWith(".gz"))
  522. buffer.setBooleanProperty(Buffer.GZIPPED,true);
  523. if(buffer.getBooleanProperty(Buffer.GZIPPED))
  524. out = new GZIPOutputStream(out);
  525. write(buffer,out);
  526. if(twoStageSave)
  527. {
  528. if(!vfs._rename(session,savePath,path,view))
  529. throw new IOException(savePath);
  530. }
  531. // We only save markers to VFS's that support deletion.
  532. // Otherwise, we will accumilate stale marks files.
  533. if((vfs.getCapabilities() & VFS.DELETE_CAP) != 0)
  534. {
  535. if(jEdit.getBooleanProperty("persistentMarkers")
  536. && buffer.getMarkers().size() != 0)
  537. {
  538. setStatus(jEdit.getProperty("vfs.status.save-markers",args));
  539. setProgressValue(0);
  540. out = vfs._createOutputStream(session,markersPath,view);
  541. if(out != null)
  542. writeMarkers(buffer,out);
  543. }
  544. else
  545. vfs._delete(session,markersPath,view);
  546. }
  547. }
  548. else
  549. buffer.setBooleanProperty(ERROR_OCCURRED,true);
  550. if(!twoStageSave)
  551. VFSManager.sendVFSUpdate(vfs,path,true);
  552. }
  553. finally
  554. {
  555. buffer.readUnlock();
  556. }
  557. }
  558. catch(IOException io)
  559. {
  560. Log.log(Log.ERROR,this,io);
  561. String[] pp = { io.toString() };
  562. VFSManager.error(view,path,"ioerror.write-error",pp);
  563. buffer.setBooleanProperty(ERROR_OCCURRED,true);
  564. }
  565. catch(WorkThread.Abort a)
  566. {
  567. if(out != null)
  568. {
  569. try
  570. {
  571. out.close();
  572. }
  573. catch(IOException io)
  574. {
  575. }
  576. }
  577. buffer.setBooleanProperty(ERROR_OCCURRED,true);
  578. }
  579. finally
  580. {
  581. try
  582. {
  583. vfs._saveComplete(session,buffer,path,view);
  584. vfs._endVFSSession(session,view);
  585. }
  586. catch(IOException io)
  587. {
  588. Log.log(Log.ERROR,this,io);
  589. String[] pp = { io.toString() };
  590. VFSManager.error(view,path,"ioerror.write-error",pp);
  591. buffer.setBooleanProperty(ERROR_OCCURRED,true);
  592. }
  593. catch(WorkThread.Abort a)
  594. {
  595. buffer.setBooleanProperty(ERROR_OCCURRED,true);
  596. }
  597. }
  598. } //}}}
  599. //{{{ autosave() method
  600. private void autosave()
  601. {
  602. OutputStream out = null;
  603. try
  604. {
  605. String[] args = { vfs.getFileName(path) };
  606. setStatus(jEdit.getProperty("vfs.status.autosave",args));
  607. // the entire save operation can be aborted...
  608. setAbortable(true);
  609. try
  610. {
  611. //buffer.readLock();
  612. if(!buffer.isDirty())
  613. {
  614. // buffer has been saved while we
  615. // were waiting.
  616. return;
  617. }
  618. out = vfs._createOutputStream(session,path,view);
  619. if(out == null)
  620. return;
  621. write(buffer,out);
  622. }
  623. catch(Exception e)
  624. {
  625. }
  626. finally
  627. {
  628. //buffer.readUnlock();
  629. }
  630. }
  631. catch(WorkThread.Abort a)
  632. {
  633. if(out != null)
  634. {
  635. try
  636. {
  637. out.close();
  638. }
  639. catch(IOException io)
  640. {
  641. }
  642. }
  643. }
  644. } //}}}
  645. //{{{ write() method
  646. private void write(Buffer buffer, OutputStream _out)
  647. throws IOException
  648. {
  649. BufferedWriter out = new BufferedWriter(
  650. new OutputStreamWriter(_out,
  651. buffer.getStringProperty(Buffer.ENCODING)),
  652. IOBUFSIZE);
  653. Segment lineSegment = new Segment();
  654. String newline = buffer.getStringProperty(Buffer.LINESEP);
  655. if(newline == null)
  656. newline = System.getProperty("line.separator");
  657. setProgressMaximum(buffer.getLineCount() / PROGRESS_INTERVAL);
  658. setProgressValue(0);
  659. int i = 0;
  660. while(i < buffer.getLineCount())
  661. {
  662. buffer.getLineText(i,lineSegment);
  663. out.write(lineSegment.array,lineSegment.offset,
  664. lineSegment.count);
  665. if(i != buffer.getLineCount() - 1)
  666. {
  667. out.write(newline);
  668. }
  669. if(++i % PROGRESS_INTERVAL == 0)
  670. setProgressValue(i / PROGRESS_INTERVAL);
  671. }
  672. if(jEdit.getBooleanProperty("stripTrailingEOL")
  673. && buffer.getBooleanProperty(Buffer.TRAILING_EOL))
  674. {
  675. out.write(newline);
  676. }
  677. out.close();
  678. } //}}}
  679. //{{{ writeMarkers() method
  680. private void writeMarkers(Buffer buffer, OutputStream out)
  681. throws IOException
  682. {
  683. Writer o = new BufferedWriter(new OutputStreamWriter(out));
  684. Vector markers = buffer.getMarkers();
  685. for(int i = 0; i < markers.size(); i++)
  686. {
  687. Marker marker = (Marker)markers.elementAt(i);
  688. o.write('!');
  689. o.write(marker.getShortcut());
  690. o.write(';');
  691. String pos = String.valueOf(marker.getPosition());
  692. o.write(pos);
  693. o.write(';');
  694. o.write(pos);
  695. o.write('\n');
  696. }
  697. o.close();
  698. } //}}}
  699. //{{{ insert() method
  700. private void insert()
  701. {
  702. InputStream in = null;
  703. try
  704. {
  705. try
  706. {
  707. String[] args = { vfs.getFileName(path) };
  708. setStatus(jEdit.getProperty("vfs.status.load",args));
  709. setAbortable(true);
  710. path = vfs._canonPath(session,path,view);
  711. VFS.DirectoryEntry entry = vfs._getDirectoryEntry(
  712. session,path,view);
  713. long length;
  714. if(entry != null)
  715. length = entry.length;
  716. else
  717. length = 0L;
  718. in = vfs._createInputStream(session,path,false,view);
  719. if(in == null)
  720. return;
  721. if(path.endsWith(".gz"))
  722. in = new GZIPInputStream(in);
  723. read(buffer,in,length);
  724. }
  725. catch(IOException io)
  726. {
  727. Log.log(Log.ERROR,this,io);
  728. String[] pp = { io.toString() };
  729. VFSManager.error(view,path,"ioerror.read-error",pp);
  730. buffer.setBooleanProperty(ERROR_OCCURRED,true);
  731. }
  732. }
  733. catch(WorkThread.Abort a)
  734. {
  735. if(in != null)
  736. {
  737. try
  738. {
  739. in.close();
  740. }
  741. catch(IOException io)
  742. {
  743. }
  744. }
  745. buffer.setBooleanProperty(ERROR_OCCURRED,true);
  746. }
  747. finally
  748. {
  749. try
  750. {
  751. vfs._endVFSSession(session,view);
  752. }
  753. catch(IOException io)
  754. {
  755. Log.log(Log.ERROR,this,io);
  756. String[] pp = { io.toString() };
  757. VFSManager.error(view,path,"ioerror.read-error",pp);
  758. buffer.setBooleanProperty(ERROR_OCCURRED,true);
  759. }
  760. catch(WorkThread.Abort a)
  761. {
  762. buffer.setBooleanProperty(ERROR_OCCURRED,true);
  763. }
  764. }
  765. } //}}}
  766. //}}}
  767. }