Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,9 @@ public void setInput(Object input) {
if (fComposite != null && input instanceof ICompareInput) {
fInput= (ICompareInput) input;

InputStream left= null;
InputStream right= null;

String message= null;
try {
left= getStream(fInput.getLeft());
right= getStream(fInput.getRight());
try (InputStream left = getStream(fInput.getLeft()); InputStream right = getStream(fInput.getRight())) {

if (left != null && right != null) {
int pos= 0;
Expand Down Expand Up @@ -117,9 +113,6 @@ public void setInput(Object input) {
} catch (CoreException | IOException ex) {
message = Utilities.getString(fBundle, "errorMessage"); //$NON-NLS-1$
CompareUIPlugin.log(ex);
} finally {
Utilities.close(left);
Utilities.close(right);
}
if (message != null) {
fMessage.setText(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*******************************************************************************/
package org.eclipse.compare.internal;

import static java.nio.charset.StandardCharsets.UTF_16;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
Expand Down Expand Up @@ -60,7 +62,6 @@
public class ComparePreferencePage extends PreferencePage implements IWorkbenchPreferencePage {

private static class FakeInput implements ITypedElement, IEncodedStreamContentAccessor {
static final String UTF_16= "UTF-16"; //$NON-NLS-1$
String fContent;

FakeInput(String name) {
Expand All @@ -80,11 +81,11 @@ public String getType() {
}
@Override
public InputStream getContents() {
return new ByteArrayInputStream(Utilities.getBytes(fContent, UTF_16));
return new ByteArrayInputStream(fContent.getBytes(UTF_16));
}
@Override
public String getCharset() {
return UTF_16;
return UTF_16.name();
}

private String loadPreviewContentFromFile(String key) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2011 IBM Corporation and others.
* Copyright (c) 2000, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -13,6 +13,8 @@
*******************************************************************************/
package org.eclipse.compare.internal;

import static java.nio.charset.StandardCharsets.UTF_16;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
Expand Down Expand Up @@ -57,7 +59,6 @@ public class EditionAction extends BaseCompareAction {
* for a Document.
*/
static class DocumentBufferNode implements ITypedElement, IEncodedStreamContentAccessor {
private static final String UTF_16= "UTF-16"; //$NON-NLS-1$
private final IDocument fDocument;
private final IFile fFile;

Expand All @@ -83,12 +84,12 @@ public Image getImage() {

@Override
public InputStream getContents() {
return new ByteArrayInputStream(Utilities.getBytes(fDocument.get(), UTF_16));
return new ByteArrayInputStream(fDocument.get().getBytes(UTF_16));
}

@Override
public String getCharset() {
return UTF_16;
return UTF_16.name();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2017 IBM Corporation and others.
* Copyright (c) 2000, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -358,22 +358,14 @@ public static String getString(String key) {
}
}

public static String getFormattedString(String key, String arg) {
public static String getFormattedString(String key, Object... arg) {
try {
return MessageFormat.format(CompareUI.getResourceBundle().getString(key), arg);
} catch (MissingResourceException e) {
return "!" + key + "!"; //$NON-NLS-2$ //$NON-NLS-1$
}
}

public static String getFormattedString(String key, String arg0, String arg1) {
try {
return MessageFormat.format(CompareUI.getResourceBundle().getString(key), arg0, arg1);
} catch (MissingResourceException e) {
return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
}
}

public static String getString(ResourceBundle bundle, String key) {
return getString(bundle, key, key);
}
Expand Down Expand Up @@ -652,18 +644,6 @@ public static String getCharset(Object resource) {
return ResourcesPlugin.getEncoding();
}

public static byte[] getBytes(String s, String encoding) {
byte[] bytes= null;
if (s != null) {
try {
bytes= s.getBytes(encoding);
} catch (UnsupportedEncodingException e) {
bytes= s.getBytes();
}
}
return bytes;
}

public static String readString(IStreamContentAccessor sa) throws CoreException {
String encoding= null;
if (sa instanceof IEncodedStreamContentAccessor) {
Expand All @@ -675,16 +655,6 @@ public static String readString(IStreamContentAccessor sa) throws CoreException
return Utilities.readString(sa, encoding);
}

public static void close(InputStream is) {
if (is != null) {
try {
is.close();
} catch (IOException ex) {
// silently ignored
}
}
}

public static IResource getFirstResource(ISelection selection) {
IResource[] resources = getResources(selection);
if (resources.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2011 IBM Corporation and others.
* Copyright (c) 2000, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -13,6 +13,8 @@
*******************************************************************************/
package org.eclipse.compare.structuremergeviewer;

import static java.nio.charset.StandardCharsets.UTF_16;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
Expand Down Expand Up @@ -65,7 +67,6 @@
public class DocumentRangeNode
implements IDocumentRange, IStructureComparator, IEditableContent,
IEncodedStreamContentAccessor, IAdaptable, IEditableContentExtension {
private static final String UTF_16= "UTF-16"; //$NON-NLS-1$

private final IDocument fBaseDocument;
private Position fRange; // the range in the base document
Expand Down Expand Up @@ -347,7 +348,7 @@ public InputStream getContents() {
} catch (BadLocationException ex) {
s= ""; //$NON-NLS-1$
}
return new ByteArrayInputStream(Utilities.getBytes(s, UTF_16));
return new ByteArrayInputStream(s.getBytes(UTF_16));
}


Expand Down Expand Up @@ -419,7 +420,7 @@ protected void internalSetContents(byte[] content) {

@Override
public String getCharset() {
return UTF_16;
return UTF_16.name();
}

/**
Expand Down
Loading