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

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

#
Java | 96 lines | 56 code | 7 blank | 33 comment | 1 complexity | e23417efb1838300e9e250446c0903fc 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 3925 2001-11-30 11:40:16Z spestov $
  34. */
  35. public class UrlVFS extends VFS
  36. {
  37. //{{{ UrlVFS constructor
  38. public UrlVFS()
  39. {
  40. super("url");
  41. } //}}}
  42. //{{{ getCapabilities() method
  43. public int getCapabilities()
  44. {
  45. return READ_CAP | WRITE_CAP;
  46. } //}}}
  47. //{{{ constructPath() method
  48. public String constructPath(String parent, String path)
  49. {
  50. if(parent.endsWith("/"))
  51. return parent + path;
  52. else
  53. return parent + '/' + path;
  54. } //}}}
  55. //{{{ _createInputStream() method
  56. public InputStream _createInputStream(Object session,
  57. String path, boolean ignoreErrors, Component comp)
  58. throws IOException
  59. {
  60. try
  61. {
  62. return new URL(path).openStream();
  63. }
  64. catch(MalformedURLException mu)
  65. {
  66. Log.log(Log.ERROR,this,mu);
  67. String[] args = { mu.getMessage() };
  68. VFSManager.error(comp,path,"badurl",args);
  69. return null;
  70. }
  71. } //}}}
  72. //{{{ _createOutputStream() method
  73. public OutputStream _createOutputStream(Object session, String path,
  74. Component comp) throws IOException
  75. {
  76. try
  77. {
  78. return new URL(path).openConnection()
  79. .getOutputStream();
  80. }
  81. catch(MalformedURLException mu)
  82. {
  83. Log.log(Log.ERROR,this,mu);
  84. String[] args = { mu.getMessage() };
  85. VFSManager.error(comp,path,"badurl",args);
  86. return null;
  87. }
  88. } //}}}
  89. }