@Test public void testFetch() { File file = fileFetchService.fetch("http: assertNotNull(file); assertThat(file.length(), not(0l)); }
public File fetch(String path) { HttpGet get = new HttpGet(path); CloseableHttpResponse response = null; File file = null; try { response = httpclient.execute(get); StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() == 200) { file = null; String fileName = System.getProperty("java.io.tmpdir") + File.separator + getFileName(ShortUrl.shortText(new Date().getTime() + path + System.nanoTime())) + getSuffix(path); file = new File(fileName); FileOutputStream outputStream = new FileOutputStream(file); InputStream inputStream = response.getEntity().getContent(); byte buff[] = new byte[4096]; int counts = 0; while ((counts = inputStream.read(buff)) != -1) { outputStream.write(buff, 0, counts); } outputStream.flush(); outputStream.close(); } } catch (IOException e) { e.printStackTrace(); logger.error(e); } return file; }
FileFetchService { public File fetch(String path) { HttpGet get = new HttpGet(path); CloseableHttpResponse response = null; File file = null; try { response = httpclient.execute(get); StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() == 200) { file = null; String fileName = System.getProperty("java.io.tmpdir") + File.separator + getFileName(ShortUrl.shortText(new Date().getTime() + path + System.nanoTime())) + getSuffix(path); file = new File(fileName); FileOutputStream outputStream = new FileOutputStream(file); InputStream inputStream = response.getEntity().getContent(); byte buff[] = new byte[4096]; int counts = 0; while ((counts = inputStream.read(buff)) != -1) { outputStream.write(buff, 0, counts); } outputStream.flush(); outputStream.close(); } } catch (IOException e) { e.printStackTrace(); logger.error(e); } return file; } }
FileFetchService { public File fetch(String path) { HttpGet get = new HttpGet(path); CloseableHttpResponse response = null; File file = null; try { response = httpclient.execute(get); StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() == 200) { file = null; String fileName = System.getProperty("java.io.tmpdir") + File.separator + getFileName(ShortUrl.shortText(new Date().getTime() + path + System.nanoTime())) + getSuffix(path); file = new File(fileName); FileOutputStream outputStream = new FileOutputStream(file); InputStream inputStream = response.getEntity().getContent(); byte buff[] = new byte[4096]; int counts = 0; while ((counts = inputStream.read(buff)) != -1) { outputStream.write(buff, 0, counts); } outputStream.flush(); outputStream.close(); } } catch (IOException e) { e.printStackTrace(); logger.error(e); } return file; }  }
FileFetchService { public File fetch(String path) { HttpGet get = new HttpGet(path); CloseableHttpResponse response = null; File file = null; try { response = httpclient.execute(get); StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() == 200) { file = null; String fileName = System.getProperty("java.io.tmpdir") + File.separator + getFileName(ShortUrl.shortText(new Date().getTime() + path + System.nanoTime())) + getSuffix(path); file = new File(fileName); FileOutputStream outputStream = new FileOutputStream(file); InputStream inputStream = response.getEntity().getContent(); byte buff[] = new byte[4096]; int counts = 0; while ((counts = inputStream.read(buff)) != -1) { outputStream.write(buff, 0, counts); } outputStream.flush(); outputStream.close(); } } catch (IOException e) { e.printStackTrace(); logger.error(e); } return file; }  File fetch(String path); }
FileFetchService { public File fetch(String path) { HttpGet get = new HttpGet(path); CloseableHttpResponse response = null; File file = null; try { response = httpclient.execute(get); StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() == 200) { file = null; String fileName = System.getProperty("java.io.tmpdir") + File.separator + getFileName(ShortUrl.shortText(new Date().getTime() + path + System.nanoTime())) + getSuffix(path); file = new File(fileName); FileOutputStream outputStream = new FileOutputStream(file); InputStream inputStream = response.getEntity().getContent(); byte buff[] = new byte[4096]; int counts = 0; while ((counts = inputStream.read(buff)) != -1) { outputStream.write(buff, 0, counts); } outputStream.flush(); outputStream.close(); } } catch (IOException e) { e.printStackTrace(); logger.error(e); } return file; }  File fetch(String path);  }