Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDani Megert2004-05-27 19:07:12 +0000
committerDani Megert2004-05-27 19:07:12 +0000
commitad77635f17f81adf10f69cc02529cf131882bc4c (patch)
treec8b661b31f781a2d4e2fc17f72b8cde5cd779780 /org.eclipse.core.filebuffers
parent9f72014b1e1e1699b560e87257eed2520b128a8e (diff)
downloadeclipse.platform.text-ad77635f17f81adf10f69cc02529cf131882bc4c.tar.gz
eclipse.platform.text-ad77635f17f81adf10f69cc02529cf131882bc4c.tar.xz
eclipse.platform.text-ad77635f17f81adf10f69cc02529cf131882bc4c.zip
Using new core API
Diffstat (limited to 'org.eclipse.core.filebuffers')
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/AbstractFileBuffer.java30
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/JavaTextFileBuffer.java32
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceTextFileBuffer.java24
3 files changed, 32 insertions, 54 deletions
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/AbstractFileBuffer.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/AbstractFileBuffer.java
index 874a0edde..6be8c2a9e 100644
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/AbstractFileBuffer.java
+++ b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/AbstractFileBuffer.java
@@ -13,7 +13,6 @@ 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;
@@ -34,33 +33,4 @@ public abstract class AbstractFileBuffer implements IFileBuffer {
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);
- }
}
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/JavaTextFileBuffer.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/JavaTextFileBuffer.java
index 378e946ac..4a5415e00 100644
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/JavaTextFileBuffer.java
+++ b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/JavaTextFileBuffer.java
@@ -66,20 +66,23 @@ public class JavaTextFileBuffer extends JavaFileBuffer implements ITextFileBuffe
/**
* Reader chunk size.
*/
- static final private int READER_CHUNK_SIZE= 2048;
+ private static final int READER_CHUNK_SIZE= 2048;
/**
* Buffer size.
*/
- static final private int BUFFER_SIZE= 8 * READER_CHUNK_SIZE;
+ private static final int BUFFER_SIZE= 8 * READER_CHUNK_SIZE;
/**
- * Constant for representing the ok status. This is considered a value object.
+ * Constant for representing the OK status. This is considered a value object.
*/
- static final private IStatus STATUS_OK= new Status(IStatus.OK, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, FileBuffersMessages.getString("FileBuffer.status.ok"), null); //$NON-NLS-1$
+ private static final IStatus STATUS_OK= new Status(IStatus.OK, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, FileBuffersMessages.getString("FileBuffer.status.ok"), null); //$NON-NLS-1$
/**
* Constant for representing the error status. This is considered a value object.
*/
- static final private IStatus STATUS_ERROR= new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.INFO, FileBuffersMessages.getString("FileBuffer.status.error"), null); //$NON-NLS-1$
-
+ private static final IStatus STATUS_ERROR= new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.INFO, FileBuffersMessages.getString("FileBuffer.status.error"), null); //$NON-NLS-1$
+ /**
+ * Constant denoting UTF-8 encoding.
+ */
+ private static final String CHARSET_UTF_8= "UTF-8"; //$NON-NLS-1$
/** The element's document */
@@ -259,7 +262,7 @@ public class JavaTextFileBuffer extends JavaFileBuffer implements ITextFileBuffe
QualifiedName[] options= new QualifiedName[] { IContentDescription.CHARSET, IContentDescription.BYTE_ORDER_MARK };
IContentDescription description= Platform.getContentTypeManager().getDescriptionFor(stream, fFile.getName(), options);
if (description != null) {
- fEncoding= getCharset(description);
+ fEncoding= description.getCharset();
fUTF8BOM= (byte[]) description.getProperty(IContentDescription.BYTE_ORDER_MARK);
if (fUTF8BOM != null && fUTF8BOM != IContentDescription.BOM_UTF_8)
@@ -296,7 +299,7 @@ public class JavaTextFileBuffer extends JavaFileBuffer implements ITextFileBuffe
* This is a workaround for a corresponding bug in Java readers and writer,
* see: http://developer.java.sun.com/developer/bugParade/bugs/4508058.html
*/
- if (fUTF8BOM != null) {
+ if (fUTF8BOM != null && CHARSET_UTF_8.equals(encoding)) {
byte[] bytesWithBOM= new byte[bytes.length + 3];
System.arraycopy(fUTF8BOM, 0, bytesWithBOM, 0, 3);
System.arraycopy(bytes, 0, bytesWithBOM, 3, bytes.length);
@@ -350,11 +353,12 @@ public class JavaTextFileBuffer extends JavaFileBuffer implements ITextFileBuffe
try {
QualifiedName[] options= new QualifiedName[] { IContentDescription.CHARSET, IContentDescription.BYTE_ORDER_MARK };
IContentDescription description= Platform.getContentTypeManager().getDescriptionFor(reader, fFile.getName(), options);
- String encoding= getCharset(description);
- if (encoding != null)
- return encoding;
- else if (fUTF8BOM != null)
- return "UTF-8"; //$NON-NLS-1$
+ if (description != null) {
+ String encoding= description.getCharset();
+ if (encoding != null)
+ return encoding;
+ } else if (fUTF8BOM != null)
+ return CHARSET_UTF_8;
} catch (IOException ex) {
// try next strategy
} finally {
@@ -390,7 +394,7 @@ public class JavaTextFileBuffer extends JavaFileBuffer implements ITextFileBuffe
* see: http://developer.java.sun.com/developer/bugParade/bugs/4508058.html
* </p>
*/
- if (fUTF8BOM != null) {
+ if (fUTF8BOM != null && CHARSET_UTF_8.equals(encoding)) {
contentStream.read();
contentStream.read();
contentStream.read();
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceTextFileBuffer.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceTextFileBuffer.java
index e71f9df3f..9c0caf86a 100644
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceTextFileBuffer.java
+++ b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceTextFileBuffer.java
@@ -75,14 +75,17 @@ public class ResourceTextFileBuffer extends ResourceFileBuffer implements ITextF
*/
static final private QualifiedName ENCODING_KEY= new QualifiedName(FileBuffersPlugin.PLUGIN_ID, "encoding"); //$NON-NLS-1$
/**
- * Constant for representing the ok status. This is considered a value object.
+ * Constant for representing the OK status. This is considered a value object.
*/
static final private IStatus STATUS_OK= new Status(IStatus.OK, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, FileBuffersMessages.getString("FileBuffer.status.ok"), null); //$NON-NLS-1$
/**
* Constant for representing the error status. This is considered a value object.
*/
static final private IStatus STATUS_ERROR= new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.INFO, FileBuffersMessages.getString("FileBuffer.status.error"), null); //$NON-NLS-1$
-
+ /**
+ * Constant denoting UTF-8 encoding.
+ */
+ private static final String CHARSET_UTF_8= "UTF-8"; //$NON-NLS-1$
/** The element's document */
@@ -281,7 +284,7 @@ public class ResourceTextFileBuffer extends ResourceFileBuffer implements ITextF
* - byte order mark is not valid for UTF-8
*/
protected void readUTF8BOM() throws CoreException {
- if ("UTF-8".equals(fEncoding)) { //$NON-NLS-1$
+ if (CHARSET_UTF_8.equals(fEncoding)) {
IContentDescription description= fFile.getContentDescription();
if (description != null) {
fUTF8BOM= (byte[]) description.getProperty(IContentDescription.BYTE_ORDER_MARK);
@@ -323,7 +326,7 @@ public class ResourceTextFileBuffer extends ResourceFileBuffer implements ITextF
* This is a workaround for a corresponding bug in Java readers and writer,
* see: http://developer.java.sun.com/developer/bugParade/bugs/4508058.html
*/
- if (fUTF8BOM != null) {
+ if (fUTF8BOM != null && CHARSET_UTF_8.equals(encoding)) {
byte[] bytesWithBOM= new byte[bytes.length + 3];
System.arraycopy(fUTF8BOM, 0, bytesWithBOM, 0, 3);
System.arraycopy(bytes, 0, bytesWithBOM, 3, bytes.length);
@@ -390,11 +393,12 @@ public class ResourceTextFileBuffer extends ResourceFileBuffer implements ITextF
try {
QualifiedName[] options= new QualifiedName[] { IContentDescription.CHARSET, IContentDescription.BYTE_ORDER_MARK };
IContentDescription description= Platform.getContentTypeManager().getDescriptionFor(reader, fFile.getName(), options);
- String encoding= getCharset(description);
- if (encoding != null)
- return encoding;
- else if (fUTF8BOM != null)
- return "UTF-8"; //$NON-NLS-1$
+ if (description != null) {
+ String encoding= description.getCharset();
+ if (encoding != null)
+ return encoding;
+ } else if (fUTF8BOM != null)
+ return CHARSET_UTF_8;
} catch (IOException ex) {
// try next strategy
} finally {
@@ -486,7 +490,7 @@ public class ResourceTextFileBuffer extends ResourceFileBuffer implements ITextF
* This is a workaround for a corresponding bug in Java readers and writer,
* see: http://developer.java.sun.com/developer/bugParade/bugs/4508058.html
*/
- if (fUTF8BOM != null) {
+ if (fUTF8BOM != null && CHARSET_UTF_8.equals(encoding)) {
contentStream.read();
contentStream.read();
contentStream.read();

Back to the top