Adding Git source, NetBeans project files, GPL v2 LICENSE, ant build file.
[nbgit.git] / src / org / netbeans / modules / git / ui / log / FileEnvironment.java
blobc0856a67d2752a4e715bcac98b2047776fbc6182
1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common
8 * Development and Distribution License("CDDL") (collectively, the
9 * "License"). You may not use this file except in compliance with the
10 * License. You can obtain a copy of the License at
11 * http://www.netbeans.org/cddl-gplv2.html
12 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13 * specific language governing permissions and limitations under the
14 * License. When distributing the software, include this License Header
15 * Notice in each file and include the License file at
16 * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17 * particular file as subject to the "Classpath" exception as provided
18 * by Sun in the GPL Version 2 section of the License file that
19 * accompanied this code. If applicable, add the following below the
20 * License Header, with the fields enclosed by brackets [] replaced by
21 * your own identifying information:
22 * "Portions Copyrighted [year] [name of copyright owner]"
24 * Contributor(s):
26 * The Original Software is NetBeans. The Initial Developer of the Original
27 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28 * Microsystems, Inc. All Rights Reserved.
29 * Portions Copyright 2008 Alexander Coles (Ikonoklastik Productions).
31 * If you wish your version of this file to be governed by only the CDDL
32 * or only the GPL Version 2, indicate your decision by adding
33 * "[Contributor] elects to include this software in this distribution
34 * under the [CDDL or GPL Version 2] license." If you do not indicate a
35 * single choice of license, a recipient has the option to distribute
36 * your version of this file under either the CDDL, the GPL Version 2 or
37 * to extend the choice of license to its licensees as provided above.
38 * However, if you add GPL Version 2 code and therefore, elected the GPL
39 * Version 2 license, then the option applies only if the new code is
40 * made subject to such option by the copyright holder.
42 package org.netbeans.modules.git.ui.log;
44 import java.io.File;
45 import java.io.FileInputStream;
46 import java.io.IOException;
47 import java.io.InputStream;
48 import java.util.Date;
49 import org.netbeans.modules.git.VersionsCache;
50 import org.openide.ErrorManager;
51 import org.openide.text.CloneableEditorSupport;
54 /**
55 * Defines numb read-only File environment.
57 * @author Maros Sandor
59 public abstract class FileEnvironment implements CloneableEditorSupport.Env {
61 /** Serial Version UID */
62 private static final long serialVersionUID = 1L;
64 private String mime = "text/plain"; // NOI18N
66 private final File peer;
68 private final String revision;
70 private transient Date modified;
72 /** Creates new StreamEnvironment */
73 public FileEnvironment(File baseFile, String revision, String mime) {
74 if (baseFile == null) throw new NullPointerException();
75 peer = baseFile;
76 modified = new Date();
77 this.revision = revision;
78 if (mime != null) {
79 this.mime = mime;
83 public void markModified() throws java.io.IOException {
84 throw new IOException("r/o"); // NOI18N
87 public void unmarkModified() {
90 public void removePropertyChangeListener(java.beans.PropertyChangeListener propertyChangeListener) {
93 public boolean isModified() {
94 return false;
97 public java.util.Date getTime() {
98 return modified;
101 public void removeVetoableChangeListener(java.beans.VetoableChangeListener vetoableChangeListener) {
104 public boolean isValid() {
105 return true;
108 public java.io.OutputStream outputStream() throws java.io.IOException {
109 throw new IOException("r/o"); // NOI18N
112 public java.lang.String getMimeType() {
113 return mime;
117 * Always return fresh stream.
119 public java.io.InputStream inputStream() throws java.io.IOException {
120 return new LazyInputStream();
123 private class LazyInputStream extends InputStream {
125 private InputStream in;
127 public LazyInputStream() {
130 private InputStream peer() throws IOException {
131 try {
132 if (in == null) {
133 File remoteFile = VersionsCache.getInstance().getFileRevision(peer, revision);
134 in = new FileInputStream(remoteFile);
136 return in;
137 } catch (IOException ex) {
138 ErrorManager err = ErrorManager.getDefault();
139 IOException ioex = new IOException();
140 err.annotate(ioex, ex);
141 err.annotate(ioex, ErrorManager.USER, null, null, null, null);
142 throw ioex;
146 @Override
147 public int available() throws IOException {
148 return peer().available();
151 @Override
152 public void close() throws IOException {
153 peer().close();
156 @Override
157 public void mark(int readlimit) {
160 @Override
161 public boolean markSupported() {
162 return false;
165 public int read() throws IOException {
166 return peer().read();
169 @Override
170 public int read(byte b[]) throws IOException {
171 return peer().read(b);
174 @Override
175 public int read(byte b[], int off, int len) throws IOException {
176 return peer().read(b, off, len);
179 @Override
180 public void reset() throws IOException {
181 peer().reset();
184 @Override
185 public long skip(long n) throws IOException {
186 return peer().skip(n);
191 public void addVetoableChangeListener(java.beans.VetoableChangeListener vetoableChangeListener) {
194 public void addPropertyChangeListener(java.beans.PropertyChangeListener propertyChangeListener) {