diff --git a/briar-android/src/org/briarproject/plugins/tor/TorPlugin.java b/briar-android/src/org/briarproject/plugins/tor/TorPlugin.java index cdd557ea8be0bb93ebd2a55db1e8965c25054718..c9586af6d82e0f72e2edded3e56a8a449fea4ba3 100644 --- a/briar-android/src/org/briarproject/plugins/tor/TorPlugin.java +++ b/briar-android/src/org/briarproject/plugins/tor/TorPlugin.java @@ -34,8 +34,10 @@ import org.briarproject.api.properties.TransportProperties; import org.briarproject.api.reporting.DevReporter; import org.briarproject.api.settings.Settings; import org.briarproject.api.system.LocationUtils; +import org.briarproject.util.IoUtils; import org.briarproject.util.StringUtils; +import java.io.Closeable; import java.io.EOFException; import java.io.File; import java.io.FileInputStream; @@ -243,17 +245,17 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener { // Unzip the Tor binary to the filesystem in = getTorInputStream(); out = new FileOutputStream(torFile); - copy(in, out); + IoUtils.copy(in, out); // Make the Tor binary executable if (!torFile.setExecutable(true, true)) throw new IOException(); // Unzip the GeoIP database to the filesystem in = getGeoIpInputStream(); out = new FileOutputStream(geoIpFile); - copy(in, out); + IoUtils.copy(in, out); // Copy the config file to the filesystem in = getConfigInputStream(); out = new FileOutputStream(configFile); - copy(in, out); + IoUtils.copy(in, out); doneFile.createNewFile(); } catch (IOException e) { tryToClose(in); @@ -284,28 +286,9 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener { return appContext.getResources().getAssets().open("torrc"); } - private void copy(InputStream in, OutputStream out) throws IOException { - byte[] buf = new byte[4096]; - while (true) { - int read = in.read(buf); - if (read == -1) break; - out.write(buf, 0, read); - } - in.close(); - out.close(); - } - - private void tryToClose(InputStream in) { - try { - if (in != null) in.close(); - } catch (IOException e) { - if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e); - } - } - - private void tryToClose(OutputStream out) { + private void tryToClose(Closeable c) { try { - if (out != null) out.close(); + if (c != null) c.close(); } catch (IOException e) { if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e); }