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