forked from rongchao/epmet-cloud-rizhao
18 changed files with 270 additions and 89 deletions
@ -0,0 +1,37 @@ |
|||||
|
package com.epmet.commons.tools.utils; |
||||
|
|
||||
|
import java.io.File; |
||||
|
import java.io.IOException; |
||||
|
import java.io.InputStream; |
||||
|
import java.nio.file.Files; |
||||
|
|
||||
|
public class FileUtils { |
||||
|
|
||||
|
/** |
||||
|
* 创建临时文件. |
||||
|
* |
||||
|
* @param inputStream 输入文件流 |
||||
|
* @param name 文件名 |
||||
|
* @param ext 扩展名 |
||||
|
* @param tmpDirFile 临时文件夹目录 |
||||
|
*/ |
||||
|
public static File createTmpFile(InputStream inputStream, String name, String ext, File tmpDirFile) throws IOException { |
||||
|
File resultFile = File.createTempFile(name, '.' + ext, tmpDirFile); |
||||
|
|
||||
|
resultFile.deleteOnExit(); |
||||
|
org.apache.commons.io.FileUtils.copyToFile(inputStream, resultFile); |
||||
|
return resultFile; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 创建临时文件. |
||||
|
* |
||||
|
* @param inputStream 输入文件流 |
||||
|
* @param name 文件名 |
||||
|
* @param ext 扩展名 |
||||
|
*/ |
||||
|
public static File createTmpFile(InputStream inputStream, String name, String ext) throws IOException { |
||||
|
return createTmpFile(inputStream, name, ext, Files.createTempDirectory("weixin-java-tools-temp").toFile()); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,33 @@ |
|||||
|
package com.epmet.commons.tools.utils; |
||||
|
|
||||
|
import org.apache.http.HttpEntity; |
||||
|
import org.apache.http.HttpResponse; |
||||
|
import org.apache.http.StatusLine; |
||||
|
import org.apache.http.client.HttpResponseException; |
||||
|
import org.apache.http.client.ResponseHandler; |
||||
|
import org.apache.http.util.EntityUtils; |
||||
|
|
||||
|
import java.io.IOException; |
||||
|
import java.io.InputStream; |
||||
|
|
||||
|
/** |
||||
|
* 输入流响应处理器. |
||||
|
* |
||||
|
* @author Daniel Qian |
||||
|
*/ |
||||
|
public class InputStreamResponseHandler implements ResponseHandler<InputStream> { |
||||
|
public static final ResponseHandler<InputStream> INSTANCE = new InputStreamResponseHandler(); |
||||
|
private static final int STATUS_CODE_300 = 300; |
||||
|
|
||||
|
@Override |
||||
|
public InputStream handleResponse(final HttpResponse response) throws IOException { |
||||
|
final StatusLine statusLine = response.getStatusLine(); |
||||
|
final HttpEntity entity = response.getEntity(); |
||||
|
if (statusLine.getStatusCode() >= STATUS_CODE_300) { |
||||
|
EntityUtils.consume(entity); |
||||
|
throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase()); |
||||
|
} |
||||
|
return entity == null ? null : entity.getContent(); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,33 @@ |
|||||
|
package com.epmet.commons.tools.utils; |
||||
|
|
||||
|
import org.apache.http.Consts; |
||||
|
import org.apache.http.HttpEntity; |
||||
|
import org.apache.http.HttpResponse; |
||||
|
import org.apache.http.StatusLine; |
||||
|
import org.apache.http.client.HttpResponseException; |
||||
|
import org.apache.http.client.ResponseHandler; |
||||
|
import org.apache.http.util.EntityUtils; |
||||
|
|
||||
|
import java.io.IOException; |
||||
|
|
||||
|
/** |
||||
|
* copy from {@link org.apache.http.impl.client.BasicResponseHandler} |
||||
|
* |
||||
|
* @author Daniel Qian |
||||
|
*/ |
||||
|
public class Utf8ResponseHandler implements ResponseHandler<String> { |
||||
|
|
||||
|
public static final ResponseHandler<String> INSTANCE = new Utf8ResponseHandler(); |
||||
|
|
||||
|
@Override |
||||
|
public String handleResponse(final HttpResponse response) throws IOException { |
||||
|
final StatusLine statusLine = response.getStatusLine(); |
||||
|
final HttpEntity entity = response.getEntity(); |
||||
|
if (statusLine.getStatusCode() >= 300) { |
||||
|
EntityUtils.consume(entity); |
||||
|
throw new HttpResponseException(statusLine.getStatusCode(), statusLine.toString()); |
||||
|
} |
||||
|
return entity == null ? null : EntityUtils.toString(entity, Consts.UTF_8); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,18 @@ |
|||||
|
package com.epmet.dto; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
import org.springframework.web.multipart.MultipartFile; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
|
||||
|
/** |
||||
|
* @author zhaoqifeng |
||||
|
* @dscription |
||||
|
* @date 2020/7/24 10:10 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class QrCodeDTO implements Serializable { |
||||
|
private static final long serialVersionUID = -1787470699926486609L; |
||||
|
private byte[] qrCode; |
||||
|
private MultipartFile media; |
||||
|
} |
Loading…
Reference in new issue