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

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

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

/**解析文件列表
         * 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) {
                             //這里代碼要修訂
                        //這是原來的代碼,沒有傳入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;
            }

相關文章

  • Spring中的@Scheduled定時任務注解詳解

    Spring中的@Scheduled定時任務注解詳解

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

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

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

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

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

    SpringBoot設置接口超時的方法小結

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

    認識Java底層操作系統(tǒng)與并發(fā)基礎

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

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

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

    SpringMVC異常處理的三種方式

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

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

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

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

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

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

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

最新評論

石台县| 庄河市| 彰化县| 广安市| 股票| 上杭县| 蒙自县| 瑞丽市| 马龙县| 聂拉木县| 绍兴市| 闵行区| 康定县| 金川县| 新闻| 宜良县| 兰溪市| 奈曼旗| 巴中市| 磴口县| 韶山市| 普陀区| 新津县| 江阴市| 新泰市| 策勒县| 兴城市| 都匀市| 邵东县| 剑河县| 沁源县| 大丰市| 政和县| 九江县| 威远县| 易门县| 潮州市| 乐清市| 吉安县| 武平县| 波密县|