📄 graphicsredliningtaskutil.java
字号:
package com.esri.solutions.jitk.web.tasks.redlining.graphics;
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.util.List;
import net.sf.image4j.codec.ico.ICODecoder;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.text.DateFormat;
import java.util.Date;
public class GraphicsRedliningTaskUtil {
public GraphicsRedliningTaskUtil() {
}
private static byte[] getBytesFromFile(File file) {
try{
InputStream is = new FileInputStream(file);
ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
final int DEFAULT_BUFFER_SIZE = 1024 * 4;
byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
int count = 0;
int num = 0;
while ((num = is.read(buffer)) != -1){
bytestream.write(buffer, 0, num);
count += num;
}
return bytestream.toByteArray();
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static byte[] getBytesFromFile(String strInFile, String sessionId){
try{
File inFile = new File(strInFile);
List<BufferedImage> images = ICODecoder.read(inFile);
BufferedImage img = (BufferedImage)images.get(images.size()-1);
// bytearray doesn't work, so, save the bytes to png
String dstr = DateFormat.getDateTimeInstance().format(new Date());
String filename = dstr.replaceAll(" ", "_");
filename = "jitk_" + sessionId + "_" + filename.replaceAll(":", "_") + ".png";
String pngFileName = System.getProperty("java.io.tmpdir") + System.getProperty("file.separator") + filename;
File pngFile = new File(pngFileName);
javax.imageio.ImageIO.write(img, "png", pngFile);
byte[] data = getBytesFromFile(pngFile);
pngFile.delete();
return data;
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static String checkSize(byte[] data, int widthParam, int heightParam, int sizeParam){
try{
if (data.length > sizeParam * 1024) return "File size is too large. File can not be uploaded.";
BufferedImage img = ImageIO.read(new ByteArrayInputStream(data));
int width = img.getWidth();
int height = img.getHeight();
if (width > widthParam || height > heightParam) return "File width or height is too large. File can not be uploaded.";
}catch(Exception e){
e.printStackTrace();
}
return "OK";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -