⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 picture.java

📁 1、在Tomcat的Webapps目录下建立一个目录
💻 JAVA
字号:
/* * Picture.java * * Created on 2004年12月23日, 上午10:24 * 这个类封装了Picture属性 * */package com.mg.admin;import java.io.*;import java.util.*;import org.jdom.*;import org.jdom.input.*;import org.jdom.output.*;import java.text.SimpleDateFormat;import java.text.DateFormat;/** * 这个类封装了Message消息 */public class Picture extends Object{        //********************成员变量************************        /**     * 定义当前包含的元素数量     */    public static final int ELEMENT_NUM = 4;    /**     * 标题     */    private String title;        /**     * 日期     */    private String datetime;        /**     * 当前操作用户     */    private String user;        /**     * 图像文件名     */    private String filename;        /**     * 保存文件上传前在客户端的路径和名字     */    private String clientFileName;        /**     * 用于保存图像数据     */    private ByteArrayOutputStream memoryOutputStream;        /**     * 数据缓存大小,超过缓冲大小后,数据将被写入磁盘.     */    private long sizeThreshold;        //********************成员函数************************        /**     * 构造函数     * <p>     * @see #setRootPath     */    public Picture() {        datetime = getCurrentTime();    }        /**     * 获得当前日前和时间字符串     * <p>     * @return 返回表示当前日期和时间的字符串     */    private String getCurrentTime() {        //使用缺省的时区和地区        Calendar rightNow = Calendar.getInstance();        rightNow.setTime(new Date());        Date today = rightNow.getTime();        DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm aaa");        return df.format(today);    }        /**     * 获得图像的标题     * <p>     * @return  返回图像标题     * <p>     * @see #setTitle()     */    public String getTitle() {        return title;    }        /**     * 设置图像的标题     * <p>     * @param value 图像标题     * <p>     * @see #getTitle()     */    public void setTitle(String value) {        title = value;    }        /**     * 获得当前时间     * <p>     * @return  返回当前时间     * <p>     * @see #setDateTime()     */    public String getDateTime() {        return datetime;    }        /**     * 设置当前时间     * <p>     * @param value 当前时间     * <p>     * @see #getDateTime()     */    public void setDateTime(String value) {        datetime = value;    }        /**     * 获得当前用户     * <p>     * @return  返回当前用户     * <p>     * @see #setUser()     */    public String getUser() {        return user;    }        /**     * 设置当前用户     * <p>     * @param value 当前用户     * <p>     * @see #getUser()     */    public void setUser(String value) {        user = value;    }        /**     * 获得图像的内容     * <p>     * @return  返回图像的内容     * <p>     * @see #setFileName()     */    public String getFileName() {        return filename;    }        /**     * 设置图像的文件名     * <p>     * @param value 图像的文件名     * <p>     * @see #getFileName()     */    public void setFileName(String value) {        filename = value;    }        /**     * 获得文件的类型     * <p>     * @return 文件的扩展名。     */    public String getFileType() {        String ret = "";        if (filename.toLowerCase().endsWith(".gif")) {            ret = "gif";        } else if (filename.toLowerCase().endsWith(".jpg")) {            ret = "jpg";        }        return ret;    }        /**     * 判断上传前的文件类型是否为可以识别的类型     * <p>     * @return 如果文件类型不能处理,返回false,否则返回ture。     */    public boolean isValidFileType() {        if (filename == null) {            return true;        }         if ((filename.toLowerCase().endsWith(".gif")) ||                (filename.toLowerCase().endsWith(".jpg"))) {            return true;        }        return false;    }        /**     * 返回上传前在客户端的文件名     *     * @return 上传前在客户端的文件名     */    public String getClientFileName() {        return clientFileName;    }        /**     * 设置上传前在客户端的文件名     *     * @param clientFileName 上传前在客户端的文件名     */    public void setClientFileName(String clientFileName) {        this.clientFileName = clientFileName;    }        public void setSizeThreshold(int value) {        sizeThreshold = value;    }        /**     * 返回上传文件的OutputStream对象     *     * @return A上传文件的OutputStream对象     */    public OutputStream getOutputStream(String clientFileName,            long sizeMax) throws IOException {        this.clientFileName = clientFileName;        sizeThreshold = sizeMax;        if (memoryOutputStream == null) {            memoryOutputStream = new ByteArrayOutputStream((int)sizeMax);        }        return memoryOutputStream;    }        public String getClientShortName() {        String ret = "";        if (clientFileName != null) {            int index = clientFileName.lastIndexOf('\\');            if (index>-1) {                ret = clientFileName.substring(index+1);            }        }        return ret;    }            /**     * 把图像写入到磁盘保存     * <p>     * @param file 要保存到的File对象。     *     */    public void write(File file) throws Exception {                FileOutputStream fout = null;        if (memoryOutputStream!=null) {            try {                fout = new FileOutputStream(file);                fout.write(memoryOutputStream.toByteArray());            } finally {                if (fout != null) {                    fout.close();                }            }        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -