I need to create data structure, lets call it ByteCache, which containes some amount of bytes and it should support such methods:
1) ByteCache.length() - returns amount of bytes stored in it 2) ByteCache.add(Byte[] bytes) - adds new bytes to the end of presently contained inside 3) ByteCache.get(int offset, int length) - returns byte list from offset to offset+length bytes
It's supposed that there will be one thread writer (which adds bytes to cache) and another thread which reads some amounts of written bytes if there already present.
So what is the best way to do such things in java? May be there is such data structure, or some library ready to use, which I don't know, though I've read about some but didn't get a clue. I'm absolutely new to java, so please be patient.