最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

快速解決commons-fileupload組件無(wú)法處理自定義head信息的bug

 更新時(shí)間:2013年08月30日 09:23:21   作者:  
問(wèn)題在于fileupload組件解析完自定義的head節(jié)點(diǎn)后,卻忘記傳遞到FileItemStreamImpl中了,稍作修訂,即可修正該bug
Jakarta commons fileupload組件可以處理HTTP請(qǐng)求及響應(yīng),很多時(shí)候被用來(lái)處理文件上傳,但是近期發(fā)現(xiàn),當(dāng)我們自定義文件上傳、自己組裝mime信息、文件上傳時(shí)加入自定義head節(jié)點(diǎn)時(shí),fileupload組件無(wú)法獲得自定義的head節(jié)點(diǎn),仔細(xì)分析了fileupload組件源代碼后,發(fā)現(xiàn)核心方法在FileUploadBase文件的findNextItem方法中,問(wèn)題在于fileupload組件解析完自定義的head節(jié)點(diǎn)后,卻忘記傳遞到FileItemStreamImpl中了,稍作修訂,即可修正該bug。
復(fù)制代碼 代碼如下:

/**解析文件列表
         * Called for finding the nex item, if any.
         * @return True, if an next item was found, otherwise false.
         * @throws IOException An I/O error occurred.
         */
        private boolean findNextItem() throws IOException {
            if (eof) {
                return false;
            }
            if (currentItem != null) {
                currentItem.close();
                currentItem = null;
            }
            for (;;) {
                boolean nextPart;
                if (skipPreamble) {
                    nextPart = multi.skipPreamble();
                } else {
                    nextPart = multi.readBoundary();
                }
                if (!nextPart) {
                    if (currentFieldName == null) {
                        // Outer multipart terminated -> No more data
                        eof = true;
                        return false;
                    }
                    // Inner multipart terminated -> Return to parsing the outer
                    multi.setBoundary(boundary);
                    currentFieldName = null;
                    continue;
                }
                FileItemHeaders headers = getParsedHeaders(multi.readHeaders());
                if (currentFieldName == null) {
                    // We're parsing the outer multipart
                    String fieldName = getFieldName(headers);
                    if (fieldName != null) {
                        String subContentType = headers.getHeader(CONTENT_TYPE);
                        if (subContentType != null
                                &&  subContentType.toLowerCase()
                                        .startsWith(MULTIPART_MIXED)) {
                            currentFieldName = fieldName;
                            // Multiple files associated with this field name
                            byte[] subBoundary = getBoundary(subContentType);
                            multi.setBoundary(subBoundary);
                            skipPreamble = true;
                            continue;
                        }
                        String fileName = getFileName(headers);
                        currentItem = new FileItemStreamImpl(fileName,
                                fieldName, headers.getHeader(CONTENT_TYPE),
                                fileName == null, getContentLength(headers));
                        notifier.noteItem();
                        itemValid = true;
                        return true;
                    }
                } else {
                    String fileName = getFileName(headers);
                    if (fileName != null) {
                             //這里代碼要修訂
                        //這是原來(lái)的代碼,沒(méi)有傳入header
                        //currentItem = new FileItemStreamImpl(fileName, currentFieldName,headers.getHeader(CONTENT_TYPE),false, getContentLength(headers));
                        //這是新的代碼,我們要傳入header
                        currentItem = new FileItemStreamImpl(fileName, currentFieldName,headers.getHeader(CONTENT_TYPE),false, getContentLength(headers),headers);
                        notifier.noteItem();
                        itemValid = true;
                        return true;
                    }
                }
                multi.discardBodyData();
            }
        }

 

            /**原始代碼,存在丟失FileItemHeaders信息的bug
             * Creates a new instance.
             * @param pName The items file name, or null.
             * @param pFieldName The items field name.
             * @param pContentType The items content type, or null.
             * @param pFormField Whether the item is a form field.
             * @param pContentLength The items content length, if known, or -1
             * @throws IOException Creating the file item failed.
             */
            FileItemStreamImpl(String pName, String pFieldName,
                    String pContentType, boolean pFormField,
                    long pContentLength) throws IOException {
                name = pName;
                fieldName = pFieldName;
                contentType = pContentType;
                formField = pFormField;
                final ItemInputStream itemStream = multi.newInputStream();
                InputStream istream = itemStream;
                if (fileSizeMax != -1) {
                    if (pContentLength != -1
                            &&  pContentLength > fileSizeMax) {
                        FileUploadException e =
                            new FileSizeLimitExceededException(
                                "The field " + fieldName
                                + " exceeds its maximum permitted "
                                + " size of " + fileSizeMax
                                + " characters.",
                                pContentLength, fileSizeMax);
                        throw new FileUploadIOException(e);
                    }
                    istream = new LimitedInputStream(istream, fileSizeMax) {
                        protected void raiseError(long pSizeMax, long pCount)
                                throws IOException {
                            itemStream.close(true);
                            FileUploadException e =
                                new FileSizeLimitExceededException(
                                    "The field " + fieldName
                                    + " exceeds its maximum permitted "
                                    + " size of " + pSizeMax
                                    + " characters.",
                                    pCount, pSizeMax);
                            throw new FileUploadIOException(e);
                        }
                    };
                }
                stream = istream;
            }

 

            /**創(chuàng)建FileItem,修訂后的代碼,解決丟失FileItemHeaders信息的bug
             * @param pName
             * @param pFieldName
             * @param pContentType
             * @param pFormField
             * @param pContentLength
             * @param headers
             * @throws IOException
             */
            FileItemStreamImpl(String pName, String pFieldName,
                    String pContentType, boolean pFormField,
                    long pContentLength,FileItemHeaders headers) throws IOException {
                name = pName;
                fieldName = pFieldName;
                contentType = pContentType;
                formField = pFormField;
                if(headers!=null){
                        this.headers = headers;
                }
                final ItemInputStream itemStream = multi.newInputStream();
                InputStream istream = itemStream;
                if (fileSizeMax != -1) {
                    if (pContentLength != -1
                            &&  pContentLength > fileSizeMax) {
                        FileUploadException e =
                            new FileSizeLimitExceededException(
                                "The field " + fieldName
                                + " exceeds its maximum permitted "
                                + " size of " + fileSizeMax
                                + " characters.",
                                pContentLength, fileSizeMax);
                        throw new FileUploadIOException(e);
                    }
                    istream = new LimitedInputStream(istream, fileSizeMax) {
                        protected void raiseError(long pSizeMax, long pCount)
                                throws IOException {
                            itemStream.close(true);
                            FileUploadException e =
                                new FileSizeLimitExceededException(
                                    "The field " + fieldName
                                    + " exceeds its maximum permitted "
                                    + " size of " + pSizeMax
                                    + " characters.",
                                    pCount, pSizeMax);
                            throw new FileUploadIOException(e);
                        }
                    };
                }
                stream = istream;
            }

