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

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

?? multipartstream.java

?? 解觖java技術(shù)中后臺(tái)無法上傳數(shù)給的情況
?? JAVA
?? 第 1 頁 / 共 2 頁
字號(hào):
/*
 * Copyright 2001-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 net.myvietnam.mvncore.web.fileupload;

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

/**
 * <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 example of usage of this class.<br>
 *
 * <pre>
 *    try {
 *        MultipartStream multipartStream = new MultipartStream(input,
 *                                                              boundary);
 *        boolean nextPart = multipartStream.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>
 * @author Sean C. Sullivan
 *
 * @version $Id: MultipartStream.java,v 1.2 2006/02/12 04:43:11 minhnn Exp $
 */
public class MultipartStream {

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


    /**
     * The Carriage Return ASCII character value.
     */
    public static final byte CR = 0x0D;


    /**
     * The Line Feed ASCII character value.
     */
    public static final byte LF = 0x0A;


    /**
     * The dash (-) ASCII character value.
     */
    public static final byte DASH = 0x2D;


    /**
     * 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 = {
            CR, LF, CR, LF };


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


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


    /**
     * A byte sequence that precedes a boundary (<code>CRLF--</code>).
     */
    protected static final byte[] BOUNDARY_PREFIX = {
            CR, LF, DASH, DASH};


    /**
     * The number of bytes, over and above the boundary size, to use for the
     * keep region.
     */
    private static final int KEEP_REGION_PAD = 3;


    // ----------------------------------------------------------- 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;


    /**
     * The content encoding to use when reading headers.
     */
    private String headerEncoding;


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


