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 8428475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:04:07+00:00 2026-06-10T05:04:07+00:00

I am currently using the Java ByteBuffer ByteBuffer batch = ByteBuffer.allocate(tuple_size * batch_size )

  • 0

I am currently using the Java ByteBuffer

    ByteBuffer batch = ByteBuffer.allocate(tuple_size * batch_size ) ;
    int pos = 0;
    int sent = 0;
    while ( sent++ < batch_size) {
            Event event = (Event) it.next();
            batch.put(event.getData(), pos, tuple_size);
            pos += tuple_size;

        }
    return batch.array();

Currently, batch_size is set to 2. My issue is that on the second round, I get an IndexOutofBoundsException which I cannot explain given that, printing out the follwoing details:

       System.out.println(pos + " " +  batch.capacity() +  " " + batch.position() + " " +  batch.remaining()); 

I get:
0 200 0 200 (round 0)

100 200 100 100 (round 1)

which is what one would expect. Now, based on the documentation, it seems that the bound checks do hold:

 offset - The offset within the array of the first byte to be read; must be non-negative and no larger than array.length
 length - The number of bytes to be read from the given array; must be non-negative and no larger than array.length - offset

How do I completely fill up the buffer? (whilst keeping the underlying buffer to have length tuple_size * batch_size?)

  • 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-06-10T05:04:08+00:00Added an answer on June 10, 2026 at 5:04 am

    I think you don’t need the pos variable. The put method is trying to read into event.getData() at position pos, while I think you want to read event.getData() from position 0. You can simply use batch.put(event.getData()) to append the whole content of the array into the buffer.

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

Sidebar

Related Questions

I am currently using Java ME to extract Addressbook (ContactList) fields in a device
I am currently using Ubuntu 11.10 and java SE 1.6.0_26. I am trying to
I'm currently using the ImageJ jar (ij.jar) in a Java application that I am
I am currently looking in to some file uploading using Java Server Faces. I've
we are currently working on a new web application using Java and MySql. We
I am working on an IMAP client using java mail. We currently have a
I am using the URLUTF8Encoder.java class from W3C ( www.w3.org/International/URLUTF8Encoder.java ). Currently, it will
I'm new to Eclipse and am using it currently to play with Java EE.
I'm currently implementing a .NET wrapper for a Java library by using JNI to
I am currently building an application using Tomcat, Spring and JAVA. I am using

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.