blob: fbb27f2b7d1f8598655e2244bb61f25b7b11a8b7 [file] [log] [blame]
Jake Slack03928ae2014-05-13 18:41:56 -07001//
2// ========================================================================
3// Copyright (c) 1995-2014 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
19package org.eclipse.jetty.util.resource;
20
21import java.io.File;
22import java.io.FileNotFoundException;
23import java.io.IOException;
24import java.io.InputStream;
25import java.io.OutputStream;
26import java.net.URL;
27
28
29/* ------------------------------------------------------------ */
30/** Bad Resource.
31 *
32 * A Resource that is returned for a bade URL. Acts as a resource
33 * that does not exist and throws appropriate exceptions.
34 *
35 *
36 */
37class BadResource extends URLResource
38{
39 /* ------------------------------------------------------------ */
40 private String _message=null;
41
42 /* -------------------------------------------------------- */
43 BadResource(URL url, String message)
44 {
45 super(url,null);
46 _message=message;
47 }
48
49
50 /* -------------------------------------------------------- */
51 @Override
52 public boolean exists()
53 {
54 return false;
55 }
56
57 /* -------------------------------------------------------- */
58 @Override
59 public long lastModified()
60 {
61 return -1;
62 }
63
64 /* -------------------------------------------------------- */
65 @Override
66 public boolean isDirectory()
67 {
68 return false;
69 }
70
71 /* --------------------------------------------------------- */
72 @Override
73 public long length()
74 {
75 return -1;
76 }
77
78
79 /* ------------------------------------------------------------ */
80 @Override
81 public File getFile()
82 {
83 return null;
84 }
85
86 /* --------------------------------------------------------- */
87 @Override
88 public InputStream getInputStream() throws IOException
89 {
90 throw new FileNotFoundException(_message);
91 }
92
93 /* --------------------------------------------------------- */
94 @Override
95 public OutputStream getOutputStream()
96 throws java.io.IOException, SecurityException
97 {
98 throw new FileNotFoundException(_message);
99 }
100
101 /* --------------------------------------------------------- */
102 @Override
103 public boolean delete()
104 throws SecurityException
105 {
106 throw new SecurityException(_message);
107 }
108
109 /* --------------------------------------------------------- */
110 @Override
111 public boolean renameTo( Resource dest)
112 throws SecurityException
113 {
114 throw new SecurityException(_message);
115 }
116
117 /* --------------------------------------------------------- */
118 @Override
119 public String[] list()
120 {
121 return null;
122 }
123
124 /* ------------------------------------------------------------ */
125 @Override
126 public void copyTo(File destination)
127 throws IOException
128 {
129 throw new SecurityException(_message);
130 }
131
132 /* ------------------------------------------------------------ */
133 @Override
134 public String toString()
135 {
136 return super.toString()+"; BadResource="+_message;
137 }
138
139}