Most Robust way of reading a file or stream using Java (to prevent DoS attacks)

后端 未结 7 464
长情又很酷
长情又很酷 2020-12-04 13:51

Currently I have the below code for reading an InputStream. I am storing the whole file into a StringBuilder variable and processing this string af

7条回答
  •  一个人的身影
    2020-12-04 14:16

    This worked for me without any problems.

        char charArray[] = new char[ MAX_BUFFER_SIZE ];
        int i = 0;
        int c = 0;
        while((c = br.read()) != -1 && i < MAX_BUFFER_SIZE) {
            char character = (char) c;
            charArray[i++] = character;
       }
       return Arrays.copyOfRange(charArray,0,i); 
    

提交回复
热议问题