View Javadoc

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      @Override
46      public boolean exists()
47      {
48          return false;
49      }
50          
51      /* -------------------------------------------------------- */
52      @Override
53      public long lastModified()
54      {
55          return -1;
56      }
57  
58      /* -------------------------------------------------------- */
59      @Override
60      public boolean isDirectory()
61      {
62          return false;
63      }
64  
65      /* --------------------------------------------------------- */
66      @Override
67      public long length()
68      {
69          return -1;
70      }
71          
72          
73      /* ------------------------------------------------------------ */
74      @Override
75      public File getFile()
76      {
77          return null;
78      }
79          
80      /* --------------------------------------------------------- */
81      @Override
82      public InputStream getInputStream() throws IOException
83      {
84          throw new FileNotFoundException(_message);
85      }
86          
87      /* --------------------------------------------------------- */
88      @Override
89      public OutputStream getOutputStream()
90          throws java.io.IOException, SecurityException
91      {
92          throw new FileNotFoundException(_message);
93      }
94          
95      /* --------------------------------------------------------- */
96      @Override
97      public boolean delete()
98          throws SecurityException
99      {
100         throw new SecurityException(_message);
101     }
102 
103     /* --------------------------------------------------------- */
104     @Override
105     public boolean renameTo( Resource dest)
106         throws SecurityException
107     {
108         throw new SecurityException(_message);
109     }
110 
111     /* --------------------------------------------------------- */
112     @Override
113     public String[] list()
114     {
115         return null;
116     }
117 
118     /* ------------------------------------------------------------ */
119     @Override
120     public void copyTo(File destination)
121         throws IOException
122     {
123         throw new SecurityException(_message);
124     }
125     
126     /* ------------------------------------------------------------ */
127     @Override
128     public String toString()
129     {
130         return super.toString()+"; BadResource="+_message;
131     }
132     
133 }