Commit b4ac4eae by 李辅翼

fix it

parent c9f96191
...@@ -87,6 +87,12 @@ public class FtpProxyWebApi { ...@@ -87,6 +87,12 @@ public class FtpProxyWebApi {
} }
} }
/**
* ftp
*
* @param urls
* @return
*/
@PostMapping("/testFtpUtil") @PostMapping("/testFtpUtil")
public synchronized PicByte testFtpUtil(@RequestParam("urls") String urls) { public synchronized PicByte testFtpUtil(@RequestParam("urls") String urls) {
PicByte picByte = new PicByte(); PicByte picByte = new PicByte();
...@@ -155,6 +161,13 @@ public class FtpProxyWebApi { ...@@ -155,6 +161,13 @@ public class FtpProxyWebApi {
} }
} }
/**
* http
*
* @param urls
* @return
*/
@PostMapping("/testHttpUtil") @PostMapping("/testHttpUtil")
public synchronized PicByte testHttpUtil(@RequestParam("urls") String urls) { public synchronized PicByte testHttpUtil(@RequestParam("urls") String urls) {
String[] urlArr = urls.split(","); String[] urlArr = urls.split(",");
...@@ -226,6 +239,138 @@ public class FtpProxyWebApi { ...@@ -226,6 +239,138 @@ public class FtpProxyWebApi {
} }
/**
* ftp总队的
*
* @param url
* @return
*/
@GetMapping("/ftpPic")
public void ftpPic(@RequestParam("url") String url, HttpServletResponse response) {
FtpUtil ftpUtil = null;
byte[] bytes=null;
try {
paramUrl(url);
ftpUtil = new FtpUtil(host, 21, userName, password);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
boolean flag = ftpUtil.downloadPicFile(path, filename, bos);
if (flag) {
bytes = bos.toByteArray();
} else {
logger.info("获取图片失败");
}
} catch (Throwable e) {
e.printStackTrace();
} finally {
if (ftpUtil != null) {
ftpUtil = null;
}
}
try {
response.setCharacterEncoding("UTF-8");
response.setContentType("application/octet-stream");
response.addHeader(
"Content-Disposition",
"attachment; filename=\"test.jpg\"");
response.getOutputStream().write(bytes);
} catch (IOException e) {
}
}
/**
* http总队的
*
* @param urls
* @return
*/
@GetMapping("/httpPic")
public void httpPic(@RequestParam("url") String urls, HttpServletResponse response) {
Map<String, byte[]> map = new HashMap<>();
HttpURLConnection httpURLConnection = null;
InputStream inputStream = null;
ByteArrayOutputStream bos = null;
byte[] buffer=null;
try {
URL url = new URL(urls);
httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setConnectTimeout(3000);
httpURLConnection.setDoInput(true);
httpURLConnection.setRequestMethod("GET");
int responseCode = httpURLConnection.getResponseCode();
if (responseCode == 200) {
// 从服务器返回一个输入流
inputStream = httpURLConnection.getInputStream();
if (inputStream != null && inputStream.available() > 0) {
bos = new ByteArrayOutputStream();
int length;
byte[] buf = new byte[1024 * 2];
while (-1 != (length = inputStream.read(buf, 0, buf.length))) {
bos.write(buf, 0, length);
}
ByteArrayInputStream fis = new ByteArrayInputStream(bos.toByteArray());
bos.flush();
bos.close();
buffer = new byte[fis.available()];
int offset = 0;
int numRead = 0;
while (offset < buffer.length && (numRead = fis.read(buffer, offset, buffer.length - offset)) >= 0) {
offset += numRead;
}
if (offset != buffer.length) {
throw new IOException("Could not completely read file ");
}
fis.close();
}
inputStream.close();
}
} catch (Throwable e) {
e.printStackTrace();
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (bos != null) {
try {
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
try {
response.setCharacterEncoding("UTF-8");
response.setContentType("application/octet-stream");
response.addHeader(
"Content-Disposition",
"attachment; filename=\"test.jpg\"");
response.getOutputStream().write(buffer);
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* http总队的
*
* @param
* @return
*/
@GetMapping("/showImg")
public void showImg(@RequestParam("url") String urls,HttpServletResponse response) {
try {
String html = "<html><body><img src=\"/ftp/httpPic?url="+urls+"\"/></body></html>";
response.getOutputStream().write(html.getBytes("UTF-8"));
} catch (IOException e) {
e.printStackTrace();
}
}
@PostMapping("/downloadByUrls") @PostMapping("/downloadByUrls")
public synchronized PicByte list2(@RequestParam("urls") String urls, HttpServletResponse response) { public synchronized PicByte list2(@RequestParam("urls") String urls, HttpServletResponse response) {
PicByte picByte = new PicByte(); PicByte picByte = new PicByte();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment