KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > RemoteAnnotationStorage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.ccvs.ui;
12
13 import java.io.IOException JavaDoc;
14 import java.io.InputStream JavaDoc;
15
16 import org.eclipse.core.resources.IEncodedStorage;
17 import org.eclipse.core.resources.IResourceStatus;
18 import org.eclipse.core.runtime.*;
19 import org.eclipse.osgi.util.NLS;
20 import org.eclipse.team.core.TeamException;
21 import org.eclipse.team.internal.ccvs.core.*;
22 import org.eclipse.team.internal.core.TeamPlugin;
23
24 public class RemoteAnnotationStorage extends PlatformObject implements IEncodedStorage {
25
26     private InputStream JavaDoc contents;
27     private ICVSRemoteFile file;
28     
29     public RemoteAnnotationStorage(ICVSRemoteFile file, InputStream JavaDoc contents) {
30         this.file = file;
31         this.contents = contents;
32     }
33
34     public InputStream JavaDoc getContents() throws CoreException {
35         try {
36             // Contents are a ByteArrayInputStream which can be reset to the beginning
37
contents.reset();
38         } catch (IOException JavaDoc e) {
39             CVSUIPlugin.log(CVSException.wrapException(e));
40         }
41         return contents;
42     }
43
44     public String JavaDoc getCharset() throws CoreException {
45         InputStream JavaDoc contents = getContents();
46         try {
47             String JavaDoc charSet = TeamPlugin.getCharset(getName(), contents);
48             return charSet;
49         } catch (IOException JavaDoc e) {
50             throw new CVSException(new Status(IStatus.ERROR, CVSUIPlugin.ID, IResourceStatus.FAILED_DESCRIBING_CONTENTS, NLS.bind(CVSUIMessages.RemoteAnnotationStorage_1, (new String JavaDoc[] { getFullPath().toString() })), e));
51         } finally {
52             try {
53                 contents.close();
54             } catch (IOException JavaDoc e1) {
55                 // Ignore
56
}
57         }
58     }
59
60     public IPath getFullPath() {
61         ICVSRepositoryLocation location = file.getRepository();
62         IPath path = new Path(null, location.getRootDirectory());
63         path = path.setDevice(location.getHost() + IPath.DEVICE_SEPARATOR);
64         // see bug 176809
65
String JavaDoc revision = ""; //$NON-NLS-1$
66
try {
67             revision = ' ' + file.getRevision();
68         } catch (TeamException e) {
69             //ignore
70
}
71         path = path.append(file.getRepositoryRelativePath() + revision);
72         return path;
73     }
74     public String JavaDoc getName() {
75         return file.getName();
76     }
77     public boolean isReadOnly() {
78         return true;
79     }
80 }
81
Popular Tags