1 package net.sourceforge.phpeclipse.builder;
4 import java.io.FileInputStream;
5 import java.io.FileNotFoundException;
6 import java.io.FileOutputStream;
7 import java.io.IOException;
8 import java.io.InputStream;
10 //import net.sourceforge.;
11 import net.sourceforge.phpdt.internal.ui.util.StreamUtil;
12 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
14 import org.eclipse.core.resources.IStorage;
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.IPath;
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.eclipse.core.runtime.IStatus;
19 import org.eclipse.core.runtime.PlatformObject;
20 import org.eclipse.core.runtime.Status;
23 * (c) Copyright QNX Software Systems Ltd. 2002.
24 * All Rights Reserved.
31 public class FileStorage extends PlatformObject implements IStorage {
32 private boolean forceReadOnly;
34 private final IPath path;
36 private final File file;
39 * Two FileStorages are equal if their IPaths are equal.
41 * @see java.lang.Object#equals(java.lang.Object)
43 public boolean equals(Object obj) {
46 if (!(obj instanceof FileStorage))
48 FileStorage other = (FileStorage) obj;
49 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,
62 PHPeclipsePlugin.PLUGIN_ID, IStatus.ERROR, e.toString(), e));
69 * @see org.eclipse.core.resources.IStorage#getFullPath()
71 public IPath getFullPath() {
78 * @see org.eclipse.core.resources.IStorage#getName()
80 public String getName() {
81 return this.path.lastSegment();
87 * @see org.eclipse.core.resources.IStorage#isReadOnly()
89 public boolean isReadOnly() {
90 return forceReadOnly || !file.canWrite();
98 public FileStorage(IPath path) {
100 this.file = path.toFile();
106 * @see java.lang.Object#toString()
108 public String toString() {
109 return path.toOSString();
118 public void setContents(InputStream stream, boolean overwrite, boolean b,
119 IProgressMonitor monitor) throws CoreException {
121 StreamUtil.transferStreams(stream, new FileOutputStream(file));
122 } catch (FileNotFoundException e) {
123 throw new CoreException(new Status(IStatus.ERROR,
124 PHPeclipsePlugin.PLUGIN_ID, IStatus.ERROR, e.toString(), e));
125 } catch (IOException e) {
126 throw new CoreException(new Status(IStatus.ERROR,
127 PHPeclipsePlugin.PLUGIN_ID, IStatus.ERROR, e.toString(), e));
132 * Some document providers (notably CompilationUnitDocumentProvider) can't
133 * handle read/write storage.
135 public void setReadOnly() {
136 forceReadOnly = true;