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