Java中最好的可调整大小的循环字节缓冲区是什么? [英] What is the best resizable circular byte buffer available in Java?

查看:92
本文介绍了Java中最好的可调整大小的循环字节缓冲区是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need a byte buffer class in Java for single-threaded use. I should be able to insert data at the back of the buffer and read data at the front, with an amortized cost of O(1). The buffer should resize when it's full, rather than throw an exception or something.

我可以自己写一个,但是如果不存在,我会感到非常惊讶

I could write one myself, but I'd be very surprised if this didn't exist yet in a standard Java package, and if it doesn't, I'd expect it to exist in some well-tested public library.

您会推荐什么?

在标准Java程序包中,如果没有,我希望它存在于一些经过良好测试的公共库中。 / p>

What would you recommend?

推荐答案

不确定它是否是最好的,但是您有一个很好的例子,此处的循环字节缓冲区

Not sure if it is "the best", but you have a nice example of Circular Byte buffer here.

那些 Java实用程序-OstermillerUtils 类在 GPL许可下


此循环字节缓冲区实现了字节的循环缓冲区生产者/消费者模型。使用标准的Java InputStreams和OutputStreams填充和清空缓冲区。

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.

使用此类是使用PipedInputStream和PipedOutputStream的一种更简单的选择。

PipedInputStreams和PipedOutputStreams不支持标记操作,不允许您控制它们使用的缓冲区大小,并且具有更复杂的API,该API需要实例化两个类并将它们连接。

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中最好的可调整大小的循环字节缓冲区是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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