<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    ivaneeo's blog

    自由的力量,自由的生活。

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      669 Posts :: 0 Stories :: 64 Comments :: 0 Trackbacks
    public class ReaderInputStream extends InputStream {
        protected Reader reader;
        protected ByteArrayOutputStream byteArrayOut;
        protected Writer writer;
        protected char[] chars;
        protected byte[] buffer;
        protected int index, length;

          /**
           * 帶Reader參數構造函數
           *
           * @param reader - InputStream使用的Reader
           */
          public ReaderInputStream(Reader reader) {
            this.reader = reader;
            byteArrayOut = new ByteArrayOutputStream();
            writer = new OutputStreamWriter(byteArrayOut);
            chars = new char[1024];
          }

          /**
           * 帶Reader和字符編碼格式參數的構造函數
           *
           * @param reader   - InputStream使用的Reader
           * @param encoding - InputStream使用的字符編碼格式.
           * @throws 如果字符編碼格式不支持,則拋UnsupportedEncodingException異常
           */
          public ReaderInputStream(Reader reader, String encoding)
              throws UnsupportedEncodingException {
            this.reader = reader;
            byteArrayOut = new ByteArrayOutputStream();
            writer = new OutputStreamWriter(byteArrayOut, encoding);
            chars = new char[1024];
          }

          /**
           * @see java.io.InputStream#read()
           */
          public int read() throws IOException {
            if (index >= length)
              fillBuffer();
            if (index >= length)
              return -1;
            return 0xff & buffer[index++];
          }

          protected void fillBuffer() throws IOException {
            if (length < 0)
              return;
            int numChars = reader.read(chars);
            if (numChars < 0) {
              length = -1;
            } else {
              byteArrayOut.reset();
              writer.write(chars, 0, numChars);
              writer.flush();
              buffer = byteArrayOut.toByteArray();
              length = buffer.length;
              index = 0;
            }
          }

          /**
           * @see java.io.InputStream#read(byte[], int, int)
           */
          public int read(byte[] data, int off, int len) throws IOException {
            if (index >= length)
              fillBuffer();
            if (index >= length)
              return -1;
            int amount = Math.min(len, length - index);
            System.arraycopy(buffer, index, data, off, amount);
            index += amount;
            return amount;
          }

          /**
           * @see java.io.InputStream#available()
           */
          public int available() throws IOException {
            return (index < length) ? length - index :
                ((length >= 0) && reader.ready()) ? 1 : 0;
          }

          /**
           * @see java.io.InputStream#close()
           */
          public void close() throws IOException {
            reader.close();
          }

    }
    posted on 2005-08-11 09:27 ivaneeo 閱讀(2318) 評論(0)  編輯  收藏 所屬分類: java魔力
    主站蜘蛛池模板: 国产美女在线精品免费观看| 一区二区三区视频免费观看| 精品国产免费人成电影在线观看 | 亚洲AV无码一区二区乱子伦 | 久视频精品免费观看99| 亚洲大成色www永久网站| 高清永久免费观看| 亚洲免费观看视频| 花蝴蝶免费视频在线观看高清版| 国产国拍精品亚洲AV片| 亚洲а∨天堂久久精品| 日韩亚洲综合精品国产| 亚洲人成网站观看在线播放| 人人爽人人爽人人片av免费| 国产国拍精品亚洲AV片| 99精品视频在线视频免费观看| 久久综合亚洲色HEZYO社区| 一个人看的www免费在线视频| 亚洲人成在线播放网站| 四虎影视成人永久免费观看视频| 亚洲一本综合久久| 在线视频观看免费视频18| 亚洲国产欧美国产综合一区| 亚洲AV无码不卡在线观看下载| sss在线观看免费高清| 亚洲AV无一区二区三区久久| 无人在线直播免费观看| 国产AV无码专区亚洲AV蜜芽 | 色婷婷六月亚洲婷婷丁香| 成人免费观看一区二区| 亚洲AV无码专区在线厂| 综合亚洲伊人午夜网| 91久久成人免费| 看全免费的一级毛片| 日本亚洲欧洲免费天堂午夜看片女人员 | 国产日韩一区二区三免费高清| 亚洲精品午夜在线观看| 国产午夜免费福利红片| 国产午夜精品免费一区二区三区 | 高清免费久久午夜精品| 亚洲国产高清视频|