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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:05:15+00:00 2026-05-28T03:05:15+00:00

I have a class, as such: private class verifierListener implements SerialPortEventListener { String outBuffer;

  • 0

I have a class, as such:

 private class verifierListener implements SerialPortEventListener {

    String outBuffer;
    char charBuffer;

    public void serialEvent(SerialPortEvent event) {
        if (event.isRXCHAR()) {//If data is available
            timeOut = 1000;
            lastReadTimer = System.currentTimeMillis();
            if (event.getEventValue() > 0) {//Check bytes count in the input buffer

                try {
                     byte[] buffer = verifierPort.readBytes(event.getEventValue());
                     //INSERT CODE HERE
                } catch (Exception ex) {
                    ex.printStackTrace();
                }

            }
        }

With two possible methods of implementation(in the INSERT CODE HERE area)

Case A:

                        outBuffer = new String(buffer);


                        bfrFile.print(outBuffer);
                        sysOutWriter.append(outBuffer);

Case B:

                            for(byte bt : buffer) {
                                charBuffer = (char) bt;
                                bfrFile.print(charBuffer);
                                sysOutWriter.append(charBuffer);
                            }

Both compile and run, and do what they are supposed to do. But I’m trying to make this code perform as seamlessly as possible, so I don’t possibly risk a loss of transmitted data on a lower end PC.

I’m assuming that case A will have more overhead due to the String initialization, but I wanted to make certain before I remove it.

Can y’all tell which one would be cleaner, and/or how to determine the processing cost for each?

  • 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-28T03:05:16+00:00Added an answer on May 28, 2026 at 3:05 am

    You shouldn’t be loosing any data, even on a lower-end PC. That’s because there are (several) buffers in between your code and the actual data that’s coming over the serial port(operating system buffers, Java buffers, etc..). Speed-wise, unless you’re running this code a lot(as in, several thousand times per second) you shouldn’t notice a difference.

    Assuming this is a standard serial connection, and you were running at 115200 bits per second, that means that you’re getting at most 14,400 characters per second. Even if you were to read those one character at a time, you shouldn’t see a big speed hit.

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

Sidebar

Related Questions

Often I have a class as such: public class Foo { private String field1;
I have such class public unsafe class EigenSolver { public double* aPtr {get; private
(Java Spring WebApp) I have: public class PersonValidator implements Validator { private PersonDAO d;
If I have a method such as: private function testMethod(param:string):void { // Get the
I have a class along the lines of: public class Observation { private String
I have this class: private static class ClassA{ int id; String name; public ClassA(int
In AS3, if I have a class such: public class dude { //default value
If I have a base class such that public abstract class XMLSubscription <T extends
If I have a simple class such as:- @XmlRootElement public class MyClass { @XmlAttribute(required=true)
I have such a class: public class Cycle { public List<int> Edges { get;

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.