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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:11:34+00:00 2026-06-15T01:11:34+00:00

I am facing the problem similar to How to Force a jar to uses(or

  • 0

I am facing the problem similar to How to Force a jar to uses(or the jvm runs in) utf-8 instead of the system’s default encoding. There is a server and client java applications. If I run both of them from Eclipse then everything works just fine. If I make jars then a String exchanged between them gets spoiled (wrong encoding).

If I run both images with -Dfile.enconding=utf-8 JVM parameter then it works okay. But since the link above says that it is not the best solution (at least requires running jar from bat) I have tried to solve the issue with specifying encoding to BufferedReader. But it fails and with jar it is difficult to debug.

This code is for sending request and getting one line in JSON format as reply. The reply is proved to have UTF-8 encoding.

public static String sendRequest (String request) {
    if (request == null) return null;

    try {
        URL url = new URL(request);
        HttpsURLConnection con = (HttpsURLConnection)url.openConnection();
        BufferedReader inReader = new BufferedReader(new InputStreamReader(con.getInputStream(), Charset.forName("UTF-8")));
        String line = inReader.readLine();
        inReader.close();
        return line;
    } catch (Exception e) {
        e.printStackTrace(System.err);
    }

    return null;
}

This is how the line look like

{“response”:[{“uid”:123456,”first_name”:”Имя”,”last_name”:”Фамилия”}]}

Then I prepare it to use in Gson.fromJson()

int beginIndex = reply.indexOf('[');
int endIndex = reply.indexOf(']');
reply = reply.substring(beginIndex + 1, endIndex);
SocialPerson vkPerson = new Gson().fromJson(reply, SocialPerson.class);

After that the String is being sent to server using Netty’s ChannelBuffer generated with ChannelBuffers.wrappedBuffer() and NettyUtils.writeStrings()

I try to debug Client in Eclipse and Server running from jar, then Eclipse shows that until the string is really given to framework to deliver it looks valid.

Then I debug Server and Client runs from Jar and once string being received it already looks like rubbish.

At server side

    private final String username;
    private final String password;

    public SimpleCredentials(ChannelBuffer buffer)
    {
        this.username = NettyUtils.readString(buffer);
        this.password = NettyUtils.readString(buffer);
    }

Where do you think the problem can be? Sorry, I can not post all the code here.

UPD:
username is generated from firstName and lastName

ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(opCode, NettyUtils.writeStrings(userId, userName, refKey));
  • 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-15T01:11:35+00:00Added an answer on June 15, 2026 at 1:11 am

    You shouldn’t be using the file.encoding system property.

    The best way to avoid such encoding issues is to never assume anything about default platform encodings and always provide an encoding when constructing readers or when converting bytes to Strings and vice versa.

    Your sendRequest method seems to be OK with respect to handling encodings: it reads characters from the input, explicitly mentioning that it expects the stream to be encoded in UTF-8.

    However, we can’t see the other end of the client/server sequence. Quoting you:

    After that the String is being sent to server using Netty’s
    ChannelBuffer generated with ChannelBuffers.wrappedBuffer() and
    NettyUtils.writeStrings()

    You also mentioned that you can’t attach the entire code here, which is understandable; therefore, I’d advise that you look into how exactly you’re sending those strings out, and whether or not you’re explicitly specifying an encoding while doing so.

    EDIT as per OP’s update: well, I’m sorry that I am not familiar with Netty, but still I’ll take a shot here. Doesn’t NettyUtils.writeStrings(), or any of the code that calls it, accept a character encoding? I can’t find the JavaDoc to any NettyUtils online. Work with me here. 🙂

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

Sidebar

Related Questions

I'm facing problem when migrate my web app project from development server to live
We are facing a strange performance problem with SQL Server Express 2005 in a
I am facing a similar issue to the problem faced by the similar StackOverflow
I find myself again and again faced with a similar problem: there's some piece
I am facing a similar problem to this question has anybody found a solution
One problem that I am facing is having many queries with similar select statements
I'm facing a very similar problem as I'm trying to install psycopg2 onto Mac
Iam facing problem in understanding and converting a matlab code into opencv. I want
iam facing problem in passing array to view. this is my controller code.. function
I am facing problem while setting focus in EdiText. Below is my EditText property.

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.