Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 874a0eddecf8d698d700c3738c41d0959270a813 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**********************************************************************
Copyright (c) 2000, 2003 IBM Corp. and others.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Common Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/cpl-v10.html

Contributors:
	IBM Corporation - Initial implementation
**********************************************************************/
package org.eclipse.core.internal.filebuffers;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.content.IContentDescription;

import org.eclipse.core.filebuffers.IFileBuffer;

/**
 * @since 3.0
 */
public abstract class AbstractFileBuffer implements IFileBuffer {
	
	
	public abstract void create(IPath location, IProgressMonitor monitor) throws CoreException;
	
	public abstract void connect();
	
	public abstract void disconnect() throws CoreException;
	
	public abstract boolean isDisposed();

	public abstract void requestSynchronizationContext();
	
	public abstract void releaseSynchronizationContext();

	
	/**
	 * Helper method which computes the encoding out of the given description.
	 * <p>
	 * XXX:
	 * This method should be provided by Platform Core
	 * see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=64342
	 * </p>
	 * 
	 * @param description the content description
	 * @return the encoding
	 * @see org.eclipse.core.resources.IFile#getCharset()
	 */
	static String getCharset(IContentDescription description) {
		if (description == null)
			return null;
		byte[] bom= (byte[]) description.getProperty(IContentDescription.BYTE_ORDER_MARK);
		if (bom != null)
			if (bom == IContentDescription.BOM_UTF_8)
				return "UTF-8"; //$NON-NLS-1$
			else if (bom == IContentDescription.BOM_UTF_16BE || bom == IContentDescription.BOM_UTF_16LE)
				// UTF-16 will properly detect the BOM
				return "UTF-16"; //$NON-NLS-1$
			else {
				// unknown BOM... ignore it				
			}
		return (String)description.getProperty(IContentDescription.CHARSET);
	}
}

Back to the top