Results 1 to 7 of 7
  1. #1
    pankbiet is offline Member
    Join Date
    Feb 2009
    Posts
    2
    Rep Power
    0

    Default Help needed for strings....urgent

    We as a part of our project are dealing with something called info reference which is actually a stream of bytes which has hex values in it. Values can range form 00 to FF. Now the API to which this has to be sent expects a String. We tried putting the information in a string and sending it but the system at site rejects the info reference in two cases:

    1. When the info reference is of form: 11 23 45 00 00 56 56 (This is print of content of each byte of the string in Hex format. If we print is it as a string then we will see control chars printed)

    The first 00 is taken to be as a NULL and the reading of the string stops there itself and hence the system rejects is as Invalid format error.

    2. When the info stream has form : 11 23 89 89 80 80

    Here UTF coding error is coming since the string is made up of chars and for Hex values more that 7F there is no valid char represention. So the 89 and 80 and any Hex value more than 7F is replaced by the REPLACEMENT CHARACTER e.g. EFBFBD.

    We want to pass the info reference as it is. Is there any way in which java strings can be tweaked to take care of the above mentioned situaton? Its strings only.....byte arrays wont be accepted.
    Please do reply.

    Sorry again if this is not related to the forum but I really need a solution to this.

    Anticipating early reply

  2. #2
    Join Date
    Dec 2008
    Location
    Italy
    Posts
    79
    Rep Power
    0

    Default

    If you have a stream of byte you can use a java.io.InputStreamReader, then its read() method which translate bytes into chars (you can also specify the charset). Once you have the chars you can build your String and pass it to your API.

    But also notice that String has a contructor of form String(byte[] bytes)

  3. #3
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    6

    Default

    Please do NOT put "urgent" or "help please" or "!!!!!" in your title for your thread, instead describe your problem in a few words.
    -MK12
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  5. #5
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    6

    Default

    You're pretty confident... first you use a very annoying "urgent help!!" title, then hand out your homework, then give us a deadline for it! (anticipating early reply).
    -MK12
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Look at my signature too. I really hate such threads lol. Lots of members want to help newbies, so why hang on this way. :(

  7. #7
    pankbiet is offline Member
    Join Date
    Feb 2009
    Posts
    2
    Rep Power
    0

    Default

    Maybe my choice of words was inappropriate..............Apologies for the same. Thanks for taking out time to reply.

    Regards

Similar Threads

  1. hi help needed, this is urgent
    By msciriha in forum NetBeans
    Replies: 1
    Last Post: 02-07-2009, 06:16 PM
  2. Urgent help needed here pls!!
    By Manfizy in forum NetBeans
    Replies: 5
    Last Post: 01-28-2009, 07:38 AM
  3. SJF Dynamic DataTable **Urgent Help Needed**
    By pathan.umapathi@gmail.com in forum JavaServer Faces (JSF)
    Replies: 1
    Last Post: 09-26-2008, 06:50 AM
  4. Urgent Java programmer needed.
    By KevinG in forum Jobs Offered
    Replies: 5
    Last Post: 04-23-2008, 04:02 AM
  5. urgent help needed - paper submission.
    By dirtycash in forum New To Java
    Replies: 2
    Last Post: 11-23-2007, 11:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •