PageRenderTime 98ms CodeModel.GetById 90ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre4/org/gjt/sp/jedit/io/UrlVFS.java

#
Java | 89 lines | 51 code | 6 blank | 32 comment | 1 complexity | 0c8808e22adc3b1fe11de847ea8bfdb4 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.util.Log;
30//}}}
31
32/**
33 * URL VFS.
34 * @author Slava Pestov
35 * @version $Id: UrlVFS.java 4428 2003-01-12 03:08:25Z spestov $
36 */
37public class UrlVFS extends VFS
38{
39	//{{{ UrlVFS constructor
40	public UrlVFS()
41	{
42		super("url",READ_CAP | WRITE_CAP);
43	} //}}}
44
45	//{{{ constructPath() method
46	public String constructPath(String parent, String path)
47	{
48		if(parent.endsWith("/"))
49			return parent + path;
50		else
51			return parent + '/' + path;
52	} //}}}
53
54	//{{{ _createInputStream() method
55	public InputStream _createInputStream(Object session,
56		String path, boolean ignoreErrors, Component comp)
57		throws IOException
58	{
59		try
60		{
61			return new URL(path).openStream();
62		}
63		catch(MalformedURLException mu)
64		{
65			Log.log(Log.ERROR,this,mu);
66			String[] args = { mu.getMessage() };
67			VFSManager.error(comp,path,"ioerror.badurl",args);
68			return null;
69		}
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,"ioerror.badurl",args);
86			return null;
87		}
88	} //}}}
89}