/** * Creates a new <code>BOMReader</code>. A {@link BOMInputStream} is created on top of the specified * <code>InputStream</code> to auto-detect a potential {@link BOM} and use the associated encoding. * If no BOM is found at the beginning of the stream, <code>UTF-8</code> encoding is assumed. * * @param in the underlying InputStream * @throws IOException if an error occurred while detecting the BOM or initializing this reader. */ public BOMReader(InputStream in) throws IOException { this(new BOMInputStream(in), "UTF-8"); }
/** * Creates a new <code>BOMReader</code>. A {@link BOMInputStream} is created on top of the specified * <code>InputStream</code> to auto-detect a potential {@link BOM} and use the associated encoding. * If no BOM is found at the beginning of the stream, the specified default encoding is assumed. * * @param in the underlying InputStream * @param defaultEncoding the encoding used if the stream doesn't contain a BOM * @throws IOException if an error occurred while detecting the BOM or initializing this reader. */ public BOMReader(InputStream in, String defaultEncoding) throws IOException { this(new BOMInputStream(in), defaultEncoding); }
void loadDocument(InputStream in, final String encoding, DocumentListener documentListener) throws IOException { // If the encoding is UTF-something, wrap the stream in a BOMInputStream to filter out the byte-order mark // (see ticket #245) if(encoding != null && encoding.toLowerCase().startsWith("utf")) { in = new BOMInputStream(in); } // If the given encoding is invalid (null or not supported), default to "UTF-8" this.encoding = encoding==null || !Charset.isSupported(encoding) ? "UTF-8" : encoding; textEditorImpl.read(new BufferedReader(new InputStreamReader(in, this.encoding))); // Listen to document changes if(documentListener!=null) textEditorImpl.addDocumentListener(documentListener); }
private BOMInputStream getBOMInputStream(byte b[]) throws IOException { return new BOMInputStream(new ByteArrayInputStream(b)); }
BOMInputStream bin = new BOMInputStream(new ByteArrayInputStream(b, off, len)); BOM bom = bin.getBOM();