- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在从 MimeMessage 获取输入流。在InputStream中,最后我想添加\r\n。\r\n
代表消息的结束。
请提出建议。
最佳答案
您可以使用以下命令动态附加它
public class ConcatInputStream extends InputStream {
private final InputStream[] is;
private int last = 0;
ConcatInputStream(InputStream[] is) {
this.is = is;
}
public static InputStream of(InputStream... is) {
return new ConcatInputStream(is);
}
@Override
public int read(byte[] b, int off, int len) throws IOException {
for (; last < is.length; last++) {
int read = is[last].read(b, off, len);
if (read >= 0)
return read;
}
throw new EOFException();
}
@Override
public int read() throws IOException {
for (; last < is.length; last++) {
int read = is[last].read();
if (read >= 0)
return read;
}
throw new EOFException();
}
@Override
public int available() throws IOException {
long available = 0;
for(int i = last; i < is.length; i++)
available += is[i].available();
return (int) Math.min(Integer.MAX_VALUE, available);
}
}
根据你的情况,你可以这样做
InputStream in =
InputStream in2 = ConcatInputStream.of(in,
new ByteArrayInputStream("\r\n.\r\n".getBytes()));
关于java - 将字符添加到 BufferedInputStream java 的末尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28042544/
1. 概述 在这个例子中,我们将使用一个BufferedInputStream类来读取一个文件。BufferedInputStream类是用来从流中读取信息的。它在内部使用了一个缓冲机制来使性能快速提
如果文件大小 > 8k,为什么读取的最后一个字节 = 0? private static final int GAP_SIZE = 8 * 1024; public static void main(
使用缓冲输入流读取批量文件时,如何确定缓冲区的大小?它基于文件大小吗?我正在使用, byte[] buf = new byte[4096]; 如果我增加缓冲区大小,它会读取得很快吗? 最佳答案 默认值
我正在尝试用java编写服务器端和客户端。因此,客户端发送请求,如 GET/HTTP/1.0,服务器端响应(如果文件存在),如 HTTP/1.0 200 OK,放入 header 内容类型和内容长度,
我的文件写入过程如下(我称之为非集群模式) Write an object to the current position of the file. Note the position of writ
我的 BufferedInputStream 没有正确标记。这是我的代码: public static void main(String[] args) throws Exception {
对于我的 jvm,BufferedinputStream 默认缓冲区大小是 8k。这是硬编码值,还是可以通过更改某些系统参数来更改? 我希望它在不修改 java 代码的情况下使用 128k。这可能吗?
我正在使用 BufferedInputStream 从套接字中读取数据。 BufferedInputStream 内容如下: socketInput.read(replyBuffer, 0, 7);
我知道将 BufferedInpurStream 包装在 FileInputStream 周围可以使读取操作更快但尝试 弄清楚如何。我查看了 BufferedInpurStream 的源代码并得到了一
让我在这篇文章的开头谨慎一点。当谈到 Java 时,我是一个完全的初学者。我一直在断断续续地编写 PHP,但我已经准备好做一个桌面应用程序,所以出于各种原因我决定使用 Java。 我正在处理的应用程序
这个问题在这里已经有了答案: 关闭11年前。 Possible Duplicate: In Java how do a read/convert an InputStream in to a stri
BufferedInputStream 介绍 BufferedInputStream 是缓冲输入流。它继承于FilterInputStream。 BufferedInputStream 的作用是为
是 available()在 Java 中的套接字编程中使用可靠吗? 我只关心它告诉我什么时候有可用的字节读取,这样当我调用读取方法时它们不会阻塞。 BufferedInputStream.avail
这是我的代码。 while ((count = in.read(data, 0, 16384)) != -1) // while there is still data from link to be
我通过 javax.sound.sampled.AudioSystem.getAudioInputStream() 从 URLConnection 获取 AudioInputStream。当将 URL
我需要使 java BufferedInputStream 可序列化。是否有任何替代方案或任何其他方式来实现它? 您是否发现此实现中存在任何问题 import java.io.BufferedInpu
我有 Java SSL/TLS 服务器和客户端套接字。我的客户端只需将文件发送到服务器,服务器就会接收它。这是我的代码: 我的客户端方法: static boolean writeData(Buffe
我正在从 Oracle 数据库读取 BLOB 列,然后将其写入文件,如下所示: public static int execute(String filename, BLOB blob)
有人可以向我解释为什么这在 in.available()>0 注释掉的情况下工作得很好,但是当我把它放回去时它就崩溃了? mySocket = new Socket("blahblah", 12345
有一个常见的模式,当应用程序的每一层处理来自流的数据时,倾向于将其包装到 BufferedInputStream 中,因此总的来说,有很多缓冲区,从缓冲区填充,从缓冲区填充等等。 我认为这是不好的做法
我是一名优秀的程序员,十分优秀!