Skip to content

Commit

Permalink
use try-with-resource
Browse files Browse the repository at this point in the history
  • Loading branch information
EcljpseB0T authored and jukzi committed Jun 9, 2023
1 parent aa6975c commit 5f02391
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 76 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2010, 2022 Tom Schindl and others.
* Copyright (c) 2010, 2023 Tom Schindl 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 @@ -544,7 +544,7 @@ private EventAdmin getEventAdmin() {

@Override
public synchronized List<ITheme> getThemes() {
return Collections.unmodifiableList(new ArrayList<ITheme>(themes));
return Collections.unmodifiableList(new ArrayList<>(themes));
}

@Override
Expand All @@ -566,24 +566,13 @@ private IEclipsePreferences getPreferences() {
}

void copyFile(String from, String to) throws IOException {
FileInputStream fStream = null;
BufferedOutputStream outputStream = null;
try {
fStream = new FileInputStream(from);
outputStream = new BufferedOutputStream(new FileOutputStream(to));
try (FileInputStream fStream = new FileInputStream(from);
BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(to))) {
byte[] buffer = new byte[4096];
int c;
while ((c = fStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, c);
}

} finally {
if (fStream != null) {
fStream.close();
}
if (outputStream != null) {
outputStream.close();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2021 IBM Corporation and others.
* Copyright (c) 2000, 2023 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 @@ -223,30 +223,17 @@ private static File makeDisplayCopy(File file) {
}
path = path.append(ERROR_LOG_COPY_FILENAME);
File copy = path.toFile();
FileReader in = null;
FileWriter out = null;
try {
in = new FileReader(file);
try (FileReader in = new FileReader(file)) {
// don't append data, overwrite what was there
out = new FileWriter(copy);
char buffer[] = new char[4096];
int count;
while ((count = in.read(buffer, 0, buffer.length)) > 0) {
out.write(buffer, 0, count);
try (FileWriter out = new FileWriter(copy)) {
char buffer[] = new char[4096];
int count;
while ((count = in.read(buffer, 0, buffer.length)) > 0) {
out.write(buffer, 0, count);
}
}
} catch (IOException e) {
return null;
} finally {
try {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
} catch (IOException e) {
return null;
}
}
return copy;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2014, 2017 TwelveTone LLC and others.
* Copyright (c) 2014, 2023 TwelveTone LLC 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 @@ -335,48 +335,43 @@ protected IStatus run(IProgressMonitor monitor) {
final String installLocation = pluginModelBase.getInstallLocation();
if (installLocation.endsWith(".jar")) { //$NON-NLS-1$
url = new URL("file:///" + installLocation); //$NON-NLS-1$
final ZipInputStream zis = new ZipInputStream(url.openStream());
while (true) {
final ZipEntry entry = zis.getNextEntry();
if (entry == null) {
break;
}
final String name2 = entry.getName();
if (shouldIgnore(name2)) {
continue;
}
final Matcher m = patternFile.matcher(name2);
if (m.matches()) {
final Entry e = new Entry();
e.installLocation = installLocation;
cacheLocation.add(installLocation);
e.name = m.group(2);
e.path = m.group(1);
if (e.path != null) {
e.pakage = e.path.replace("/", "."); //$NON-NLS-1$ //$NON-NLS-2$
if (e.pakage.startsWith(".")) { //$NON-NLS-1$
e.pakage = e.pakage.substring(1);
}
if (e.pakage.endsWith(".")) { //$NON-NLS-1$
e.pakage = e.pakage.substring(0, e.pakage.length() - 1);
}
} else {
e.pakage = ""; //$NON-NLS-1$
try (final ZipInputStream zis = new ZipInputStream(url.openStream())) {
while (true) {
final ZipEntry entry = zis.getNextEntry();
if (entry == null) {
break;
}
cachePackage.add(e.pakage);
final String name2 = entry.getName();
if (shouldIgnore(name2)) {
continue;
}
final Matcher m = patternFile.matcher(name2);
if (m.matches()) {
final Entry e = new Entry();
e.installLocation = installLocation;
cacheLocation.add(installLocation);
e.name = m.group(2);
e.path = m.group(1);
if (e.path != null) {
e.pakage = e.path.replace("/", "."); //$NON-NLS-1$ //$NON-NLS-2$
if (e.pakage.startsWith(".")) { //$NON-NLS-1$
e.pakage = e.pakage.substring(1);
}
if (e.pakage.endsWith(".")) { //$NON-NLS-1$
e.pakage = e.pakage.substring(0, e.pakage.length() - 1);
}
} else {
e.pakage = ""; //$NON-NLS-1$
}
cachePackage.add(e.pakage);

e.bundleSymName = pluginBase.getId();
if (e.path == null) {
e.path = ""; //$NON-NLS-1$
e.bundleSymName = pluginBase.getId();
if (e.path == null) {
e.path = ""; //$NON-NLS-1$
}
cacheEntry.add(e);
cacheBundleId.add(pluginBase.getId());
}
cacheEntry.add(e);
cacheBundleId.add(pluginBase.getId());

//
// System.out.println(group
// + " -> "
// +
// m.group(2));
}
}
} else {
Expand Down

0 comments on commit 5f02391

Please sign in to comment.