1 19 package org.netbeans.modules.subversion.ui.history; 20 21 import org.openide.text.CloneableEditorSupport; 22 import org.openide.ErrorManager; 23 import org.netbeans.modules.subversion.VersionsCache; 24 25 import java.io.File ; 26 import java.io.IOException ; 27 import java.io.InputStream ; 28 import java.io.FileInputStream ; 29 import java.util.*; 30 31 36 public abstract class FileEnvironment implements CloneableEditorSupport.Env { 37 38 39 private static final long serialVersionUID = 1L; 40 41 private String mime = "text/plain"; 43 private final File peer; 44 45 private final String revision; 46 47 private transient Date modified; 48 49 50 public FileEnvironment(File baseFile, String revision, String mime) { 51 if (baseFile == null) throw new NullPointerException (); 52 peer = baseFile; 53 modified = new Date(); 54 this.revision = revision; 55 if (mime != null) { 56 this.mime = mime; 57 } 58 } 59 60 public void markModified() throws java.io.IOException { 61 throw new IOException ("r/o"); } 63 64 public void unmarkModified() { 65 } 66 67 public void removePropertyChangeListener(java.beans.PropertyChangeListener propertyChangeListener) { 68 } 69 70 public boolean isModified() { 71 return false; 72 } 73 74 public java.util.Date getTime() { 75 return modified; 76 } 77 78 public void removeVetoableChangeListener(java.beans.VetoableChangeListener vetoableChangeListener) { 79 } 80 81 public boolean isValid() { 82 return true; 83 } 84 85 public java.io.OutputStream outputStream() throws java.io.IOException { 86 throw new IOException ("r/o"); } 88 89 public java.lang.String getMimeType() { 90 return mime; 91 } 92 93 96 public java.io.InputStream inputStream() throws java.io.IOException { 97 return new LazyInputStream(); 98 } 99 100 private class LazyInputStream extends InputStream { 101 102 private InputStream in; 103 104 public LazyInputStream() { 105 } 106 107 private InputStream peer() throws IOException { 108 try { 109 if (in == null) { 110 File remoteFile = VersionsCache.getInstance().getFileRevision(peer, revision); 111 in = new FileInputStream (remoteFile); 112 } 113 return in; 114 } catch (IOException ex) { 115 ErrorManager err = ErrorManager.getDefault(); 116 IOException ioex = new IOException (); 117 err.annotate(ioex, ex); 118 err.annotate(ioex, ErrorManager.USER, null, null, null, null); 119 throw ioex; 120 } 121 } 122 123 public int available() throws IOException { 124 return peer().available(); 125 } 126 127 public void close() throws IOException { 128 peer().close(); 129 } 130 131 public void mark(int readlimit) { 132 } 133 134 public boolean markSupported() { 135 return false; 136 } 137 138 public int read() throws IOException { 139 return peer().read(); 140 } 141 142 public int read(byte b[]) throws IOException { 143 return peer().read(b); 144 } 145 146 public int read(byte b[], int off, int len) throws IOException { 147 return peer().read(b, off, len); 148 } 149 150 public void reset() throws IOException { 151 peer().reset(); 152 } 153 154 public long skip(long n) throws IOException { 155 return peer().skip(n); 156 } 157 158 } 159 160 public void addVetoableChangeListener(java.beans.VetoableChangeListener vetoableChangeListener) { 161 } 162 163 public void addPropertyChangeListener(java.beans.PropertyChangeListener propertyChangeListener) { 164 } 165 166 } 167 | Popular Tags |