java - Java 中最好的可调整大小的循环字节缓冲区是什么?

标签 java buffer byte

我需要一个 Java 中的字节缓冲区类以供单线程使用。我应该能够在缓冲区的后面插入数据并在前面读取数据,摊销成本为 O(1)。缓冲区满时应该调整大小,而不是抛出异常或其他东西。

我可以自己编写一个,但如果标准 Java 包中尚不存在此功能,我会感到非常惊讶,如果不存在,我希望它存在于一些经过良好测试的公共(public)库中.

你会推荐什么?

最佳答案

不确定它是否是“最好的”,但你有一个很好的例子 Circular Byte buffer here .

那些Java Utilities - OstermillerUtils类(class)在 GPL license 下.

This Circular Byte Buffer implements the circular buffer producer/consumer model for bytes. Filling and emptying the buffer is done with standard Java InputStreams and OutputStreams.

Using this class is a simpler alternative to using a PipedInputStream and a PipedOutputStream.
PipedInputStreams and PipedOutputStreams don't support the mark operation, don't allow you to control buffer sizes that they use, and have a more complicated API that requires a instantiating two classes and connecting them.

关于java - Java 中最好的可调整大小的循环字节缓冲区是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/325602/

相关文章:

java - Java 中的无符号字节

JavaScript:读取 8 字节到 64 位整数

java - 当输入为 "???"时,StringUtils isNumeric 返回 true,为什么?

Java 类无法正确交互

javascript - R 部分不工作

linux - 在 Fortran 程序意外结束时刷新文件

java - 如何 `read byte`在Objective-C和Java之间读取对象?

java - 资源/目录树

javascript - 使用 express js 在浏览器中显示 Pdf

c - 使用 Write() 和 snprintf() 以原子方式写入文件