KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > sp > jedit > io > UrlVFS


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
23 package org.gjt.sp.jedit.io;
24
25 //{{{ Imports
26
import java.awt.Component JavaDoc;
27 import java.io.*;
28 import java.net.*;
29 import 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  */

37 public 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 JavaDoc constructPath(String JavaDoc parent, String JavaDoc 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 JavaDoc session,
56         String JavaDoc path, boolean ignoreErrors, Component JavaDoc 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 JavaDoc[] 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 JavaDoc session, String JavaDoc path,
74         Component JavaDoc 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 JavaDoc[] args = { mu.getMessage() };
85             VFSManager.error(comp,path,"ioerror.badurl",args);
86             return null;
87         }
88     } //}}}
89
}
90
Popular Tags