亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來(lái)到蟲(chóng)蟲(chóng)下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲(chóng)蟲(chóng)下載站

?? downloadaction.java

?? struts的源代碼
?? JAVA
字號(hào):
/*
 * $Id: DownloadAction.java 164530 2005-04-25 03:11:07Z niallp $
 *
 * Copyright 2004-2005 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


package org.apache.struts.actions;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;


/**
 * This is an abstract base class that minimizes the amount of special coding
 * that needs to be written to download a file. All that is required to use
 * this class is to extend it and implement the <code>getStreamInfo()</code>
 * method so that it returns the relevant information for the file (or other
 * stream) to be downloaded. Optionally, the <code>getBufferSize()</code>
 * method may be overridden to customize the size of the buffer used to
 * transfer the file.
 *
 * @since Struts 1.2.6
 */
public abstract class DownloadAction extends Action {

    /**
     * If the <code>getBufferSize()</code> method is not overridden, this is
     * the buffer size that will be used to transfer the data to the servlet
     * output stream.
     */
    protected static final int DEFAULT_BUFFER_SIZE = 1024 * 4;

    /**
     * Returns the information on the file, or other stream, to be downloaded
     * by this action. This method must be implemented by an extending class.
     *
     * @param mapping  The ActionMapping used to select this instance.
     * @param form     The optional ActionForm bean for this request (if any).
     * @param request  The HTTP request we are processing.
     * @param response The HTTP response we are creating.
     *
     * @return The information for the file to be downloaded.
     *
     * @throws Exception if an exception occurs.
     */
    protected abstract StreamInfo getStreamInfo(ActionMapping mapping,
            ActionForm form, HttpServletRequest request,
            HttpServletResponse response)
            throws Exception;

    /**
     * Returns the size of the buffer to be used in transferring the data to
     * the servlet output stream. This method may be overridden by an extending
     * class in order to customize the buffer size.
     *
     * @return The size of the transfer buffer, in bytes.
     */
    protected int getBufferSize() {
        return DEFAULT_BUFFER_SIZE;
    }

    /**
     * Process the specified HTTP request, and create the corresponding HTTP
     * response (or forward to another web component that will create it).
     * Return an <code>ActionForward</code> instance describing where and how
     * control should be forwarded, or <code>null</code> if the response has
     * already been completed.
     *
     * @param mapping  The ActionMapping used to select this instance.
     * @param form     The optional ActionForm bean for this request (if any).
     * @param request  The HTTP request we are processing.
     * @param response The HTTP response we are creating.
     *
     * @throws Exception if an exception occurs.
     */
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        StreamInfo info = getStreamInfo(mapping, form, request, response);
        String contentType = info.getContentType();
        InputStream stream = info.getInputStream();

        try {
            response.setContentType(contentType);
            copy(stream, response.getOutputStream());
        } finally {
            if (stream != null) {
                stream.close();
            }
        }

