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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:21:20+00:00 2026-05-31T23:21:20+00:00

Ok guys, could you tell me is there a certain bug in current code:

  • 0

Ok guys, could you tell me is there a certain bug in current code:

//this all only for example so DO NOT use this terrible code
1   private void readIncomingData(SocketChannel channel){

2    try{                                     //10 - for simplicity sake
4      ByteBuffer buffer = ByteBuffer.allocate( 10 );
5      buffer.clear();

6      channel.read( buffer );

8      StringBuilder response = new StringBuilder();

9      buffer.flip();

10     Charset charset = Charset.forName(“UTF-8″);

12     //HERE IS THE DILEMMA !!!   
13     response.append( charset.decode( buffer ) );

14     // Output the response
15     System.out.println( “Data read from client ” + response );

16   } catch (IOException e) {
17     e.printStackTrace();
18  }

19}

For example the incoming text is UTF-8 coded and consist of 9 – symbols are in range of ANCII(U+007F)
codes and the 10s is the first bit of complex UTF-8 char (U+7FFFFFFF) so the next 5 bytes of
this symbol will be only in next buffer. So the last char will be encoded wrong or be missed.
Am I right and how to fix this?
By fixing i mean decoding separate nio buffers not just the whole sequence of bytes after getting all buffers.

  • 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-31T23:21:21+00:00Added an answer on May 31, 2026 at 11:21 pm

    You have a bunch of issues here. One of them is that you might not have read an entire encoded character. Usually you need to have some means of determining you have reached the end of a message such as a message length or newline before attempting to decode it.

    BTW: The largest possible code point is U+10FFFF. The largest char values is U+FFFF

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

Sidebar

Related Questions

Could you guys please tell me how I can make the following code more
Hi Guys could you please help me refactor this so that it is sensibly
Could you guys give me an example how to read and write from/to xml
I could be not more sorry guys - the question was a very wrong
Hello there fellow Stackers! I wonder if anybody could tell me what the following
Hi guys could anyone tell me where im going wrong? The basic aim of
Hi guys wonder if you guys could help me I'm trying to compile a
Ok I give up and would really appreciate it if you guys could cast
Could you guys recommend me a good db modeling tool? Mainly for SQL Server...
It seems that C# 3 hit me without me even noticing, could you guys

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.