KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > core > sourcelookup > containers > LocalFileStorage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.debug.core.sourcelookup.containers;
12
13 import java.io.File JavaDoc;
14 import java.io.FileInputStream JavaDoc;
15 import java.io.IOException JavaDoc;
16 import java.io.InputStream JavaDoc;
17
18 import org.eclipse.core.resources.IStorage;
19 import org.eclipse.core.runtime.CoreException;
20 import org.eclipse.core.runtime.IPath;
21 import org.eclipse.core.runtime.IStatus;
22 import org.eclipse.core.runtime.Path;
23 import org.eclipse.core.runtime.PlatformObject;
24 import org.eclipse.core.runtime.Status;
25 import org.eclipse.debug.core.DebugPlugin;
26 import org.eclipse.debug.internal.core.sourcelookup.SourceLookupMessages;
27
28 /**
29  * Implementation of storage for a local file
30  * (<code>java.io.File</code>).
31  * <p>
32  * This class may be instantiated; it is not intended to be subclassed.
33  * </p>
34  * @see IStorage
35  * @since 3.0
36  */

37 public class LocalFileStorage extends PlatformObject implements IStorage {
38     
39     /**
40      * The file this storage refers to.
41      */

42     private File JavaDoc fFile;
43         
44     /**
45      * Constructs and returns storage for the given file.
46      *
47      * @param file a local file
48      */

49     public LocalFileStorage(File JavaDoc file){
50         setFile(file);
51     }
52     
53     /* (non-Javadoc)
54      * @see org.eclipse.core.resources.IStorage#getContents()
55      */

56     public InputStream JavaDoc getContents() throws CoreException {
57         try {
58             return new FileInputStream JavaDoc(getFile());
59         } catch (IOException JavaDoc e){
60             throw new CoreException(new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(), DebugPlugin.INTERNAL_ERROR, SourceLookupMessages.LocalFileStorage_0, e));
61         }
62     }
63     
64     /* (non-Javadoc)
65      * @see org.eclipse.core.resources.IStorage#getFullPath()
66      */

67     public IPath getFullPath() {
68         try {
69             return new Path(getFile().getCanonicalPath());
70         } catch (IOException JavaDoc e) {
71             DebugPlugin.log(e);
72             return null;
73         }
74     }
75
76     /* (non-Javadoc)
77      * @see org.eclipse.core.resources.IStorage#getName()
78      */

79     public String JavaDoc getName() {
80         return getFile().getName();
81     }
82
83     /* (non-Javadoc)
84      * @see org.eclipse.core.resources.IStorage#isReadOnly()
85      */

86     public boolean isReadOnly() {
87         return true;
88     }
89     
90     /**
91      * Sets the file associated with this storage
92      *
93      * @param file a local file
94      */

95     private void setFile(File JavaDoc file) {
96         fFile = file;
97     }
98     
99     /**
100      * Returns the file associated with this storage
101      *
102      * @return file
103      */

104     public File JavaDoc getFile() {
105         return fFile;
106     }
107     
108     /* (non-Javadoc)
109      * @see java.lang.Object#equals(java.lang.Object)
110      */

111     public boolean equals(Object JavaDoc object) {
112         return object instanceof LocalFileStorage &&
113              getFile().equals(((LocalFileStorage)object).getFile());
114     }
115     
116     /* (non-Javadoc)
117      * @see java.lang.Object#hashCode()
118      */

119     public int hashCode() {
120         return getFile().hashCode();
121     }
122 }
123
Popular Tags