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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? multipartstream.java

?? java servlet著名論壇源代碼
?? JAVA
?? 第 1 頁 / 共 2 頁
字號:
/*
 * $Header: /cvsroot/mvnforum/myvietnam/src/net/myvietnam/mvncore/fileupload/MultipartStream.java,v 1.2 2002/11/26 03:23:57 minhnn Exp $
 * $Revision: 1.2 $
 * $Date: 2002/11/26 03:23:57 $
 *
 * ====================================================================
 *
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution, if
 *    any, must include the following acknowlegement:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowlegement may appear in the software itself,
 *    if and wherever such third-party acknowlegements normally appear.
 *
 * 4. The names "The Jakarta Project", "Commons", and "Apache Software
 *    Foundation" must not be used to endorse or promote products derived
 *    from this software without prior written permission. For written
 *    permission, please contact apache@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache"
 *    nor may "Apache" appear in their names without prior written
 *    permission of the Apache Group.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 *
 */


package net.myvietnam.mvncore.fileupload;


import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;


/**
 * <p> Low level API for processing file uploads.
 *
 * <p> This class can be used to process data streams conforming to MIME
 * 'multipart' format as defined in
 * <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>. Arbitrarily
 * large amounts of data in the stream can be processed under constant
 * memory usage.
 *
 * <p> The format of the stream is defined in the following way:<br>
 *
 * <code>
 *   multipart-body := preamble 1*encapsulation close-delimiter epilogue<br>
 *   encapsulation := delimiter body CRLF<br>
 *   delimiter := "--" boundary CRLF<br>
 *   close-delimiter := "--" boudary "--"<br>
 *   preamble := &lt;ignore&gt;<br>
 *   epilogue := &lt;ignore&gt;<br>
 *   body := header-part CRLF body-part<br>
 *   header-part := 1*header CRLF<br>
 *   header := header-name ":" header-value<br>
 *   header-name := &lt;printable ascii characters except ":"&gt;<br>
 *   header-value := &lt;any ascii characters except CR & LF&gt;<br>
 *   body-data := &lt;arbitrary data&gt;<br>
 * </code>
 *
 * <p>Note that body-data can contain another mulipart entity.  There
 * is limited support for single pass processing of such nested
 * streams.  The nested stream is <strong>required</strong> to have a
 * boundary token of the same length as the parent stream (see {@link
 * #setBoundary(byte[])}).
 *
 * <p>Here is an exaple of usage of this class.<br>
 *
 * <pre>
 *    try {
 *        MultipartStream multipartStream = new MultipartStream(input,
 *                                                              boundary);
 *        boolean nextPart = malitPartStream.skipPreamble();
 *        OutputStream output;
 *        while(nextPart) {
 *            header = chunks.readHeader();
 *            // process headers
 *            // create some output stream
 *            multipartStream.readBodyPart(output);
 *            nextPart = multipartStream.readBoundary();
 *        }
 *    } catch(MultipartStream.MalformedStreamException e) {
 *          // the stream failed to follow required syntax
 *    } catch(IOException) {
 *          // a read or write error occurred
 *    }
 *
 * </pre>
 *
 * @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
 * @author <a href="mailto:martinc@apache.org">Martin Cooper</a>
 *
 * @version $Id: MultipartStream.java,v 1.2 2002/11/26 03:23:57 minhnn Exp $
 */
public class MultipartStream
{

    // ----------------------------------------------------- Manifest constants


    /**
     * The maximum length of <code>header-part</code> that will be
     * processed (10 kilobytes = 10240 bytes.).
     */
    public static final int HEADER_PART_SIZE_MAX = 10240;


    /**
     * The default length of the buffer used for processing a request.
     */
    protected static final int DEFAULT_BUFSIZE = 4096;


    /**
     * A byte sequence that marks the end of <code>header-part</code>
     * (<code>CRLFCRLF</code>).
     */
    protected static final byte[] HEADER_SEPARATOR = {0x0D, 0x0A, 0x0D, 0x0A};


    /**
     * A byte sequence that that follows a delimiter that will be
     * followed by an encapsulation (<code>CRLF</code>).
     */
    protected static final byte[] FIELD_SEPARATOR = { 0x0D, 0x0A };


    /**
     * A byte sequence that that follows a delimiter of the last
     * encapsulation in the stream (<code>--</code>).
     */
    protected static final byte[] STREAM_TERMINATOR = { 0x2D, 0x2D };


