1 /* 2 ****************************************************************************** 3 * Copyright (C) 2004, International Business Machines Corporation and * 4 * others. All Rights Reserved. * 5 ****************************************************************************** 6 */ 7 8 package org.unicode.cldr.util; 9 10 import java.io.IOException; 11 import java.io.InputStream; 12 13 class StripUTF8BOMInputStream extends InputStream { 14 InputStream base; 15 16 StripUTF8BOMInputStream(InputStream base) { 17 this.base = base; 18 } 19 20 boolean checkForUTF8BOM = true; 21 22 /* 23 * (non-Javadoc) 24 * 25 * @see java.io.InputStream#read() 26 */ 27 public int read() throws IOException { 28 int result = base.read(); 29 if (!checkForUTF8BOM) return result; 30 // complicated by still wanting to do one delegate read per read 31 // so we just skip first char if it starts with EF, assuming valid UTF-8 32 checkForUTF8BOM = false; 33 if (result != 0xEF) return result; 34 result = base.read(); 35 result = base.read(); 36 result = base.read(); 37 return result; 38 } 39 40 }