2 * Created on 06.09.2003
4 * To change the template for this generated file go to
5 * Window>Preferences>Java>Code Generation>Code and Comments
7 package net.sourceforge.phpeclipse.builder;
10 import java.io.FileInputStream;
11 import java.io.FileNotFoundException;
12 import java.io.FileOutputStream;
13 import java.io.IOException;
14 import java.io.InputStream;
16 import net.sourceforge.phpdt.internal.ui.util.StreamUtil;
17 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
19 import org.eclipse.core.resources.IStorage;
20 import org.eclipse.core.runtime.CoreException;
21 import org.eclipse.core.runtime.IPath;
22 import org.eclipse.core.runtime.IProgressMonitor;
23 import org.eclipse.core.runtime.IStatus;
24 import org.eclipse.core.runtime.PlatformObject;
25 import org.eclipse.core.runtime.Status;
28 * (c) Copyright QNX Software Systems Ltd. 2002.
29 * All Rights Reserved.
36 public class FileStorage extends PlatformObject implements IStorage {
37 private boolean forceReadOnly;
38 private final IPath path;
39 private final File file;
42 * Two FileStorages are equal if their IPaths are equal.
43 * @see java.lang.Object#equals(java.lang.Object)
45 public boolean equals(Object obj) {
48 if (!(obj instanceof FileStorage))
50 FileStorage other = (FileStorage) obj;
51 return path.equals(other.path);
55 * @see org.eclipse.core.resources.IStorage#getContents()
57 public InputStream getContents() throws CoreException {
59 return new FileInputStream(file);
60 } catch (FileNotFoundException e) {
61 throw new CoreException(new Status(IStatus.ERROR, PHPeclipsePlugin.PLUGIN_ID, IStatus.ERROR, e.toString(), e));
66 * @see org.eclipse.core.resources.IStorage#getFullPath()
68 public IPath getFullPath() {
73 * @see org.eclipse.core.resources.IStorage#getName()
75 public String getName() {
76 return this.path.lastSegment();
80 * @see org.eclipse.core.resources.IStorage#isReadOnly()
82 public boolean isReadOnly() {
83 return forceReadOnly || !file.canWrite();
90 public FileStorage(IPath path) {
92 this.file = path.toFile();
96 * @see java.lang.Object#toString()
98 public String toString() {
99 return path.toOSString();
108 public void setContents(InputStream stream, boolean overwrite, boolean b, IProgressMonitor monitor) throws CoreException {
110 StreamUtil.transferStreams(stream, new FileOutputStream(file));
111 } catch (FileNotFoundException e) {
112 throw new CoreException(new Status(IStatus.ERROR, PHPeclipsePlugin.PLUGIN_ID, IStatus.ERROR, e.toString(), e));
113 } catch (IOException e) {
114 throw new CoreException(new Status(IStatus.ERROR, PHPeclipsePlugin.PLUGIN_ID, IStatus.ERROR, e.toString(), e));
119 * Some document providers (notably CompilationUnitDocumentProvider)
120 * can't handle read/write storage.
122 public void setReadOnly() {
123 forceReadOnly = true;