Lines 20-25
Link Here
|
20 |
import org.eclipse.core.runtime.IProgressMonitor; |
20 |
import org.eclipse.core.runtime.IProgressMonitor; |
21 |
import org.eclipse.core.runtime.ISafeRunnable; |
21 |
import org.eclipse.core.runtime.ISafeRunnable; |
22 |
import org.eclipse.core.runtime.Platform; |
22 |
import org.eclipse.core.runtime.Platform; |
|
|
23 |
import org.eclipse.core.runtime.content.IContentDescription; |
23 |
import org.eclipse.jdt.core.*; |
24 |
import org.eclipse.jdt.core.*; |
24 |
import org.eclipse.jdt.internal.core.util.Util; |
25 |
import org.eclipse.jdt.internal.core.util.Util; |
25 |
|
26 |
|
Lines 334-339
Link Here
|
334 |
|
335 |
|
335 |
// use a platform operation to update the resource contents |
336 |
// use a platform operation to update the resource contents |
336 |
try { |
337 |
try { |
|
|
338 |
String stringContents = this.getContents(); |
339 |
if (stringContents == null) return; |
340 |
|
341 |
// Get encoding |
337 |
String encoding = null; |
342 |
String encoding = null; |
338 |
try { |
343 |
try { |
339 |
encoding = this.file.getCharset(); |
344 |
encoding = this.file.getCharset(); |
Lines 341-353
Link Here
|
341 |
catch (CoreException ce) { |
346 |
catch (CoreException ce) { |
342 |
// use no encoding |
347 |
// use no encoding |
343 |
} |
348 |
} |
344 |
String stringContents = this.getContents(); |
349 |
|
345 |
if (stringContents == null) return; |
350 |
// Create bytes array |
346 |
byte[] bytes = encoding == null |
351 |
byte[] bytes = encoding == null |
347 |
? stringContents.getBytes() |
352 |
? stringContents.getBytes() |
348 |
: stringContents.getBytes(encoding); |
353 |
: stringContents.getBytes(encoding); |
349 |
ByteArrayInputStream stream = new ByteArrayInputStream(bytes); |
|
|
350 |
|
354 |
|
|
|
355 |
// Special case for UTF-8 BOM files |
356 |
// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=110576 |
357 |
if (encoding.equals(org.eclipse.jdt.internal.compiler.util.Util.UTF_8)) { //$NON-NLS-1$ |
358 |
IContentDescription description = this.file.getContentDescription(); |
359 |
if (description != null && description.getProperty(IContentDescription.BYTE_ORDER_MARK) != null) { |
360 |
int bomLength= IContentDescription.BOM_UTF_8.length; |
361 |
byte[] bytesWithBOM= new byte[bytes.length + bomLength]; |
362 |
System.arraycopy(IContentDescription.BOM_UTF_8, 0, bytesWithBOM, 0, bomLength); |
363 |
System.arraycopy(bytes, 0, bytesWithBOM, bomLength, bytes.length); |
364 |
bytes= bytesWithBOM; |
365 |
} |
366 |
} |
367 |
|
368 |
// Set file contents |
369 |
ByteArrayInputStream stream = new ByteArrayInputStream(bytes); |
351 |
if (this.file.exists()) { |
370 |
if (this.file.exists()) { |
352 |
this.file.setContents( |
371 |
this.file.setContents( |
353 |
stream, |
372 |
stream, |