KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > subversion > ui > history > FileEnvironment


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

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 JavaDoc;
26 import java.io.IOException JavaDoc;
27 import java.io.InputStream JavaDoc;
28 import java.io.FileInputStream JavaDoc;
29 import java.util.*;
30
31 /**
32  * Defines numb read-only File environment.
33  *
34  * @author Maros Sandor
35  */

36 public abstract class FileEnvironment implements CloneableEditorSupport.Env {
37
38     /** Serial Version UID */
39     private static final long serialVersionUID = 1L;
40     
41     private String JavaDoc mime = "text/plain"; // NOI18N
42

43     private final File JavaDoc peer;
44
45     private final String JavaDoc revision;
46
47     private transient Date modified;
48         
49     /** Creates new StreamEnvironment */
50     public FileEnvironment(File JavaDoc baseFile, String JavaDoc revision, String JavaDoc mime) {
51         if (baseFile == null) throw new NullPointerException JavaDoc();
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 JavaDoc {
61         throw new IOException JavaDoc("r/o"); // NOI18N
62
}
63     
64     public void unmarkModified() {
65     }
66
67     public void removePropertyChangeListener(java.beans.PropertyChangeListener JavaDoc propertyChangeListener) {
68     }
69     
70     public boolean isModified() {
71         return false;
72     }
73     
74     public java.util.Date JavaDoc getTime() {
75         return modified;
76     }
77     
78     public void removeVetoableChangeListener(java.beans.VetoableChangeListener JavaDoc vetoableChangeListener) {
79     }
80     
81     public boolean isValid() {
82         return true;
83     }
84     
85     public java.io.OutputStream JavaDoc outputStream() throws java.io.IOException JavaDoc {
86         throw new IOException JavaDoc("r/o"); // NOI18N
87
}
88
89     public java.lang.String JavaDoc getMimeType() {
90         return mime;
91     }
92
93     /**
94      * Always return fresh stream.
95      */

96     public java.io.InputStream JavaDoc inputStream() throws java.io.IOException JavaDoc {
97         return new LazyInputStream();
98     }
99
100     private class LazyInputStream extends InputStream JavaDoc {
101
102         private InputStream JavaDoc in;
103
104         public LazyInputStream() {
105         }
106
107         private InputStream JavaDoc peer() throws IOException JavaDoc {
108             try {
109                 if (in == null) {
110                     File JavaDoc remoteFile = VersionsCache.getInstance().getFileRevision(peer, revision);
111                     in = new FileInputStream JavaDoc(remoteFile);
112                 }
113                 return in;
114             } catch (IOException JavaDoc ex) {
115                 ErrorManager err = ErrorManager.getDefault();
116                 IOException JavaDoc ioex = new IOException JavaDoc();
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 JavaDoc {
124             return peer().available();
125         }
126
127         public void close() throws IOException JavaDoc {
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 JavaDoc {
139             return peer().read();
140         }
141
142         public int read(byte b[]) throws IOException JavaDoc {
143             return peer().read(b);
144         }
145
146         public int read(byte b[], int off, int len) throws IOException JavaDoc {
147             return peer().read(b, off, len);
148         }
149
150         public void reset() throws IOException JavaDoc {
151             peer().reset();
152         }
153
154         public long skip(long n) throws IOException JavaDoc {
155             return peer().skip(n);
156         }
157
158     }
159
160     public void addVetoableChangeListener(java.beans.VetoableChangeListener JavaDoc vetoableChangeListener) {
161     }
162     
163     public void addPropertyChangeListener(java.beans.PropertyChangeListener JavaDoc propertyChangeListener) {
164     }
165             
166 }
167
Popular Tags