22
33import org .apache .commons .io .FileUtils ;
44import java .io .IOException ;
5- import java .io .InputStream ;
65import java .io .BufferedReader ;
76import java .io .InputStreamReader ;
87import java .io .File ;
98import java .net .URL ;
10- import java .net .URLConnection ;
119import java .util .regex .Pattern ;
12- import java .util .zip .GZIPInputStream ;
13- import java .util .zip .ZipException ;
1410
1511class LocalBinary {
1612
@@ -62,8 +58,7 @@ private void initialize() throws LocalException {
6258 throw new LocalException ("Failed to detect OS type" );
6359 }
6460
65- String sourceURL = BIN_URL ;
66- httpPath = sourceURL + binFileName ;
61+ httpPath = BIN_URL + binFileName ;
6762 }
6863
6964 private boolean isAlpine () {
@@ -179,7 +174,7 @@ private void downloadBinary(String destParentDir, Boolean custom) throws LocalEx
179174 URL url = new URL (httpPath );
180175
181176 File f = new File (source );
182- newCopyToFile (url , f );
177+ FileUtils . copyURLToFile (url , f );
183178
184179 changePermissions (binaryPath );
185180 } catch (Exception e ) {
@@ -197,26 +192,4 @@ private void changePermissions(String path) {
197192 public String getBinaryPath () {
198193 return binaryPath ;
199194 }
200-
201- private static void newCopyToFile (URL url , File f ) throws IOException {
202- URLConnection conn = url .openConnection ();
203- conn .setRequestProperty ("User-Agent" , "browserstack-local-java/" + Local .getPackageVersion ());
204- conn .setRequestProperty ("Accept-Encoding" , "gzip, *" );
205- String contentEncoding = conn .getContentEncoding ();
206-
207- if (contentEncoding == null || !contentEncoding .toLowerCase ().contains ("gzip" )) {
208- FileUtils .copyToFile (conn .getInputStream (), f );
209- return ;
210- }
211-
212- try (InputStream stream = new GZIPInputStream (conn .getInputStream ())) {
213- if (System .getenv ().containsKey ("BROWSERSTACK_LOCAL_DEBUG_GZIP" )) {
214- System .out .println ("using gzip in " + conn .getRequestProperty ("User-Agent" ));
215- }
216-
217- FileUtils .copyToFile (stream , f );
218- } catch (ZipException e ) {
219- FileUtils .copyURLToFile (url , f );
220- }
221- }
222195}
0 commit comments