    /**
     * Default constructor.
     *
     * @see #MultipartStream(InputStream, byte[], int)
     * @see #MultipartStream(InputStream, byte[])
     *
     */
    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.
     *
     *
     * @see #MultipartStream()
     * @see #MultipartStream(InputStream, byte[])
     *
     */
    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 + BOUNDARY_PREFIX.length];
        this.boundaryLength = boundary.length + BOUNDARY_PREFIX.length;
        this.keepRegion = boundary.length + KEEP_REGION_PAD;
        System.arraycopy(BOUNDARY_PREFIX, 0, this.boundary, 0,
                BOUNDARY_PREFIX.length);
        System.arraycopy(boundary, 0, this.boundary, BOUNDARY_PREFIX.length,
                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>.
     *
     * @throws IOException when an error occurs.
     *
     * @see #MultipartStream()
     * @see #MultipartStream(InputStream, byte[], int)
     *
     */
    public MultipartStream(InputStream input,
                           byte[] boundary)
        throws IOException {
        this(input, boundary, DEFAULT_BUFSIZE);
    }


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


    /**
     * Retrieves the character encoding used when reading the headers of an
     * individual part. When not specified, or <code>null</code>, the platform
     * default encoding is used.

     *
     * @return The encoding used to read part headers.
     */
    public String getHeaderEncoding() {
        return headerEncoding;
    }


    /**
     * Specifies the character encoding to be used when reading the headers of
     * individual parts. When not specified, or <code>null</code>, the platform
     * default encoding is used.
     *
     * @param encoding The encoding used to read part headers.
     */
    public void setHeaderEncoding(String encoding) {
        headerEncoding = encoding;
    }


    /**
     * Reads a byte from the <code>buffer</code>, and refills it as
     * necessary.
     *
     * @return The next byte from the input stream.
     *
     * @throws 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.
     *
     * @throws 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();
            if (marker[0] == LF) {
                // Work around IE5 Mac bug with input type=image.
                // Because the boundary delimiter, not including the trailing
                // CRLF, must not appear within any file (RFC 2046, section
                // 5.1.1), we know the missing CR is due to a buggy browser
                // rather than a file containing something similar to a
                // boundary.
                return true;
            }

            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.
     *
     * @throws 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 - BOUNDARY_PREFIX.length) {
            throw new IllegalBoundaryException(
                    "The length of a boundary token can not be changed");
        }
        System.arraycopy(boundary, 0, this.boundary, BOUNDARY_PREFIX.length,
                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

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久网站最新地址| 伊人开心综合网| 久久久综合网站| 久久影院电视剧免费观看| 欧美成人性战久久| 欧美一区二区三区性视频| 7777精品伊人久久久大香线蕉的| 欧美中文字幕一区二区三区 | 国产成人自拍网| 国产一区二区三区黄视频| 国内精品久久久久影院一蜜桃| 久久电影国产免费久久电影| 久久99精品国产麻豆婷婷| 久久99久久精品| 国产成人高清在线| 成人av集中营| 色婷婷狠狠综合| 欧美视频在线播放| 欧美一区二区三区思思人| 欧美电影免费观看高清完整版在线观看 | 亚洲日本乱码在线观看| 综合久久久久久| 亚洲一区视频在线| 男人的天堂亚洲一区| 国产久卡久卡久卡久卡视频精品| 成人性生交大片| 日本精品一区二区三区高清| 欧美群妇大交群中文字幕| 日韩视频在线观看一区二区| 久久理论电影网| 亚洲精品日韩一| 免费成人在线观看视频| 国产精品夜夜嗨| 色哟哟国产精品免费观看| 777亚洲妇女| 久久精品视频一区| 亚洲免费看黄网站| 午夜视频久久久久久| 韩国精品免费视频| 成人免费毛片app| 欧美精品在线一区二区三区| 久久日韩精品一区二区五区| 亚洲欧洲中文日韩久久av乱码| 五月婷婷综合在线| 国产成人在线电影| 欧美中文字幕久久| 久久蜜桃一区二区| 一区二区三区高清在线| 久久精品国产99| 色婷婷综合久久久久中文 | 中文字幕亚洲欧美在线不卡| 亚洲电影中文字幕在线观看| 国内久久精品视频| 色悠悠亚洲一区二区| 26uuu亚洲综合色| 亚洲一区在线视频| 国产成人欧美日韩在线电影| 欧美三级中文字幕在线观看| 久久久久久久久97黄色工厂| 亚洲国产日韩av| 成人免费视频网站在线观看| 欧美人妇做爰xxxⅹ性高电影 | 视频一区视频二区中文| www.日韩在线| 精品国产欧美一区二区| 亚洲成va人在线观看| 粉嫩13p一区二区三区| 91精品婷婷国产综合久久竹菊| 国产精品三级av在线播放| 日本不卡高清视频| 色94色欧美sute亚洲线路一ni| 久久久精品一品道一区| 午夜伦理一区二区| 色综合久久天天| 国产午夜精品久久久久久免费视 | 国产免费成人在线视频| 日韩中文欧美在线| 日本精品一区二区三区高清 | 成人av电影在线网| 亚洲精品一区二区三区福利| 天堂va蜜桃一区二区三区漫画版| 99精品欧美一区二区三区小说| 精品国产髙清在线看国产毛片| 亚洲午夜免费电影| 在线一区二区视频| 中文字幕在线不卡视频| 丰满岳乱妇一区二区三区| 精品国产第一区二区三区观看体验 | 亚洲精品日日夜夜| 99精品欧美一区二区蜜桃免费| 国产精品你懂的| 国产成人av在线影院| 精品国产乱码久久久久久免费| 日韩av一区二区在线影视| 欧美日本一道本在线视频| 亚洲免费视频中文字幕| 成人av综合在线| 国产精品天干天干在线综合| 国产福利91精品| 国产午夜精品一区二区 | 欧美三级乱人伦电影| 亚洲免费在线观看视频| 色综合天天综合| 中文字幕日本乱码精品影院| 成人综合日日夜夜| 国产欧美日本一区二区三区| 国产成人一区在线| 国产精品人妖ts系列视频| 成人高清视频在线| 中文字幕在线视频一区| 99re在线精品| 亚洲一卡二卡三卡四卡| 欧美日韩成人一区二区| 青青草国产成人99久久| 日韩精品在线网站| 国产经典欧美精品| 中文字幕一区在线| 91色综合久久久久婷婷| 亚洲一级不卡视频| 在线播放91灌醉迷j高跟美女| 日韩成人精品在线观看| www久久精品| 成人黄色软件下载| 亚洲免费在线播放| 这里是久久伊人| 精品一区二区免费视频| 欧美韩国一区二区| 91色在线porny| 爽爽淫人综合网网站| 精品美女一区二区| av中文一区二区三区| 亚洲午夜激情av| 日韩久久免费av| 成人av片在线观看| 亚洲一区av在线| 精品久久久久一区| av激情亚洲男人天堂| 亚洲成在线观看| 久久综合九色综合97婷婷女人| 成人福利电影精品一区二区在线观看| 亚洲欧美电影一区二区| 欧美一区二区三区白人| 国产不卡视频在线观看| 亚洲一区二区三区美女| 欧美精品一区二区三区高清aⅴ | 久久疯狂做爰流白浆xx| 中文字幕制服丝袜成人av| 欧美高清一级片在线| 国产一区二区三区四区五区美女| 亚洲视频免费在线| 欧美一区二区日韩一区二区| 不卡视频一二三| 日本不卡的三区四区五区| 国产精品亲子乱子伦xxxx裸| 欧美三级三级三级| 国产成人精品免费在线| 日韩电影免费在线看| 国产精品国产馆在线真实露脸 | 欧美妇女性影城| 国产成a人无v码亚洲福利| 亚洲国产精品久久艾草纯爱| 久久网站热最新地址| 欧美三级中文字| 不卡视频在线观看| 久久se精品一区精品二区| 亚洲精品一二三| 久久久亚洲欧洲日产国码αv| 欧美日韩一区二区三区视频 | 国产精品人成在线观看免费| 欧美疯狂性受xxxxx喷水图片| 国产91精品在线观看| 日本女人一区二区三区| 亚洲欧美日韩久久精品| 久久精品夜夜夜夜久久| 7777精品伊人久久久大香线蕉的| 色综合中文综合网| 日本系列欧美系列| 亚洲日本欧美天堂| 国产亚洲欧美色| 欧美一区二区高清| 欧美性一区二区| 99久久综合狠狠综合久久| 久久不见久久见免费视频1| 午夜精品福利在线| 亚洲免费成人av| 国产精品色一区二区三区| 精品国产网站在线观看| 91精品国产综合久久精品图片| 色一情一伦一子一伦一区| 国产一区二区精品久久91| 喷白浆一区二区| 亚洲成人中文在线| 亚洲乱码日产精品bd| 国产精品白丝在线| 国产精品色噜噜| 国产精品免费免费| 国产亚洲一区二区三区四区| 欧美α欧美αv大片| 欧美一二三区在线| 欧美一区二区三区在线电影 |