Skip to content

Commit

Permalink
Simplify code
Browse files Browse the repository at this point in the history
No need to wrap BufferedInputStream in another BufferedInputStream

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1795308 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
markt-asf committed May 16, 2017
1 parent 8942a1e commit 9a28f8a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
11 changes: 2 additions & 9 deletions java/org/apache/jasper/compiler/EncodingDetector.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,8 @@ class EncodingDetector {
private final boolean encodingSpecifiedInProlog;


/*
* TODO: Refactor Jasper InputStream creation and handling so the
* InputStream passed to this method is buffered and therefore saves
* on multiple opening and re-opening of the same file.
*/
EncodingDetector(InputStream is) throws IOException {
// Keep buffer size to a minimum here. BoM will be no more than 4 bytes
// so that is the maximum we need to buffer
BufferedInputStream bis = new BufferedInputStream(is, 4);
EncodingDetector(BufferedInputStream bis) throws IOException {
// Buffer is 1k. BOM is only 4 bytes.
bis.mark(4);

BomResult bomResult = processBom(bis);
Expand Down
6 changes: 3 additions & 3 deletions java/org/apache/jasper/compiler/ParserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
*/
package org.apache.jasper.compiler;

import java.io.BufferedInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Stack;

Expand Down Expand Up @@ -318,8 +318,8 @@ private void determineSyntaxAndEncoding(String absFileName, Jar jar,
sourceEnc = "ISO-8859-1";
} else {
// XML syntax or unknown, (auto)detect encoding ...
InputStream inStream = JspUtil.getInputStream(absFileName, jar, ctxt);
EncodingDetector encodingDetector = new EncodingDetector(inStream);
BufferedInputStream bis = JspUtil.getInputStream(absFileName, jar, ctxt);
EncodingDetector encodingDetector = new EncodingDetector(bis);

sourceEnc = encodingDetector.getEncoding();
isEncodingSpecifiedInProlog = encodingDetector.isEncodingSpecifiedInProlog();
Expand Down

0 comments on commit 9a28f8a

Please sign in to comment.