相關(guān)文章

  • Spring中的@Scheduled定時(shí)任務(wù)注解詳解

    Spring中的@Scheduled定時(shí)任務(wù)注解詳解

    這篇文章主要介紹了Spring中的@Scheduled定時(shí)任務(wù)注解詳解,要使用@Scheduled注解,首先需要在啟動(dòng)類添加@EnableScheduling,啟用Spring的計(jì)劃任務(wù)執(zhí)行功能,這樣可以在容器中的任何Spring管理的bean上檢測(cè)@Scheduled注解,執(zhí)行計(jì)劃任務(wù),需要的朋友可以參考下
    2023-09-09
  • Java 深入淺出分析Synchronized原理與Callable接口

    Java 深入淺出分析Synchronized原理與Callable接口

    Synchronized關(guān)鍵字解決的是多個(gè)線程之間訪問(wèn)資源的同步性,synchronized關(guān)鍵字可以保證被它修飾的方法或者代碼塊在任意時(shí)刻只能有一個(gè)線程執(zhí)行,Runnable是執(zhí)行工作的獨(dú)立任務(wù),但是不返回任何值。如果我們希望任務(wù)完成之后有返回值,可以實(shí)現(xiàn)Callable接口
    2022-03-03
  • Spring多數(shù)據(jù)源切換失敗,發(fā)現(xiàn)與事務(wù)相關(guān)問(wèn)題

    Spring多數(shù)據(jù)源切換失敗,發(fā)現(xiàn)與事務(wù)相關(guān)問(wèn)題

    這篇文章主要介紹了Spring多數(shù)據(jù)源切換失敗,發(fā)現(xiàn)與事務(wù)相關(guān)問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-01-01
  • SpringBoot設(shè)置接口超時(shí)的方法小結(jié)

    SpringBoot設(shè)置接口超時(shí)的方法小結(jié)

    這篇文章主要介紹了SpringBoot設(shè)置接口超時(shí)的方法小結(jié),包括配置文件,config配置類及相關(guān)示例代碼,代碼簡(jiǎn)單易懂,對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-09-09
  • 認(rèn)識(shí)Java底層操作系統(tǒng)與并發(fā)基礎(chǔ)

    認(rèn)識(shí)Java底層操作系統(tǒng)與并發(fā)基礎(chǔ)

    這篇文章主要介紹了認(rèn)識(shí)Java底層操作系統(tǒng)與并發(fā)基礎(chǔ),文章圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的朋友可以參考一下
    2022-07-07
  • 怎樣給Kafka新增分區(qū)

    怎樣給Kafka新增分區(qū)

    這篇文章主要介紹了怎樣給Kafka新增分區(qū)問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-12-12
  • SpringMVC異常處理的三種方式

    SpringMVC異常處理的三種方式

    在SpringMVC中異常處理是一個(gè)重要的方面,它幫助我們有效地處理應(yīng)用程序中的異常情況,提高用戶體驗(yàn)和系統(tǒng)的穩(wěn)定性,這篇文章主要給大家介紹了關(guān)于SpringMVC異常處理的三種方式,需要的朋友可以參考下
    2024-02-02
  • MyBatis實(shí)現(xiàn)模糊查詢的幾種方式

    MyBatis實(shí)現(xiàn)模糊查詢的幾種方式

    這篇文章主要介紹了MyBatis實(shí)現(xiàn)模糊查詢的幾種方式,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-08-08
  • Springboot+redis+Interceptor+自定義annotation實(shí)現(xiàn)接口自動(dòng)冪等

    Springboot+redis+Interceptor+自定義annotation實(shí)現(xiàn)接口自動(dòng)冪等

    本篇文章給大家介紹了使用springboot和攔截器、redis來(lái)優(yōu)雅的實(shí)現(xiàn)接口冪等,對(duì)于冪等在實(shí)際的開(kāi)發(fā)過(guò)程中是十分重要的,因?yàn)橐粋€(gè)接口可能會(huì)被無(wú)數(shù)的客戶端調(diào)用,如何保證其不影響后臺(tái)的業(yè)務(wù)處理,如何保證其只影響數(shù)據(jù)一次是非常重要的,感興趣的朋友跟隨小編一起看看吧
    2019-07-07
  • IDEA2022版本創(chuàng)建maven?web項(xiàng)目的兩種方式詳解

    IDEA2022版本創(chuàng)建maven?web項(xiàng)目的兩種方式詳解

    創(chuàng)建maven?web項(xiàng)目有兩種方式,一種是使用骨架方式,一種是不使用骨架的方式,本文結(jié)合實(shí)例代碼給大家介紹了IDEA2022版本創(chuàng)建maven?web項(xiàng)目的兩種方式,需要的朋友可以參考下
    2023-02-02

最新評(píng)論

林州市| 海林市| 遂川县| 黄梅县| 桐乡市| 昆山市| 图木舒克市| 图们市| 天长市| 卓尼县| 漯河市| 长丰县| 彭山县| 江陵县| 灵丘县| 铁力市| 安陆市| 平顺县| 安多县| 宜阳县| 大连市| 太原市| 印江| 平乐县| 玉山县| 嘉兴市| 高碑店市| 浑源县| 赫章县| 南昌县| 五家渠市| 石屏县| 通榆县| 邛崃市| 浙江省| 长岭县| 德江县| 麻阳| 雷山县| 宁安市| 湛江市|