        // Tell Struts that we are done with the response.
        return null;
    }

    /**
     * Copy bytes from an <code>InputStream</code> to an
     * <code>OutputStream</code>.
     *
     * @param input  The <code>InputStream</code> to read from.
     * @param output The <code>OutputStream</code> to write to.
     *
     * @return the number of bytes copied
     *
     * @throws IOException In case of an I/O problem
     */
    public int copy(InputStream input, OutputStream output)
            throws IOException {
        byte[] buffer = new byte[getBufferSize()];
        int count = 0;
        int n = 0;
        while (-1 != (n = input.read(buffer))) {
            output.write(buffer, 0, n);
            count += n;
        }
        return count;
    }

    /**
     * The information on a file, or other stream, to be downloaded by the
     * <code>DownloadAction</code>.
     */
    public static interface StreamInfo {

        /**
         * Returns the content type of the stream to be downloaded.
         *
         * @return The content type of the stream.
         */
        public abstract String getContentType();

        /**
         * Returns an input stream on the content to be downloaded. This stream
         * will be closed by the <code>DownloadAction</code>.
         *
         * @return The input stream for the content to be downloaded.
         */
        public abstract InputStream getInputStream() throws IOException;
    }

    /**
     * A concrete implementation of the <code>StreamInfo</code> interface which
     * simplifies the downloading of a file from the disk.
     */
    public static class FileStreamInfo implements StreamInfo {

        /**
         * The content type for this stream.
         */
        private String contentType;

        /**
         * The file to be downloaded.
         */
        private File file;

        /**
         * Constructs an instance of this class, based on the supplied
         * parameters.
         *
         * @param contentType The content type of the file.
         * @param file        The file to be downloaded.
         */
        public FileStreamInfo(String contentType, File file) {
            this.contentType = contentType;
            this.file = file;
        }

        /**
         * Returns the content type of the stream to be downloaded.
         *
         * @return The content type of the stream.
         */
        public String getContentType() {
            return this.contentType;
        }

        /**
         * Returns an input stream on the file to be downloaded. This stream
         * will be closed by the <code>DownloadAction</code>.
         *
         * @return The input stream for the file to be downloaded.
         */
        public InputStream getInputStream() throws IOException {
            FileInputStream fis = new FileInputStream(file);
            BufferedInputStream bis = new BufferedInputStream(fis);
            return bis;
        }
    }

    /**
     * A concrete implementation of the <code>StreamInfo</code> interface which
     * simplifies the downloading of a web application resource.
     */
    public static class ResourceStreamInfo implements StreamInfo {

        /**
         * The content type for this stream.
         */
        private String contentType;

        /**
         * The servlet context for the resource to be downloaded.
         */
        private ServletContext context;

        /**
         * The path to the resource to be downloaded.
         */
        private String path;

        /**
         * Constructs an instance of this class, based on the supplied
         * parameters.
         *
         * @param contentType The content type of the file.
         * @param context     The servlet context for the resource.
         * @param path        The path to the resource to be downloaded.
         */
        public ResourceStreamInfo(String contentType, ServletContext context,
                String path) {
            this.contentType = contentType;
            this.context = context;
            this.path = path;
        }

        /**
         * Returns the content type of the stream to be downloaded.
         *
         * @return The content type of the stream.
         */
        public String getContentType() {
            return this.contentType;
        }

        /**
         * Returns an input stream on the resource to be downloaded. This stream
         * will be closed by the <code>DownloadAction</code>.
         *
         * @return The input stream for the resource to be downloaded.
         */
        public InputStream getInputStream() throws IOException {
            return context.getResourceAsStream(path);
        }
    }
}

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产欧美1区2区3区| 不卡av电影在线播放| 国产精品一区在线观看乱码| 99久久er热在这里只有精品66| 色偷偷一区二区三区| 欧美一区二区精品| 国产精品久久夜| 日一区二区三区| 成人免费不卡视频| 国产精品久久久久影视| 亚洲成人免费电影| 国产成人三级在线观看| 欧美怡红院视频| 久久人人超碰精品| 夜夜嗨av一区二区三区四季av| 美女视频一区二区| 91蝌蚪国产九色| 精品剧情v国产在线观看在线| 中文字幕一区二区不卡 | 成人精品免费视频| 精品视频999| 中文字幕高清一区| 日本成人在线视频网站| 99国产精品99久久久久久| 欧美mv日韩mv国产| 亚洲国产aⅴ天堂久久| 成人午夜av影视| 日韩女优制服丝袜电影| 亚洲精品国产无套在线观| 国产精一品亚洲二区在线视频| 欧美视频在线一区| 国产精品久久久久三级| 国产在线精品不卡| 91精品国产一区二区| 亚洲裸体在线观看| 高清beeg欧美| 欧美成人国产一区二区| 水蜜桃久久夜色精品一区的特点 | 一区二区三区四区五区视频在线观看| 狠狠色伊人亚洲综合成人| 在线不卡a资源高清| 伊人开心综合网| 成人激情视频网站| 久久精品人人做人人综合 | 精品国产百合女同互慰| 亚洲电影在线免费观看| 99精品欧美一区二区蜜桃免费| 久久久不卡网国产精品二区| 美腿丝袜亚洲综合| 777亚洲妇女| 亚洲大片精品永久免费| 一本大道久久a久久综合| 国产欧美日韩亚州综合| 国产在线精品视频| 久久婷婷国产综合国色天香| 久久国产综合精品| 日韩一区二区三区免费看| 日韩影院在线观看| 欧美日韩中文字幕精品| 一区二区三区日韩在线观看| 91视频xxxx| 亚洲人精品午夜| 一本久道中文字幕精品亚洲嫩 | 欧美午夜理伦三级在线观看| 亚洲综合一区在线| 欧美综合视频在线观看| 亚洲第一在线综合网站| 欧美日韩国产成人在线免费| 五月天久久比比资源色| 欧美美女网站色| 日韩专区中文字幕一区二区| 日韩欧美精品在线视频| 久久不见久久见中文字幕免费| 欧美大片一区二区| 国产一区二区三区蝌蚪| 国产亚洲福利社区一区| 国产suv一区二区三区88区| 国产精品国产自产拍高清av| 99九九99九九九视频精品| 亚洲靠逼com| 欧美日韩视频在线一区二区| 日韩**一区毛片| 久久综合九色综合97婷婷女人| 国产福利一区在线观看| 国产精品视频一区二区三区不卡| 成人av在线播放网站| 国产精品美女久久福利网站| 99久久精品99国产精品| 亚洲国产三级在线| 欧美videos大乳护士334| 高清不卡在线观看av| 亚洲手机成人高清视频| 欧美日韩性生活| 激情图片小说一区| 国产精品水嫩水嫩| 欧美三级韩国三级日本一级| 美腿丝袜亚洲一区| 日本一区二区电影| 国产亚洲一本大道中文在线| 波多野结衣欧美| 亚洲一区二区三区不卡国产欧美| 欧美一卡二卡三卡| 成人午夜视频在线观看| 亚洲成av人片在线| 久久婷婷一区二区三区| 一本到一区二区三区| 蜜臀av性久久久久蜜臀aⅴ四虎| 久久久久久久久一| 在线视频欧美精品| 精品一区二区三区日韩| 国产精品久久久久久户外露出 | 开心九九激情九九欧美日韩精美视频电影| 日韩视频免费观看高清完整版 | 国产欧美一区在线| 欧洲一区在线观看| 国产一区在线看| 亚洲精品午夜久久久| 精品精品欲导航| 色哦色哦哦色天天综合| 久久精品国产秦先生| 亚洲欧美偷拍卡通变态| 日韩女同互慰一区二区| 色哟哟在线观看一区二区三区| 奇米色一区二区| 最新中文字幕一区二区三区 | 国产成人一区在线| 亚洲一区二区美女| 国产欧美日韩精品在线| 欧美日韩国产片| 99国产精品国产精品久久| 九九九久久久精品| 亚洲一二三专区| 欧美国产一区在线| 日韩午夜电影av| 91亚洲男人天堂| 国产精品一区在线观看你懂的| 亚洲电影视频在线| 亚洲欧洲精品成人久久奇米网| 日韩免费电影一区| 欧美性xxxxx极品少妇| 99久久国产综合精品色伊 | 中文字幕乱码久久午夜不卡| 欧美精品18+| 色综合久久综合网97色综合| 国产麻豆精品theporn| 丝袜亚洲另类欧美| 樱花影视一区二区| 国产精品无码永久免费888| 精品免费国产一区二区三区四区| 欧洲精品在线观看| 99re在线精品| 91精品国产全国免费观看| 一道本成人在线| 懂色av一区二区夜夜嗨| 精品一区二区影视| 婷婷中文字幕一区三区| 一区二区三区日韩| 亚洲欧美激情视频在线观看一区二区三区| 久久伊人蜜桃av一区二区| 欧美一区二区三区成人| 欧美日韩一卡二卡| 欧美在线观看视频一区二区 | 亚洲国产日韩综合久久精品| 亚洲欧洲日韩av| 国产精品久久久久aaaa樱花| 欧美—级在线免费片| 久久免费的精品国产v∧| 日韩精品综合一本久道在线视频| 欧美日韩大陆在线| 欧美美女喷水视频| 欧美精选一区二区| 在线91免费看| 69av一区二区三区| 91麻豆精品国产91久久久| 欧美日韩一级大片网址| 欧美精品在线视频| 91精品视频网| 欧美一级在线免费| 日韩一区二区三区视频在线| 欧美一级高清大全免费观看| 91精品国产欧美一区二区成人| 在线综合+亚洲+欧美中文字幕| 欧美福利视频导航| 欧美一区二区三区男人的天堂| 日韩亚洲欧美高清| 亚洲精品一区二区三区福利| 精品粉嫩aⅴ一区二区三区四区| 欧美mv和日韩mv国产网站| 久久精品一区八戒影视| 久久精品一区二区| 一区在线观看免费| 日韩理论电影院| 一区二区三区国产豹纹内裤在线 | 日韩一区二区免费在线电影| 日韩精品中午字幕| 国产午夜精品一区二区| 中文欧美字幕免费| 国产精品国产三级国产a| 亚洲精品视频一区二区| 亚洲最新在线观看|