PageRenderTime 52ms CodeModel.GetById 30ms app.highlight 6ms RepoModel.GetById 14ms app.codeStats 0ms

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

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