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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:27:49+00:00 2026-05-27T16:27:49+00:00

I’m trying to achieve this: I have a PDF byte[] in java web service

  • 0

I’m trying to achieve this:

I have a PDF byte[] in java web service that I must send as a base64 string to a .NET client that does this to reconstruct the file.

Encoding.Convert(Encoding.Unicode, Encoding.Default, Convert.FromBase64String(inputJava))

I cannot change the client code and right now the java web service is calling another .NET web service that does this to turn the byte[] into a base64 string:

System.Text.Encoding.Convert(System.Text.Encoding.GetEncoding(1252), System.Text.Encoding.Unicode, b);

Beside the base64 that I can make in various ways (e.g. with org.apache.commons.codec.binary.Base64), I have to turn the original byte[] into a UTF-16LE byte[]…

I tried this:

byte[] output = new byte[b.length * 2];
for(int i=0; i < b.length; i++) 
{
  int val = b[i];
  if(val < 0) val += 256;

  output[2*i + 0] = (byte) (val);   
  output[2*i + 1] = 0; 
}

This works fine for values below 128 (e.g. for 1 => 0100, 2 => 0200, … , 127 => 7F00) but for values above (128 -> 255) I don’t know how to get the equivalent 2bytes values; I know that for byte 156 (9C) the corresponding value is 8301 (0x5301) and for byte 224 (E0) the corresponding value is 12501 (0x7D01) but I didn’t manage to find an algorithm to get all the other values.

Is there a mapping table between byte value and the corresponding UTF-16LE surrogate pair or an algorithm to map values from 128 to 255?

Thanks in advance!

  • 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-27T16:27:49+00:00Added an answer on May 27, 2026 at 4:27 pm

    I finally found a solution. It looks like that only bytes from 128 to 159 need the surrogate pairs. I use this piece of code to emulate .NET Unicode encoding:

    public class Encoder {
       static Map<Integer, Integer> mapTiny = new HashMap<Integer, Integer>() {
            public Integer get(Object key) {
                Integer code = super.get(key);
                if (code == null)
                    code = (Integer) key;
                return code;
            }
        };
    
        static {
            mapTiny.put(128,8364);
            mapTiny.put(130,8218);
            mapTiny.put(131,402);
            mapTiny.put(132,8222);
            mapTiny.put(133,8230);
            mapTiny.put(134,8224);
            mapTiny.put(135,8225);
            mapTiny.put(136,710);
            mapTiny.put(137,8240);
            mapTiny.put(138,352);
            mapTiny.put(139,8249);
            mapTiny.put(140,338);
            mapTiny.put(142,381);
            mapTiny.put(145,8216);
            mapTiny.put(146,8217);
            mapTiny.put(147,8220);
            mapTiny.put(148,8221);
            mapTiny.put(149,8226);
            mapTiny.put(150,8211);
            mapTiny.put(151,8212);
            mapTiny.put(152,732);
            mapTiny.put(153,8482);
            mapTiny.put(154,353);
            mapTiny.put(155,8250);
            mapTiny.put(156,339);
            mapTiny.put(158,382);
            mapTiny.put(159,376);
        }
    
    
    public static String encode(byte[] b) throws IOException {
    
            ByteArrayInputStream in = new ByteArrayInputStream(b);
            ByteArrayOutputStream convFileByteArray = new ByteArrayOutputStream();
            int i = in.read();
            while (i != -1) {
                convFileByteArray.write(new byte[] { (byte) (mapTiny.get(i) & 0xff), (byte) ((mapTiny.get(i) >> 8) & 0xff) });
                i = in.read();
            }
            return Base64.encodeToString(convFileByteArray.toByteArray(), false);
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.