Dedian |
|
|||
-- 關注搜索引擎的開發 |
日歷
統計
導航常用鏈接留言簿(8)隨筆分類(45)
隨筆檔案(82)
文章檔案(2)Java Spaces搜索積分與排名
最新評論
閱讀排行榜評論排行榜 |
-- Scenario:
??? The purpose of a reader is to interpret a low-level byte stream (ByteArrayInputStream, StringInputStream, FileInputStream and so on) as a character stream and provid character input to whatever class needs it. And it is very simple to convert an inputstream to a reader: Reader reader = new InputStreamReader( in ); //in is an instance of class InputStream or derived classesBut the issue is sometimes we need convert a reader to inputstream, think about following scenaros: 1.? the original inputstream has been filtered by certian reader, now we need save back filtered content into database by inputstream: we can not use original inputstream but filtered stream which can only get from your reader. 2.? Given a class who contains a reader to access a streaming content after complex parsering or downloading, we want to utilize the streaming content in this class while not repeating complex operations for content analysis, so we need employ some wrapper methods to get inputstream from reader. -- Solution: 1. write own InputStream implementation, such as following: class MyInputStream extends InputStreamNote: Applications that need to define a subclass of InputStream
must always provide a method that returns the next byte of input. (refer to http://java.sun.com/j2se/1.4.2/docs/api/java/io/InputStream.html) -- anything else? BTW, for parsering xml-based input stream by SAX, I am glad to see that the inputSource constructor can take either InputStream or Reader (refer to http://java.sun.com/j2se/1.4.2/docs/api/org/xml/sax/InputSource.html)
|
![]() |
|
Copyright © Dedian | Powered by: 博客園 模板提供:滬江博客 |