PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-5-pre1/org/gjt/sp/jedit/bufferio/BufferAutosaveRequest.java

#
Java | 122 lines | 64 code | 11 blank | 47 comment | 5 complexity | 1afb8cafa95b61156b20d7aa17a28524 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. * 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. package org.gjt.sp.jedit.bufferio;
  23. //{{{ Imports
  24. import java.io.*;
  25. import org.gjt.sp.jedit.io.*;
  26. import org.gjt.sp.jedit.*;
  27. import org.gjt.sp.util.*;
  28. //}}}
  29. /**
  30. * A buffer autosave request.
  31. * @author Slava Pestov
  32. * @version $Id: BufferAutosaveRequest.java 19408 2011-02-28 14:52:25Z kpouer $
  33. */
  34. public class BufferAutosaveRequest extends BufferIORequest
  35. {
  36. //{{{ BufferAutosaveRequest constructor
  37. /**
  38. * Creates a new buffer I/O request.
  39. * @param view The view
  40. * @param buffer The buffer
  41. * @param session The VFS session
  42. * @param vfs The VFS
  43. * @param path The path
  44. */
  45. public BufferAutosaveRequest(View view, Buffer buffer,
  46. Object session, VFS vfs, String path)
  47. {
  48. super(view,buffer,session,vfs,path);
  49. } //}}}
  50. //{{{ run() method
  51. public void run()
  52. {
  53. OutputStream out = null;
  54. try
  55. {
  56. String[] args = { vfs.getFileName(path) };
  57. setStatus(jEdit.getProperty("vfs.status.autosave",args));
  58. // the entire save operation can be aborted...
  59. setAbortable(true);
  60. try
  61. {
  62. //buffer.readLock();
  63. if(!buffer.isDirty())
  64. {
  65. // buffer has been saved while we
  66. // were waiting.
  67. return;
  68. }
  69. out = vfs._createOutputStream(session,path,view);
  70. if(out == null)
  71. return;
  72. write(buffer,out);
  73. }
  74. catch (FileNotFoundException e)
  75. {
  76. Log.log(Log.WARNING,this,"Unable to save " + e.getMessage());
  77. }
  78. catch(Exception e)
  79. {
  80. Log.log(Log.ERROR,this,e);
  81. String[] pp = { e.toString() };
  82. VFSManager.error(view,path,"ioerror.write-error",pp);
  83. // Incomplete autosave file should not exist.
  84. if(out != null)
  85. {
  86. try
  87. {
  88. out.close();
  89. out = null;
  90. vfs._delete(session,path,view);
  91. }
  92. catch(IOException ioe)
  93. {
  94. Log.log(Log.ERROR,this,ioe);
  95. }
  96. }
  97. }
  98. //finally
  99. //{
  100. //buffer.readUnlock();
  101. //}
  102. }
  103. catch(WorkThread.Abort a)
  104. {
  105. }
  106. finally
  107. {
  108. IOUtilities.closeQuietly(out);
  109. }
  110. } //}}}
  111. }