Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 607651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:22:57+00:00 2026-05-13T17:22:57+00:00

I’m thinking about using as a base some FIFO (for example, BoundedFifoBuffer from Apache

  • 0

I’m thinking about using as a base some FIFO (for example, BoundedFifoBuffer from Apache Commons) to organize IO tasks in my application (I was looking for something easy to use as a temporary buffer for reading from a stream and FIFO simultaneously: so I will read data from an InputStream to it and then consume the data later; in my case consuming code will eat data mostly in fixed-size chunks but I can’t guarantee that I will get those data in the same sized chunks from a stream – so to adapt this parts I want to use a FIFO that is also easily usable to InputStream.read() in its internal array to lower amount of data copying).

But I stumbled on the generic implementation of the FIFO collection. To me it looks like Java generics are just a facade that hides Object references. What about having a generic collection class (that has T[] array as its data container) with a primitive type parameter? Is it possible or do I have to use a wrapper type instead?

The most interesting question for me: is it a good idea to use generic collection like BoundedFifoBuffer, use it with byte generic type parameter and then try to use its array for reading data from a Stream: InputStream.read(byte[] b, int off, int len)? In case if generic collection here means a bunch of references to boxed bytes I doubt I want it this way… Any better suggestion than creating a special collection bound to byte type then?

PS: I was using Java 2 but then switched to C# 2 more than 4 years ago. Now I want to get my Java knowledge up-to-date. So I may get things really wrong at least around Java generics 🙂

UPDATE:

I still like Apache Commons *FifoBuffer classes. I’m considering to rewrite one of them to use the primitive byte type instead of generic type parameter and then add some logic to use its array for reading from an InputStream.

GNU Trove shows an interesting approach with simple code generation for primitive type friendly collections but it lacks FIFO out of the box. As a very general solution would be fun to get some FifoBuffer and make a template for GNU Trove from it. Additional logic most likely will fit into two additional methods E[] getBufferArray() and int getBufferLength() (to know how to invoke InputStream.read() on its array directly). For my purpose I will skip Trove step for simplicity 🙂 I checked Mahout 0.2 and so far didn’t find any FIFO collections too. The example provided by McDowell (based on ByteArrayStream) and java.nio buffers are very close to what I want. But ByteArray*Stream can be only reset to 0, you can’t conveniently get some of its data off (not all buffer’s data) and I wanted to remove only those parts I’m sure are ready to be processed and discarded (e.g. full packet or garbage before next valid packet in incoming data). java.nio.ByteBuffer has no way to discard already read data AFAIK.

To summarize: for now circular FIFO looks like the best option and I may get one from Apache Commons sources to adapt for my needs (primitive byte type + making it suitable for read() calls).

Any comments on the update?..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T17:22:57+00:00Added an answer on May 13, 2026 at 5:22 pm

    To begin with, you can’t say BoundedFifoBuffer<byte>. The compiler won’t permit it.

    If you use the raw type, you get autoboxing, in which byte silently promotes itself to Byte, and you don’t want that, either.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 365k
  • Answers 365k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can use the data in the /proc filesystem to… May 14, 2026 at 3:57 pm
  • Editorial Team
    Editorial Team added an answer Do you still get the error when you use a… May 14, 2026 at 3:57 pm
  • Editorial Team
    Editorial Team added an answer You can use array_chunk to create a single array comprised… May 14, 2026 at 3:57 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.