/[classpath]/classpath/gnu/java/net/protocol/file/Connection.java
ViewVC logotype

Diff of /classpath/gnu/java/net/protocol/file/Connection.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by mark, Thu Nov 13 17:15:03 2003 UTC revision 1.6 by mkoch, Tue Dec 2 09:09:57 2003 UTC
# Line 42  import java.io.BufferedInputStream; Line 42  import java.io.BufferedInputStream;
42  import java.io.BufferedOutputStream;  import java.io.BufferedOutputStream;
43  import java.io.File;  import java.io.File;
44  import java.io.FileInputStream;  import java.io.FileInputStream;
 import java.io.FileNotFoundException;  
45  import java.io.FileOutputStream;  import java.io.FileOutputStream;
46  import java.io.FilePermission;  import java.io.FilePermission;
47  import java.io.InputStream;  import java.io.InputStream;
# Line 68  import java.util.NoSuchElementException; Line 67  import java.util.NoSuchElementException;
67  public class Connection extends URLConnection  public class Connection extends URLConnection
68  {  {
69    /**    /**
70       * Default permission for a file
71       */
72      private static final String DEFAULT_PERMISSION = "read";
73    
74      /**
75     * This is a File object for this connection     * This is a File object for this connection
76     */     */
77    private File file;    private File file;
# Line 75  public class Connection extends URLConne Line 79  public class Connection extends URLConne
79    /**    /**
80     * InputStream if we are reading from the file     * InputStream if we are reading from the file
81     */     */
82    private BufferedInputStream inputStream;    private InputStream inputStream;
83    
84    /**    /**
85     * OutputStream if we are writing to the file     * OutputStream if we are writing to the file
86     */     */
87    private BufferedOutputStream outputStream;    private OutputStream outputStream;
88    
89    /**    /**
90     * FilePermission to read the file     * FilePermission to read the file
# Line 88  public class Connection extends URLConne Line 92  public class Connection extends URLConne
92    private FilePermission permission;    private FilePermission permission;
93    
94    /**    /**
    * Default permission for a file  
    */  
   private static final String DEFAULT_PERMISSION = "read";  
   
   /**  
95     * Calls superclass constructor to initialize.     * Calls superclass constructor to initialize.
96     */     */
97    public Connection (URL url)    public Connection(URL url)
98    {    {
99      super (url);      super (url);
100            
# Line 116  public class Connection extends URLConne Line 115  public class Connection extends URLConne
115            
116      // If not connected, then file needs to be openned.      // If not connected, then file needs to be openned.
117      file = new File (getURL().getFile());      file = new File (getURL().getFile());
   
     if (!file.exists())  
       throw new FileNotFoundException (file.getPath());  
   
118      if (doInput)      if (doInput)
119        inputStream = new BufferedInputStream (new FileInputStream (file));        inputStream = new BufferedInputStream(new FileInputStream(file));
120            
121      if (doOutput)      if (doOutput)
122        outputStream = new BufferedOutputStream (new FileOutputStream (file));        outputStream = new BufferedOutputStream(new FileOutputStream(file));
123            
124      connected = true;      connected = true;
125    }    }
# Line 140  public class Connection extends URLConne Line 135  public class Connection extends URLConne
135      throws IOException      throws IOException
136    {    {
137      if (!doInput)      if (!doInput)
138        throw new ProtocolException ("Can't open InputStream if doInput is false");        throw new ProtocolException("Can't open InputStream if doInput is false");
139            
140      if (!connected)      if (!connected)
141        connect();        connect();
# Line 159  public class Connection extends URLConne Line 154  public class Connection extends URLConne
154      throws IOException      throws IOException
155    {    {
156      if (!doOutput)      if (!doOutput)
157        throw new ProtocolException ("Can't open OutputStream if doOutput is false");        throw new
158            ProtocolException("Can't open OutputStream if doOutput is false");
159    
160      if (!connected)      if (!connected)
161        connect();        connect();
# Line 178  public class Connection extends URLConne Line 174  public class Connection extends URLConne
174        {        {
175          if (!connected)          if (!connected)
176            connect();            connect();
177            
178          return file.lastModified();          return file.lastModified();
179        }        }
180      catch (IOException e)      catch (IOException e)
# Line 206  public class Connection extends URLConne Line 202  public class Connection extends URLConne
202          return -1;          return -1;
203        }        }
204    }    }
205      
   
206    /**    /**
207     * This method returns a <code>Permission</code> object representing the     * This method returns a <code>Permission</code> object representing the
208     * permissions required to access this URL.  This method returns a     * permissions required to access this URL.  This method returns a
# Line 321  public class Connection extends URLConne Line 316  public class Connection extends URLConne
316          }          }
317        };        };
318    }    }
319      
320  } // class FileURLConnection  } // class FileURLConnection

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26