Skip to content

Commit 5a21350

Browse files
author
Niall Pemberton
committed
IO-162 and IO-178 Minor refactoring to simplify
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/io/trunk@1004123 13f79535-47bb-0310-9956-ffa450edef68
1 parent 1056d5d commit 5a21350

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/java/org/apache/commons/io/input/BOMInputStream.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,18 @@ public ByteOrderMark getBOM() throws IOException {
181181
return byteOrderMark;
182182
}
183183

184+
/**
185+
* Return the BOM charset Name - {@link ByteOrderMark#getCharsetName()}.
186+
*
187+
* @return The BOM charset Name or null if no BOM found
188+
* @throws IOException if an error reading the first bytes of the stream occurs
189+
*
190+
*/
191+
public String getBOMCharsetName() throws IOException {
192+
getBOM();
193+
return (byteOrderMark == null ? null : byteOrderMark.getCharsetName());
194+
}
195+
184196
/**
185197
* This method reads and either preserves or skips the first bytes in the
186198
* stream. It behaves like the single-byte <code>read()</code> method,

src/java/org/apache/commons/io/input/XmlStreamReader.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,8 @@ private void doRawStream(InputStream is, boolean lenient)
447447
throws IOException {
448448
BOMInputStream bom = new BOMInputStream(new BufferedInputStream(is, BUFFER_SIZE), false, BOMS);
449449
BOMInputStream pis = new BOMInputStream(bom, true, XML_GUESS_BYTES);
450-
String bomEnc = (bom.hasBOM() ? bom.getBOM().getCharsetName() : null);
451-
String xmlGuessEnc = (pis.hasBOM() ? pis.getBOM().getCharsetName() : null);
450+
String bomEnc = bom.getBOMCharsetName();
451+
String xmlGuessEnc = pis.getBOMCharsetName();
452452
String xmlEnc = getXmlProlog(pis, xmlGuessEnc);
453453
this.encoding = calculateRawEncoding(bomEnc, xmlGuessEnc, xmlEnc, pis);
454454
this.reader = new InputStreamReader(is, encoding);
@@ -469,8 +469,8 @@ private void doHttpStream(InputStream is, String httpContentType,
469469
BOMInputStream pis = new BOMInputStream(bom, true, XML_GUESS_BYTES);
470470
String cTMime = getContentTypeMime(httpContentType);
471471
String cTEnc = getContentTypeEncoding(httpContentType);
472-
String bomEnc = (bom.hasBOM() ? bom.getBOM().getCharsetName() : null);
473-
String xmlGuessEnc = (pis.hasBOM() ? pis.getBOM().getCharsetName() : null);
472+
String bomEnc = bom.getBOMCharsetName();
473+
String xmlGuessEnc = pis.getBOMCharsetName();
474474
String xmlEnc = getXmlProlog(pis, xmlGuessEnc);
475475
this.encoding = calculateHttpEncoding(cTMime, cTEnc, bomEnc,
476476
xmlGuessEnc, xmlEnc, pis, lenient);

0 commit comments

Comments
 (0)