2
2
3
3
import org .apache .commons .io .FileUtils ;
4
4
import java .io .IOException ;
5
- import java .io .InputStream ;
6
5
import java .io .BufferedReader ;
7
6
import java .io .InputStreamReader ;
8
7
import java .io .File ;
9
8
import java .net .URL ;
10
- import java .net .URLConnection ;
11
9
import java .util .regex .Pattern ;
12
- import java .util .zip .GZIPInputStream ;
13
- import java .util .zip .ZipException ;
14
10
15
11
class LocalBinary {
16
12
@@ -62,8 +58,7 @@ private void initialize() throws LocalException {
62
58
throw new LocalException ("Failed to detect OS type" );
63
59
}
64
60
65
- String sourceURL = BIN_URL ;
66
- httpPath = sourceURL + binFileName ;
61
+ httpPath = BIN_URL + binFileName ;
67
62
}
68
63
69
64
private boolean isAlpine () {
@@ -179,7 +174,7 @@ private void downloadBinary(String destParentDir, Boolean custom) throws LocalEx
179
174
URL url = new URL (httpPath );
180
175
181
176
File f = new File (source );
182
- newCopyToFile (url , f );
177
+ FileUtils . copyURLToFile (url , f );
183
178
184
179
changePermissions (binaryPath );
185
180
} catch (Exception e ) {
@@ -197,26 +192,4 @@ private void changePermissions(String path) {
197
192
public String getBinaryPath () {
198
193
return binaryPath ;
199
194
}
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
- }
222
195
}
0 commit comments