Use of IO for closing/copying streams
This commit is contained in:
parent
ad066c6e42
commit
ae8177ce07
|
@ -29,9 +29,11 @@ import java.io.InputStream;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
|
||||||
import dorkbox.systemTray.SystemTray;
|
import dorkbox.systemTray.SystemTray;
|
||||||
|
import dorkbox.util.IO;
|
||||||
import dorkbox.util.Property;
|
import dorkbox.util.Property;
|
||||||
import dorkbox.util.process.ShellProcessBuilder;
|
import dorkbox.util.process.ShellProcessBuilder;
|
||||||
|
|
||||||
|
@SuppressWarnings({"DanglingJavadoc", "WeakerAccess"})
|
||||||
public
|
public
|
||||||
class GnomeShellExtension {
|
class GnomeShellExtension {
|
||||||
private static final String UID = "SystemTray@Dorkbox";
|
private static final String UID = "SystemTray@Dorkbox";
|
||||||
|
@ -116,14 +118,7 @@ class GnomeShellExtension {
|
||||||
.append("\n");
|
.append("\n");
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (bin != null) {
|
IO.close(bin, logger);
|
||||||
try {
|
|
||||||
bin.close();
|
|
||||||
} catch (IOException ioe) {
|
|
||||||
System.err.println("Error closing the metadata file:" + bin);
|
|
||||||
ioe.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -161,39 +156,20 @@ class GnomeShellExtension {
|
||||||
outputWriter.flush();
|
outputWriter.flush();
|
||||||
outputWriter.close();
|
outputWriter.close();
|
||||||
} finally {
|
} finally {
|
||||||
if (outputWriter != null) {
|
IO.close(outputWriter, logger);
|
||||||
try {
|
|
||||||
outputWriter.close();
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// copies our provided extension.js file to the correct location on disk
|
// copies our provided extension.js file to the correct location on disk
|
||||||
InputStream reader = null;
|
InputStream reader = null;
|
||||||
FileOutputStream fileOutputStream = null;
|
FileOutputStream fileOutputStream = null;
|
||||||
try {
|
try {
|
||||||
fileOutputStream = new FileOutputStream(extensionFile);
|
|
||||||
reader = GnomeShellExtension.class.getResourceAsStream("extension.js");
|
reader = GnomeShellExtension.class.getResourceAsStream("extension.js");
|
||||||
|
fileOutputStream = new FileOutputStream(extensionFile);
|
||||||
|
|
||||||
byte[] buffer = new byte[4096];
|
IO.copyStream(reader, fileOutputStream);
|
||||||
int read;
|
|
||||||
while ((read = reader.read(buffer)) > 0) {
|
|
||||||
fileOutputStream.write(buffer, 0, read);
|
|
||||||
}
|
|
||||||
} finally {
|
} finally {
|
||||||
if (reader != null) {
|
IO.close(reader, logger);
|
||||||
try {
|
IO.close(fileOutputStream, logger);
|
||||||
reader.close();
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (fileOutputStream != null) {
|
|
||||||
try {
|
|
||||||
fileOutputStream.close();
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user