PageRenderTime 61ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 125 lines | 74 code | 11 blank | 40 comment | 4 complexity | 933038c566b42da3efb19c69b8670637 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. * 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. 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 insert request.
  31. * @author Slava Pestov
  32. * @version $Id: BufferInsertRequest.java 12504 2008-04-22 23:12:43Z ezust $
  33. */
  34. public class BufferInsertRequest extends BufferIORequest
  35. {
  36. //{{{ BufferInsertRequest 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 BufferInsertRequest(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. InputStream in = null;
  54. try
  55. {
  56. String[] args = { vfs.getFileName(path) };
  57. setStatus(jEdit.getProperty("vfs.status.load",args));
  58. setAbortable(true);
  59. path = vfs._canonPath(session,path,view);
  60. VFSFile entry = vfs._getFile(
  61. session,path,view);
  62. long length;
  63. if(entry != null)
  64. length = entry.getLength();
  65. else
  66. length = 0L;
  67. in = vfs._createInputStream(session,path,false,view);
  68. if(in == null)
  69. return;
  70. final SegmentBuffer seg = read(
  71. autodetect(in),length,true);
  72. /* we don't do this in Buffer.insert() so that
  73. we can insert multiple files at once */
  74. VFSManager.runInAWTThread(new Runnable()
  75. {
  76. public void run()
  77. {
  78. view.getTextArea().setSelectedText(
  79. seg.toString());
  80. }
  81. });
  82. }
  83. catch(Exception e)
  84. {
  85. Log.log(Log.ERROR,this,e);
  86. String[] pp = { e.toString() };
  87. VFSManager.error(view,path,"ioerror.read-error",pp);
  88. buffer.setBooleanProperty(ERROR_OCCURRED,true);
  89. }
  90. catch(WorkThread.Abort a)
  91. {
  92. buffer.setBooleanProperty(ERROR_OCCURRED,true);
  93. }
  94. finally
  95. {
  96. IOUtilities.closeQuietly(in);
  97. try
  98. {
  99. vfs._endVFSSession(session,view);
  100. }
  101. catch(Exception e)
  102. {
  103. Log.log(Log.ERROR,this,e);
  104. String[] pp = { e.toString() };
  105. VFSManager.error(view,path,"ioerror.read-error",pp);
  106. buffer.setBooleanProperty(ERROR_OCCURRED,true);
  107. }
  108. catch(WorkThread.Abort a)
  109. {
  110. buffer.setBooleanProperty(ERROR_OCCURRED,true);
  111. }
  112. }
  113. } //}}}
  114. }