PageRenderTime 54ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre4/org/gjt/sp/jedit/io/UrlVFS.java

#
Java | 89 lines | 51 code | 6 blank | 32 comment | 1 complexity | 0c8808e22adc3b1fe11de847ea8bfdb4 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. * UrlVFS.java - URL VFS
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2000 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.io;
  23. //{{{ Imports
  24. import java.awt.Component;
  25. import java.io.*;
  26. import java.net.*;
  27. import org.gjt.sp.util.Log;
  28. //}}}
  29. /**
  30. * URL VFS.
  31. * @author Slava Pestov
  32. * @version $Id: UrlVFS.java 4428 2003-01-12 03:08:25Z spestov $
  33. */
  34. public class UrlVFS extends VFS
  35. {
  36. //{{{ UrlVFS constructor
  37. public UrlVFS()
  38. {
  39. super("url",READ_CAP | WRITE_CAP);
  40. } //}}}
  41. //{{{ constructPath() method
  42. public String constructPath(String parent, String path)
  43. {
  44. if(parent.endsWith("/"))
  45. return parent + path;
  46. else
  47. return parent + '/' + path;
  48. } //}}}
  49. //{{{ _createInputStream() method
  50. public InputStream _createInputStream(Object session,
  51. String path, boolean ignoreErrors, Component comp)
  52. throws IOException
  53. {
  54. try
  55. {
  56. return new URL(path).openStream();
  57. }
  58. catch(MalformedURLException mu)
  59. {
  60. Log.log(Log.ERROR,this,mu);
  61. String[] args = { mu.getMessage() };
  62. VFSManager.error(comp,path,"ioerror.badurl",args);
  63. return null;
  64. }
  65. } //}}}
  66. //{{{ _createOutputStream() method
  67. public OutputStream _createOutputStream(Object session, String path,
  68. Component comp) throws IOException
  69. {
  70. try
  71. {
  72. return new URL(path).openConnection()
  73. .getOutputStream();
  74. }
  75. catch(MalformedURLException mu)
  76. {
  77. Log.log(Log.ERROR,this,mu);
  78. String[] args = { mu.getMessage() };
  79. VFSManager.error(comp,path,"ioerror.badurl",args);
  80. return null;
  81. }
  82. } //}}}
  83. }