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

  • Home
  • SEARCH
  • 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 8986005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:26:57+00:00 2026-06-15T21:26:57+00:00

I am reading a data in byte-by-byte. when i have determined that i have

  • 0

I am reading a data in byte-by-byte. when i have determined that i have an entire message, i need to pass it to another function as a string. Some messages can be quite large, but the sizes vary frequently. Which implementation do you all feel is most effecient:

public test class
{
   char[] buffer = new char[MAX_SIZE_7200];
   int bufferIndex = 0;
   void parseData(ArrayList<Byte> msg, length)
   {
       while (!msg.isEmpty())
       {
          buffer[bufferIndex++] = (char) msg.remove(0);
          if (isfullmessage)
          {
             parseData(new String(buffer, 0, bufferIndex);
             bufferIndex = 0;  //restart and continue parsing data
          }
       }
   }
 }

OR:

public test class
{
   List<Character> buffer = new ArrayList<Character>();
   int bufferIndex = 0;
   void parseData(ArrayList<Byte> msg, length)
   {
       while (!msg.isEmpty())
       {
          buffer.add((char) msg.remove(0));
          if (isfullmessage)
          {
              StringBuilder builder = new StringBuilder(buffer.size());
              for (Character ch: buffer)
              {
                  builder.append(ch);
              }
              parseData(builder.toString());
              buffer.clear();
          }
       }
   }
 }  

OR:

public test class
    {
       StringBuilder buffer = new StringBuilder();
       int bufferIndex = 0;
       void parseData(ArrayList<Byte> msg, length)
       {
           while (!msg.isEmpty())
           {
              buffer.append((char) msg.remove(0));
              if (isfullmessage)
              {                  
                  parseData(builder.toString());
                  buffer.clear();  //some stringbuilder clear function
              }
           }
       }
     }  

or is there a more efficient way. Please note that i have the variables holding my finished message outside the scope of the function since i might process data that does not contain a full message and may take multiple executions of the function to get a full message and process it.

  • 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-15T21:26:58+00:00Added an answer on June 15, 2026 at 9:26 pm

    Use StringBuilder. It supports appending characters one at a time, expands capacity as needed, and can be reset for reuse purposes.

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

Sidebar

Related Questions

I have a Java class, where I'm reading data in via an InputStream byte[]
I have a BluetoothSocket that I am reading data from, using a separate Thread
I have an application that reads string data in from a stream. The string
I have a thread reading data from a bluetooth stream that sends the data
I have some code from the net reading hyperspectral data (image, so lots of
I have a byte array that I am reading in from a NetworkStream. The
I am reading data from an Excel worksheet. Some of the data is percent
I am reading data from a file that has, unfortunately, two types of character
I want to use the pack() function in Perl to encode some data. Then
I have to send the audio data in byte array obtain by recording from

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.