PageRenderTime 41ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-1-pre5/org/gjt/sp/jedit/io/UrlVFS.java

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