Skip to content

Commit 0029076

Browse files
committed
Remove useless internal utilities in o.e.compare
Newer Java versions have constructs and APIs that make these useless.
1 parent 8895728 commit 0029076

File tree

5 files changed

+17
-51
lines changed

5 files changed

+17
-51
lines changed

team/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/BinaryCompareViewer.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,9 @@ public void setInput(Object input) {
8282
if (fComposite != null && input instanceof ICompareInput) {
8383
fInput= (ICompareInput) input;
8484

85-
InputStream left= null;
86-
InputStream right= null;
8785

8886
String message= null;
89-
try {
90-
left= getStream(fInput.getLeft());
91-
right= getStream(fInput.getRight());
87+
try (InputStream left = getStream(fInput.getLeft()); InputStream right = getStream(fInput.getRight())) {
9288

9389
if (left != null && right != null) {
9490
int pos= 0;
@@ -117,9 +113,6 @@ public void setInput(Object input) {
117113
} catch (CoreException | IOException ex) {
118114
message = Utilities.getString(fBundle, "errorMessage"); //$NON-NLS-1$
119115
CompareUIPlugin.log(ex);
120-
} finally {
121-
Utilities.close(left);
122-
Utilities.close(right);
123116
}
124117
if (message != null) {
125118
fMessage.setText(message);

team/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ComparePreferencePage.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*******************************************************************************/
1616
package org.eclipse.compare.internal;
1717

18+
import static java.nio.charset.StandardCharsets.UTF_16;
19+
1820
import java.io.ByteArrayInputStream;
1921
import java.io.InputStream;
2022
import java.util.ArrayList;
@@ -60,7 +62,6 @@
6062
public class ComparePreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
6163

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

6667
FakeInput(String name) {
@@ -80,11 +81,11 @@ public String getType() {
8081
}
8182
@Override
8283
public InputStream getContents() {
83-
return new ByteArrayInputStream(Utilities.getBytes(fContent, UTF_16));
84+
return new ByteArrayInputStream(fContent.getBytes(UTF_16));
8485
}
8586
@Override
8687
public String getCharset() {
87-
return UTF_16;
88+
return UTF_16.name();
8889
}
8990

9091
private String loadPreviewContentFromFile(String key) {

team/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/EditionAction.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2011 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -13,6 +13,8 @@
1313
*******************************************************************************/
1414
package org.eclipse.compare.internal;
1515

16+
import static java.nio.charset.StandardCharsets.UTF_16;
17+
1618
import java.io.ByteArrayInputStream;
1719
import java.io.InputStream;
1820
import java.lang.reflect.InvocationTargetException;
@@ -57,7 +59,6 @@ public class EditionAction extends BaseCompareAction {
5759
* for a Document.
5860
*/
5961
static class DocumentBufferNode implements ITypedElement, IEncodedStreamContentAccessor {
60-
private static final String UTF_16= "UTF-16"; //$NON-NLS-1$
6162
private final IDocument fDocument;
6263
private final IFile fFile;
6364

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

8485
@Override
8586
public InputStream getContents() {
86-
return new ByteArrayInputStream(Utilities.getBytes(fDocument.get(), UTF_16));
87+
return new ByteArrayInputStream(fDocument.get().getBytes(UTF_16));
8788
}
8889

8990
@Override
9091
public String getCharset() {
91-
return UTF_16;
92+
return UTF_16.name();
9293
}
9394
}
9495

team/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2017 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -358,22 +358,14 @@ public static String getString(String key) {
358358
}
359359
}
360360

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

369-
public static String getFormattedString(String key, String arg0, String arg1) {
370-
try {
371-
return MessageFormat.format(CompareUI.getResourceBundle().getString(key), arg0, arg1);
372-
} catch (MissingResourceException e) {
373-
return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
374-
}
375-
}
376-
377369
public static String getString(ResourceBundle bundle, String key) {
378370
return getString(bundle, key, key);
379371
}
@@ -652,18 +644,6 @@ public static String getCharset(Object resource) {
652644
return ResourcesPlugin.getEncoding();
653645
}
654646

655-
public static byte[] getBytes(String s, String encoding) {
656-
byte[] bytes= null;
657-
if (s != null) {
658-
try {
659-
bytes= s.getBytes(encoding);
660-
} catch (UnsupportedEncodingException e) {
661-
bytes= s.getBytes();
662-
}
663-
}
664-
return bytes;
665-
}
666-
667647
public static String readString(IStreamContentAccessor sa) throws CoreException {
668648
String encoding= null;
669649
if (sa instanceof IEncodedStreamContentAccessor) {
@@ -675,16 +655,6 @@ public static String readString(IStreamContentAccessor sa) throws CoreException
675655
return Utilities.readString(sa, encoding);
676656
}
677657

678-
public static void close(InputStream is) {
679-
if (is != null) {
680-
try {
681-
is.close();
682-
} catch (IOException ex) {
683-
// silently ignored
684-
}
685-
}
686-
}
687-
688658
public static IResource getFirstResource(ISelection selection) {
689659
IResource[] resources = getResources(selection);
690660
if (resources.length > 0) {

team/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DocumentRangeNode.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2011 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -13,6 +13,8 @@
1313
*******************************************************************************/
1414
package org.eclipse.compare.structuremergeviewer;
1515

16+
import static java.nio.charset.StandardCharsets.UTF_16;
17+
1618
import java.io.ByteArrayInputStream;
1719
import java.io.InputStream;
1820
import java.util.ArrayList;
@@ -65,7 +67,6 @@
6567
public class DocumentRangeNode
6668
implements IDocumentRange, IStructureComparator, IEditableContent,
6769
IEncodedStreamContentAccessor, IAdaptable, IEditableContentExtension {
68-
private static final String UTF_16= "UTF-16"; //$NON-NLS-1$
6970

7071
private final IDocument fBaseDocument;
7172
private Position fRange; // the range in the base document
@@ -347,7 +348,7 @@ public InputStream getContents() {
347348
} catch (BadLocationException ex) {
348349
s= ""; //$NON-NLS-1$
349350
}
350-
return new ByteArrayInputStream(Utilities.getBytes(s, UTF_16));
351+
return new ByteArrayInputStream(s.getBytes(UTF_16));
351352
}
352353

353354

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

420421
@Override
421422
public String getCharset() {
422-
return UTF_16;
423+
return UTF_16.name();
423424
}
424425

425426
/**

0 commit comments

Comments
 (0)