KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > SystemFileStorage


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.pde.internal.ui.editor;
12
13 import java.io.File JavaDoc;
14 import java.io.FileInputStream JavaDoc;
15 import java.io.FileNotFoundException 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.pde.internal.ui.PDEPlugin;
26
27 public class SystemFileStorage extends PlatformObject implements IStorage {
28     private File JavaDoc file;
29     /**
30      * Constructor for SystemFileStorage.
31      */

32     public SystemFileStorage(File JavaDoc file) {
33         this.file = file;
34     }
35
36     public File JavaDoc getFile() {
37         return file;
38     }
39     public InputStream JavaDoc getContents() throws CoreException {
40         try {
41             return new FileInputStream JavaDoc(file);
42         } catch (FileNotFoundException JavaDoc e) {
43             IStatus status =
44                 new Status(IStatus.ERROR, PDEPlugin.getPluginId(), IStatus.OK, null, e);
45             throw new CoreException(status);
46         }
47     }
48     public IPath getFullPath() {
49         return new Path(file.getAbsolutePath());
50     }
51     public String JavaDoc getName() {
52         return file.getName();
53     }
54     public boolean isReadOnly() {
55         return true;
56     }
57
58     public boolean equals(Object JavaDoc object) {
59         return object instanceof SystemFileStorage
60             && getFile().equals(((SystemFileStorage) object).getFile());
61     }
62
63     public int hashCode() {
64         return getFile().hashCode();
65     }
66 }
67
Popular Tags