    // ----------------------------------------------------------- Data members


    /**
     * The input stream from which data is read.
     */
    private InputStream input;


    /**
     * The length of the boundary token plus the leading <code>CRLF--</code>.
     */
    private int boundaryLength;


    /**
     * The amount of data, in bytes, that must be kept in the buffer in order
     * to detect delimiters reliably.
     */
    private int keepRegion;


    /**
     * The byte sequence that partitions the stream.
     */
    private byte[] boundary;


    /**
     * The length of the buffer used for processing the request.
     */
    private int bufSize;


    /**
     * The buffer used for processing the request.
     */
    private byte[] buffer;


    /**
     * The index of first valid character in the buffer.
     * <br>
     * 0 <= head < bufSize
     */
    private int head;


    /**
     * The index of last valid characer in the buffer + 1.
     * <br>
     * 0 <= tail <= bufSize
     */
    private int tail;


    // ----------------------------------------------------------- Constructors


    /**
     * Default constructor.
     */
    public MultipartStream()
    {
    }


    /**
     * <p> Constructs a <code>MultipartStream</code> with a custom size buffer.
     *
     * <p> Note that the buffer must be at least big enough to contain the
     * boundary string, plus 4 characters for CR/LF and double dash, plus at
     * least one byte of data.  Too small a buffer size setting will degrade
     * performance.
     *
     * @param input    The <code>InputStream</code> to serve as a data source.
     * @param boundary The token used for dividing the stream into
     *                 <code>encapsulations</code>.
     * @param bufSize  The size of the buffer to be used, in bytes.
     */
    public MultipartStream(InputStream input,
                           byte[] boundary,
                           int bufSize)
    {
        this.input = input;
        this.bufSize = bufSize;
        this.buffer = new byte[bufSize];

        // We prepend CR/LF to the boundary to chop trailng CR/LF from
        // body-data tokens.
        this.boundary = new byte[boundary.length + 4];
        this.boundaryLength = boundary.length + 4;
        this.keepRegion = boundary.length + 3;
        this.boundary[0] = 0x0D;
        this.boundary[1] = 0x0A;
        this.boundary[2] = 0x2D;
        this.boundary[3] = 0x2D;
        System.arraycopy(boundary, 0, this.boundary, 4, boundary.length);

        head = 0;
        tail = 0;
    }


    /**
     * <p> Constructs a <code>MultipartStream</code> with a default size buffer.
     *
     * @param input    The <code>InputStream</code> to serve as a data source.
     * @param boundary The token used for dividing the stream into
     *                 <code>encapsulations</code>.
     *
     * @exception IOException when an error occurs.
     */
    public MultipartStream(InputStream input,
                           byte[] boundary)
        throws IOException
    {
        this(input, boundary, DEFAULT_BUFSIZE);
    }


    // --------------------------------------------------------- Public methods


    /**
     * Reads a byte from the <code>buffer</code>, and refills it as
     * necessary.
     *
     * @return The next byte from the input stream.
     *
     * @exception IOException if there is no more data available.
     */
    public byte readByte()
        throws IOException
    {
        // Buffer depleted ?
        if (head == tail)
        {
            head = 0;
            // Refill.
            tail = input.read(buffer, head, bufSize);
            if (tail == -1)
            {
                // No more data available.
                throw new IOException("No more data is available");
            }
        }
        return buffer[head++];
    }


    /**
     * Skips a <code>boundary</code> token, and checks whether more
     * <code>encapsulations</code> are contained in the stream.
     *
     * @return <code>true</code> if there are more encapsulations in
     *         this stream; <code>false</code> otherwise.
     *
     * @exception MalformedStreamException if the stream ends unexpecetedly or
     *                                     fails to follow required syntax.
     */
    public boolean readBoundary()
        throws MalformedStreamException
    {
        byte[] marker = new byte[2];
        boolean nextChunk = false;

        head += boundaryLength;
        try
        {
            marker[0] = readByte();
            marker[1] = readByte();
            if (arrayequals(marker, STREAM_TERMINATOR, 2))
            {
                nextChunk = false;
            }
            else if (arrayequals(marker, FIELD_SEPARATOR, 2))
            {
                nextChunk = true;
            }
            else
            {
                throw new MalformedStreamException(
                        "Unexpected characters follow a boundary");
            }
        }
        catch (IOException e)
        {
            throw new MalformedStreamException("Stream ended unexpectedly");
        }
        return nextChunk;
    }


