01: /*
02: * $Id: FileURLConnection.java,v 1.2 2002/09/16 08:05:07 jkl Exp $
03: *
04: * Copyright (c) 2002 Njet Communications Ltd. All Rights Reserved.
05: *
06: * Use is subject to license terms, as defined in
07: * Anvil Sofware License, Version 1.1. See LICENSE
08: * file, or http://njet.org/license-1.1.txt
09: */
10: package anvil.util;
11:
12: import java.io.File;
13: import java.io.FileInputStream;
14: import java.io.InputStream;
15: import java.io.IOException;
16: import java.io.OutputStream;
17: import java.net.UnknownServiceException;
18: import java.net.URL;
19: import java.net.URLConnection;
20:
21: /**
22: * class FileURLConnection
23: *
24: * @author: Jani Lehtimäki
25: */
26: public class FileURLConnection extends URLConnection {
27: private String _fileName;
28: private File _file;
29: private long _lastModified = 0;
30: private boolean _fileExists = false;
31:
32: FileURLConnection(URL url) {
33: super (url);
34: _fileName = url.getFile();
35: _file = new File(_fileName);
36: _fileExists = _file.exists();
37: if (_fileExists) {
38: _lastModified = _file.lastModified();
39: }
40: }
41:
42: public void connect() throws IOException {
43: if (connected == false) {
44: connected = true;
45: }
46: }
47:
48: public long getLastModified() {
49: return _lastModified;
50: }
51:
52: public boolean hasBeenModified() {
53: return (ifModifiedSince == 0)
54: || (_lastModified > ifModifiedSince);
55: }
56:
57: public InputStream getInputStream() throws IOException {
58: connect();
59: if (_fileExists) {
60: return new FileInputStream(_fileName);
61: } else {
62: throw new IOException("File not found: " + _fileName);
63: }
64: }
65:
66: public OutputStream getOutputStream() throws IOException {
67: connect();
68: throw new UnknownServiceException();
69: }
70:
71: }
|