utf8inputstreamconverter.java
来自「开源的axion的数据库代码」· Java 代码 · 共 55 行
JAVA
55 行
/* * Created on May 27, 2003 * */package org.axiondb.util;import java.io.IOException;import java.io.InputStream;import java.io.UnsupportedEncodingException;/** * @author mdelagrange * */public class Utf8InputStreamConverter extends InputStream { // this class will require modification // if we need non-ascii conversions private String _targetEncoding = null; private InputStream _utf8Stream = null; /** * Currently only supports "US-ASCII" * * @param targetEncoding "US-ASCII" * @throws UnsupportedEncodingException */ public Utf8InputStreamConverter(InputStream utf8Stream, String targetEncoding) throws UnsupportedEncodingException { if (targetEncoding.equals("US-ASCII") == false) { throw new UnsupportedEncodingException(targetEncoding); } _targetEncoding = targetEncoding; _utf8Stream = utf8Stream; } /** * Returns a byte encoded as ASCII. If non-ASCII characters are encountered in the * underlying UTF-8 stream, an IOException is thrown. * * @see java.io.InputStream#read() */ public int read() throws IOException { int theByte = _utf8Stream.read(); if (theByte > 127) { throw new IOException("Could not convert stream from UTF-8 to " + _targetEncoding); } return theByte; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?