/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
23package org.gjt.sp.jedit.io;
24
25//{{{ Imports
26import java.awt.Component;
27import java.io.*;
28import java.net.*;
29import org.gjt.sp.jedit.*;
30import org.gjt.sp.util.Log;
31//}}}
32
33/**
34 * URL VFS.
35 * @author Slava Pestov
36 * @version $Id: UrlVFS.java 4202 2002-05-28 03:01:22Z spestov $
37 */
38public class UrlVFS extends VFS
39{
40 //{{{ UrlVFS constructor
41 public UrlVFS()
42 {
43 super("url",READ_CAP | WRITE_CAP);
44 } //}}}
45
46 //{{{ constructPath() method
47 public String constructPath(String parent, String path)
48 {
49 if(parent.endsWith("/"))
50 return parent + path;
51 else
52 return parent + '/' + path;
53 } //}}}
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,"ioerror.badurl",args);
69 return null;
70 }
71 } //}}}
72
73 //{{{ _createOutputStream() method
74 public OutputStream _createOutputStream(Object session, String path,
75 Component comp) throws IOException
76 {
77 try
78 {
79 return new URL(path).openConnection()
80 .getOutputStream();
81 }
82 catch(MalformedURLException mu)
83 {
84 Log.log(Log.ERROR,this,mu);
85 String[] args = { mu.getMessage() };
86 VFSManager.error(comp,path,"ioerror.badurl",args);
87 return null;
88 }
89 } //}}}
90}