//
|
// Source code recreated from a .class file by IntelliJ IDEA
|
// (powered by FernFlower decompiler)
|
//
|
|
package org.jeecg.modules.doc.vo;
|
|
import cn.hutool.core.io.FileTypeUtil;
|
|
import java.io.File;
|
import java.io.FileInputStream;
|
import java.io.IOException;
|
import java.io.InputStream;
|
import java.io.OutputStream;
|
import javax.servlet.ServletOutputStream;
|
import javax.servlet.http.HttpServletResponse;
|
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.IOUtils;
|
import org.jeecg.modules.doc.util.CharsetUtils;
|
import org.jeecg.modules.doc.util.UFOPUtils;
|
|
public abstract class Previewer {
|
public ThumbImage thumbImage;
|
|
protected abstract InputStream getInputStream(String fileUrl);
|
|
public void imageThumbnailPreview(HttpServletResponse httpServletResponse, String fileUrl) {
|
|
boolean isVideo = UFOPUtils.isVideoFile(FilenameUtils.getExtension(fileUrl));
|
String thumbnailImgUrl = fileUrl;
|
if (isVideo) {
|
thumbnailImgUrl = fileUrl.replace("." + FilenameUtils.getExtension(fileUrl), ".jpg");
|
}
|
|
File cacheFile = UFOPUtils.getCacheFile(thumbnailImgUrl);
|
ServletOutputStream outputStream;
|
if (cacheFile.exists()) {
|
FileInputStream fis = null;
|
outputStream = null;
|
|
try {
|
fis = new FileInputStream(cacheFile);
|
outputStream = httpServletResponse.getOutputStream();
|
IOUtils.copy(fis, outputStream);
|
} catch (IOException var26) {
|
var26.printStackTrace();
|
} finally {
|
IOUtils.closeQuietly(fis);
|
IOUtils.closeQuietly(outputStream);
|
}
|
} else {
|
InputStream inputstream = null;
|
outputStream = null;
|
InputStream in = null;
|
|
try {
|
inputstream = this.getInputStream(fileUrl);
|
if (inputstream != null) {
|
outputStream = httpServletResponse.getOutputStream();
|
int thumbImageWidth = this.thumbImage.getWidth();
|
int thumbImageHeight = this.thumbImage.getHeight();
|
int width = thumbImageWidth == 0 ? 150 : thumbImageWidth;
|
int height = thumbImageHeight == 0 ? 150 : thumbImageHeight;
|
String type = FileTypeUtil.getType(this.getInputStream(fileUrl));
|
boolean isImageFile = UFOPUtils.isImageFile(type);
|
if (isVideo) {
|
in = VideoOperation.thumbnailsImage(inputstream, cacheFile, width, height);
|
} else if (isImageFile) {
|
in = ImageOperation.thumbnailsImage(inputstream, cacheFile, width, height);
|
} else {
|
in = inputstream;
|
}
|
|
IOUtils.copy(in, outputStream);
|
}
|
} catch (IOException var25) {
|
var25.printStackTrace();
|
} finally {
|
IOUtils.closeQuietly(in);
|
IOUtils.closeQuietly(inputstream);
|
IOUtils.closeQuietly(outputStream);
|
|
|
}
|
}
|
|
}
|
|
public void imageOriginalPreview(HttpServletResponse httpServletResponse, String fileUrl) {
|
InputStream inputStream = null;
|
OutputStream outputStream = null;
|
|
try {
|
inputStream = this.getInputStream(fileUrl);
|
outputStream = httpServletResponse.getOutputStream();
|
byte[] bytes = IOUtils.toByteArray(inputStream);
|
bytes = CharsetUtils.convertTxtCharsetToUTF8(bytes, FilenameUtils.getExtension(fileUrl));
|
outputStream.write(bytes);
|
} catch (IOException var9) {
|
var9.printStackTrace();
|
} finally {
|
IOUtils.closeQuietly(inputStream);
|
IOUtils.closeQuietly(outputStream);
|
|
|
}
|
|
}
|
|
public Previewer() {
|
}
|
|
public ThumbImage getThumbImage() {
|
return this.thumbImage;
|
}
|
|
public void setThumbImage(final ThumbImage thumbImage) {
|
this.thumbImage = thumbImage;
|
}
|
|
public boolean equals(final Object o) {
|
if (o == this) {
|
return true;
|
} else if (!(o instanceof Previewer)) {
|
return false;
|
} else {
|
Previewer other = (Previewer)o;
|
if (!other.canEqual(this)) {
|
return false;
|
} else {
|
Object this$thumbImage = this.getThumbImage();
|
Object other$thumbImage = other.getThumbImage();
|
if (this$thumbImage == null) {
|
if (other$thumbImage != null) {
|
return false;
|
}
|
} else if (!this$thumbImage.equals(other$thumbImage)) {
|
return false;
|
}
|
|
return true;
|
}
|
}
|
}
|
|
protected boolean canEqual(final Object other) {
|
return other instanceof Previewer;
|
}
|
|
public int hashCode() {
|
int result = 1;
|
Object $thumbImage = this.getThumbImage();
|
result = result * 59 + ($thumbImage == null ? 43 : $thumbImage.hashCode());
|
return result;
|
}
|
|
public String toString() {
|
return "Previewer(thumbImage=" + this.getThumbImage() + ")";
|
}
|
}
|