1 // ========================================================================
2 // Copyright (c) 1996-2009 Mort Bay Consulting Pty. Ltd.
3 // ------------------------------------------------------------------------
4 // All rights reserved. This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v1.0
6 // and Apache License v2.0 which accompanies this distribution.
7 // The Eclipse Public License is available at
8 // http://www.eclipse.org/legal/epl-v10.html
9 // The Apache License v2.0 is available at
10 // http://www.opensource.org/licenses/apache2.0.php
11 // You may elect to redistribute this code under either of these licenses.
12 // ========================================================================
13 package org.eclipse.jetty.util.resource;
14
15 import java.io.File;
16 import java.io.FileNotFoundException;
17 import java.io.IOException;
18 import java.io.InputStream;
19 import java.io.OutputStream;
20 import java.net.URL;
21
22
23 /* ------------------------------------------------------------ */
24 /** Bad Resource.
25 *
26 * A Resource that is returned for a bade URL. Acts as a resource
27 * that does not exist and throws appropriate exceptions.
28 *
29 *
30 */
31 class BadResource extends URLResource
32 {
33 /* ------------------------------------------------------------ */
34 private String _message=null;
35
36 /* -------------------------------------------------------- */
37 BadResource(URL url, String message)
38 {
39 super(url,null);
40 _message=message;
41 }
42
43
44 /* -------------------------------------------------------- */
45 public boolean exists()
46 {
47 return false;
48 }
49
50 /* -------------------------------------------------------- */
51 public long lastModified()
52 {
53 return -1;
54 }
55
56 /* -------------------------------------------------------- */
57 public boolean isDirectory()
58 {
59 return false;
60 }
61
62 /* --------------------------------------------------------- */
63 public long length()
64 {
65 return -1;
66 }
67
68
69 /* ------------------------------------------------------------ */
70 public File getFile()
71 {
72 return null;
73 }
74
75 /* --------------------------------------------------------- */
76 public InputStream getInputStream() throws IOException
77 {
78 throw new FileNotFoundException(_message);
79 }
80
81 /* --------------------------------------------------------- */
82 public OutputStream getOutputStream()
83 throws java.io.IOException, SecurityException
84 {
85 throw new FileNotFoundException(_message);
86 }
87
88 /* --------------------------------------------------------- */
89 public boolean delete()
90 throws SecurityException
91 {
92 throw new SecurityException(_message);
93 }
94
95 /* --------------------------------------------------------- */
96 public boolean renameTo( Resource dest)
97 throws SecurityException
98 {
99 throw new SecurityException(_message);
100 }
101
102 /* --------------------------------------------------------- */
103 public String[] list()
104 {
105 return null;
106 }
107
108 /* ------------------------------------------------------------ */
109 public String toString()
110 {
111 return super.toString()+"; BadResource="+_message;
112 }
113
114 }