将BufferedReader转换为InputStream [英] Convert BufferedReader to InputStream

查看:2047
本文介绍了将BufferedReader转换为InputStream的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个API,它有一个需要InputStream参数的有用方法。我想要提供给此方法的数据当前由BufferedReader表示。该库准备处理字节流,我有字符数据,我将提供它。

I have an API with a useful method that requires an InputStream argument. The data that I want to provide to this method is currently represented by a BufferedReader. The library is prepared to deal with byte streams, I have character data that I'm going to feed it.

我不会在不同的编码之间进行更改。

I am not changing between different encodings.

我花了大量时间试图发现我确信这是一种标准的方法来做到这一点,但似乎没有。我不想将所有数据都读入内存,因此输出了一个字节数组输入流。

I have spent what seems an inordinate amount of time trying to discover what I was sure would be a standard way to do this, but there doesn't seem to be one. I do NOT want to read all my data into memory, so a byte array input stream is out.

我想我自己也可以写一个 - 对输入流的读取会调用readLine(或只是读取缓冲区)来获取一些字节然后返回一个编码来自它的字节数组。但我必须这样做吗?是不是其他人已经完成了所有的计算和错误检查以及所有那些难以在第一时间获得正确的废话?

I suppose I can write one myself -- the read to my input stream would call readLine (or just read of a buffer) to get some bytes and then return an encoded array of bytes from it. But do I have to? Hasn't someone else already done all the calculations and error checking and all of that nonsense that is hard to get right the first time?

推荐答案

判断您的标题 ReaderInputStream appache commons-io 可能会让您感兴趣。

Judging by your title ReaderInputStream from appache commons-io may interest you.

这篇关于将BufferedReader转换为InputStream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