    /**
     * <p>Changes the boundary token used for partitioning the stream.
     *
     * <p>This method allows single pass processing of nested multipart
     * streams.
     *
     * <p>The boundary token of the nested stream is <code>required</code>
     * to be of the same length as the boundary token in parent stream.
     *
     * <p>Restoring the parent stream boundary token after processing of a
     * nested stream is left to the application.
     *
     * @param boundary The boundary to be used for parsing of the nested
     *                 stream.
     *
     * @exception IllegalBoundaryException if the <code>boundary</code>
     *                                     has a different length than the one
     *                                     being currently parsed.
     */
    public void setBoundary(byte[] boundary)
        throws IllegalBoundaryException
    {
        if (boundary.length != boundaryLength - 4)
        {
            throw new IllegalBoundaryException(
                    "The length of a boundary token can not be changed");
        }
        System.arraycopy(boundary, 0, this.boundary, 4, boundary.length);
    }


    /**
     * <p>Reads the <code>header-part</code> of the current
     * <code>encapsulation</code>.
     *
     * <p>Headers are returned verbatim to the input stream, including the
     * trailing <code>CRLF</code> marker. Parsing is left to the
     * application.
     *
     * <p><strong>TODO</strong> allow limiting maximum header size to
     * protect against abuse.
     *
     * @return The <code>header-part</code> of the current encapsulation.
     *
     * @exception MalformedStreamException if the stream ends unexpecetedly.
     */
    public String readHeaders()
        throws MalformedStreamException
    {
        int i = 0;
        byte b[] = new byte[1];
        StringBuffer buf = new StringBuffer();
        int sizeMax = HEADER_PART_SIZE_MAX;
        int size = 0;
        while (i < 4)
        {
            try
            {
                b[0] = readByte();
            }
            catch (IOException e)
            {
                throw new MalformedStreamException("Stream ended unexpectedly");

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
宅男噜噜噜66一区二区66| 成人av在线一区二区三区| 欧美电视剧在线看免费| 麻豆免费精品视频| 精品国产污网站| 国产成人在线视频免费播放| 国产精品福利一区二区| 在线观看国产91| 奇米888四色在线精品| 久久久国产精品麻豆| www.色精品| 亚洲成a人在线观看| 日韩欧美亚洲国产另类| 成人免费观看男女羞羞视频| 悠悠色在线精品| 日韩一级黄色大片| 成人av电影观看| 日本视频免费一区| 日本一区二区电影| 久久精品欧美日韩精品| caoporm超碰国产精品| 午夜天堂影视香蕉久久| 久久女同精品一区二区| 91九色02白丝porn| 日韩精品一二三四| 国产精品毛片大码女人| 欧美日韩一二区| 国产电影一区在线| 亚洲午夜免费电影| 国产视频一区二区三区在线观看| 色噜噜久久综合| 激情综合色播五月| 一区二区三区精品视频| 精品国产伦一区二区三区免费| 成人久久18免费网站麻豆| 日本欧美一区二区在线观看| 国产精品视频免费| 日韩小视频在线观看专区| 成人av网站免费| 蜜臀av性久久久久蜜臀av麻豆| 亚洲天堂福利av| 久久久亚洲精品石原莉奈| 欧美午夜精品理论片a级按摩| 国产成人免费视频网站高清观看视频| 亚洲成人激情社区| 亚洲女爱视频在线| 亚洲国产精品av| 精品人在线二区三区| 欧美亚洲禁片免费| av一区二区三区四区| 狠狠色丁香久久婷婷综合_中| 日日夜夜精品视频免费| 亚洲欧美日韩一区二区 | 欧美国产日韩精品免费观看| 欧美精三区欧美精三区| 日本韩国精品在线| 暴力调教一区二区三区| 国产激情一区二区三区| 久88久久88久久久| 美女爽到高潮91| 青青草91视频| 日产精品久久久久久久性色 | 亚洲国产aⅴ成人精品无吗| 国产精品无遮挡| 久久久久久99精品| 久久麻豆一区二区| 欧美白人最猛性xxxxx69交| 91精品免费观看| 91麻豆精品91久久久久同性| 欧美日韩国产精品自在自线| 欧美色图激情小说| 欧美日韩在线播| 欧美日韩一区二区在线观看视频 | 欧美美女激情18p| 色天天综合色天天久久| 91麻豆精品一区二区三区| av不卡免费电影| 色综合一区二区三区| 91在线视频官网| 色婷婷av一区二区三区之一色屋| 91丨porny丨蝌蚪视频| 色综合天天综合在线视频| 91欧美激情一区二区三区成人| av电影在线不卡| 在线免费观看日本欧美| 欧美日韩激情在线| 精品国产乱码久久久久久图片| 精品成a人在线观看| 久久亚洲春色中文字幕久久久| 精品对白一区国产伦| 日韩视频在线观看一区二区| 久久久美女艺术照精彩视频福利播放| 久久看人人爽人人| 亚洲欧美另类图片小说| 亚洲高清免费视频| 国产一区二区按摩在线观看| 国产99久久久国产精品潘金| 91免费观看在线| 欧美巨大另类极品videosbest| 精品久久久久久久人人人人传媒 | 91久久精品国产91性色tv| 欧美在线观看你懂的| 日韩一本二本av| 日本一二三四高清不卡| 亚洲综合网站在线观看| 蜜臀av一区二区在线观看| 大胆亚洲人体视频| 欧美亚洲精品一区| 久久久精品免费观看| 亚洲精品一二三四区| 六月丁香综合在线视频| 99热这里都是精品| 欧美一区2区视频在线观看| 国产欧美日韩在线看| 樱桃视频在线观看一区| 麻豆中文一区二区| 91啪九色porn原创视频在线观看| 欧美一区二区三区免费在线看 | 成人欧美一区二区三区1314| 亚洲电影在线播放| 粉嫩aⅴ一区二区三区四区| 欧美性一级生活| 国产女人水真多18毛片18精品视频 | 亚洲欧美日韩久久| 久久精品国产99| 欧美日韩综合在线免费观看| 久久久www免费人成精品| 亚洲成av人片| 9人人澡人人爽人人精品| 日韩午夜在线观看视频| 一区二区成人在线| 国产·精品毛片| 亚洲激情校园春色| 不卡的av电影| 欧美www视频| 亚洲国产sm捆绑调教视频| 成人精品gif动图一区| 欧美一区二区三区婷婷月色| 亚洲欧美另类久久久精品2019| 国产一区二区三区四区五区美女 | 久久久久久久久蜜桃| 亚洲3atv精品一区二区三区| 菠萝蜜视频在线观看一区| 欧美一级爆毛片| 婷婷久久综合九色综合绿巨人| 色婷婷精品大在线视频| 久久精品综合网| 激情综合五月天| 日韩精品资源二区在线| 午夜视频在线观看一区| 色狠狠av一区二区三区| 国产精品久久久久久久久动漫| 国产在线不卡一区| 精品国产乱码久久久久久免费 | 成人综合在线观看| 国产日韩成人精品| 国产精品一品视频| 久久综合九色综合欧美98 | 国产高清久久久| 国产亚洲人成网站| 国产成人8x视频一区二区| 久久综合久久鬼色| 国产精品乡下勾搭老头1| 国产亚洲综合色| 国产成人免费在线| 国产精品久久久久久久久免费相片| 国产美女精品人人做人人爽| 久久久噜噜噜久噜久久综合| 国产在线不卡一卡二卡三卡四卡| 精品嫩草影院久久| 经典三级在线一区| 日本一区二区免费在线| 成人精品视频一区二区三区尤物| 日韩一区欧美小说| 在线观看日韩国产| 婷婷一区二区三区| 精品区一区二区| 成人黄色a**站在线观看| 中文字幕一区免费在线观看| 99麻豆久久久国产精品免费| 亚洲免费观看高清| 69av一区二区三区| 国产综合色产在线精品| 国产精品久久久久久久久免费桃花| 91原创在线视频| 日韩国产高清在线| 久久午夜羞羞影院免费观看| 成人午夜激情在线| 一区二区三区丝袜| 欧美一区二区女人| 国产激情精品久久久第一区二区| 中文字幕一区二区三区乱码在线 | 日韩三级伦理片妻子的秘密按摩| 看电影不卡的网站| 日本一区二区三级电影在线观看 | 中文字幕精品在线不卡| 色呦呦日韩精品| 日韩1区2区日韩1区2区| 国产精品天美传媒| 欧美日韩一区二区在线观看|