1 19 package org.netbeans.modules.versioning.system.cvss.ui.history; 20 21 import java.io.*; 22 import java.net.*; 23 import java.util.*; 24 25 import org.openide.text.*; 26 import org.openide.ErrorManager; 27 import org.netbeans.modules.versioning.system.cvss.VersionsCache; 28 import org.netbeans.modules.versioning.system.cvss.IllegalCommandException; 29 import org.netbeans.modules.versioning.system.cvss.NotVersionedException; 30 import org.netbeans.lib.cvsclient.command.CommandException; 31 import org.netbeans.lib.cvsclient.connection.AuthenticationException; 32 33 34 39 public abstract class FileEnvironment implements CloneableEditorSupport.Env { 40 41 42 private static final long serialVersionUID = 1L; 43 44 private String mime = "text/plain"; 46 private final File peer; 47 48 private final String revision; 49 50 private transient Date modified; 51 52 53 public FileEnvironment(File baseFile, String revision, String mime) { 54 if (baseFile == null) throw new NullPointerException (); 55 peer = baseFile; 56 modified = new Date(); 57 this.revision = revision; 58 if (mime != null) { 59 this.mime = mime; 60 } 61 } 62 63 public void markModified() throws java.io.IOException { 64 throw new IOException("r/o"); } 66 67 public void unmarkModified() { 68 } 69 70 public void removePropertyChangeListener(java.beans.PropertyChangeListener propertyChangeListener) { 71 } 72 73 public boolean isModified() { 74 return false; 75 } 76 77 public java.util.Date getTime() { 78 return modified; 79 } 80 81 public void removeVetoableChangeListener(java.beans.VetoableChangeListener vetoableChangeListener) { 82 } 83 84 public boolean isValid() { 85 return true; 86 } 87 88 public java.io.OutputStream outputStream() throws java.io.IOException { 89 throw new IOException("r/o"); } 91 92 public java.lang.String getMimeType() { 93 return mime; 94 } 95 96 99 public java.io.InputStream inputStream() throws java.io.IOException { 100 return new LazyInputStream(); 101 } 102 103 private class LazyInputStream extends InputStream { 104 105 private InputStream in; 106 107 public LazyInputStream() { 108 } 109 110 private InputStream peer() throws IOException { 111 try { 112 if (in == null) { 113 File remoteFile = VersionsCache.getInstance().getRemoteFile(peer, revision, null); 114 in = new FileInputStream(remoteFile); 115 } 116 return in; 117 } catch (MalformedURLException ex) { 118 ErrorManager err = ErrorManager.getDefault(); 119 IOException ioex = new IOException(); 120 err.annotate(ioex, ex); 121 err.annotate(ioex, ErrorManager.USER, null, null, null, null); 122 throw ioex; 123 } catch (IOException ex) { 124 ErrorManager err = ErrorManager.getDefault(); 125 IOException ioex = new IOException(); 126 err.annotate(ioex, ex); 127 err.annotate(ioex, ErrorManager.USER, null, null, null, null); 128 throw ioex; 129 } catch (CommandException ex) { 130 ErrorManager err = ErrorManager.getDefault(); 131 IOException ioex = new IOException(); 132 err.annotate(ioex, ex); 133 err.annotate(ioex, ErrorManager.USER, null, null, null, null); 134 throw ioex; 135 } catch (IllegalCommandException ex) { 136 ErrorManager err = ErrorManager.getDefault(); 137 IOException ioex = new IOException(); 138 err.annotate(ioex, ex); 139 err.annotate(ioex, ErrorManager.USER, null, null, null, null); 140 throw ioex; 141 } catch (AuthenticationException ex) { 142 ErrorManager err = ErrorManager.getDefault(); 143 IOException ioex = new IOException(); 144 err.annotate(ioex, ex); 145 err.annotate(ioex, ErrorManager.USER, null, null, null, null); 146 throw ioex; 147 } catch (NotVersionedException ex) { 148 ErrorManager err = ErrorManager.getDefault(); 149 IOException ioex = new IOException(); 150 err.annotate(ioex, ex); 151 err.annotate(ioex, ErrorManager.USER, null, null, null, null); 152 throw ioex; 153 } 154 } 155 156 public int available() throws IOException { 157 return peer().available(); 158 } 159 160 public void close() throws IOException { 161 peer().close(); 162 } 163 164 public void mark(int readlimit) { 165 } 166 167 public boolean markSupported() { 168 return false; 169 } 170 171 public int read() throws IOException { 172 return peer().read(); 173 } 174 175 public int read(byte b[]) throws IOException { 176 return peer().read(b); 177 } 178 179 public int read(byte b[], int off, int len) throws IOException { 180 return peer().read(b, off, len); 181 } 182 183 public void reset() throws IOException { 184 peer().reset(); 185 } 186 187 public long skip(long n) throws IOException { 188 return peer().skip(n); 189 } 190 191 } 192 193 public void addVetoableChangeListener(java.beans.VetoableChangeListener vetoableChangeListener) { 194 } 195 196 public void addPropertyChangeListener(java.beans.PropertyChangeListener propertyChangeListener) { 197 } 198 199 } 200 | Popular Tags |