Convert/Represent 1 byte char in 2 bytes

Hello All,
I would like to convert/represent the 1 byte char to 2 byte.
for example the "Test ��" is a 9 byte string if i use getBytes()
the byte array length is 7 bytes but if i use getBytes("UTF8")
i'm getting 9 bytes but it's not printing "��"
Now i want to represent them in a 2 byte. How do i do that?
Regards
G S Sundaram

getBytes("UTF16-BE") or getBytes("UTF16-LE"). What is �� supposed to be here?

Similar Messages

  • FM to convert double byte chars

    Hi All,
    Is there anyone know what are the function module to convert double-byte chars? Thanks.

    Seems like Blue Sky is not clear
    You want to convert what into what?
    Whats the purpose of this requirement, kindly give more details.
    Regards
    Karthik D

  • JDBC thin driver pads CHAR col to byte size when NLS_LENGTH_SEMANTICS=CHAR

    We're using an Oracle 9.2 database with the database character set specified as AL32UTF8 with NLS_LENGTH_SEMANTICS set to CHAR. I've reproduced this problem with both the "classes12.zip" and "ojdbc14.jar" available with the Oracle 9.2 client installation.
    The problem occurs with the JDBC thin driver. The problem does not occur with the JDBC OCI driver (nor SQL*Plus 9.2).
    There are 2 relatively simply workarounds: use the OCI driver or convert CHAR columns to VARCHAR2 columns. I'm mostly curious as to whether there is some kind of setting for the thin driver to circumvent this problem, or if this is actually expected behavior. We're not that familiar with the NLS_LENGTH_SEMANTICS setting.
    Consider a table as follows:
    create table my_table (status CHAR(1));
    If I describe the table it correctly shows the column using CHAR semantics.
    STATUS CHAR(1 CHAR)
    Given the AL32UTF8, this means that 4 bytes of storage are reserved for this column.
    If I insert a single ASCII character in this table (for example "A") then read it back using the JDBC thin driver, I get the string "A " - the letter A followed by 3 spaces. In other words, the thin driver appears to have padded the value to its BYTE length. The OCI driver and SQL*Plus do not pad the value.
    I understand that CHAR columns are normally blank padded when the data size is shorter than the defined column length, but I think that with NLS_LENGTH_SEMANTICS=CHAR, the padding should be based on the length of the column in chars, not in bytes.
    Can anyone shed some light on this issue?
    Thanks in advance,
    Tim

    Update:
    I guess I should mention we're using Java 2 SDK 1.4.1_01 on Windows XP with an Oracle 9.2 database on Windows 2000.

  • Help with Sample on Converting an XML string to a byte stream

    Hello All,<br /><br />I am sure this is something simple, but I am just not figuring it out right now.<br /><br />I am following the sample - "Converting an XML string to a byte stream" from the developer guide since I want to prepopulate just 1 field in my PDF form.<br /><br />How do I reference my form field within my servlet code properly??<br /><br />I have tried a few things now, my field is within a subform, so I thought it would be <root><subformName><fieldname>My data</fieldname></subformName></root>  I have also tried adding <page1> in there too.<br /><br />I am following everything else exactly as given in the sample code.<br /><br />I do have an embedded schema within the form and the field is bound.<br /><br />Thanks,<br />Jennifer

    Well, if you have a schema defined in the form, then the hierarchy of your data must match what is described in the schema. So, can't really tell you what it would look like, but just follow your schema.
    Chris
    Adobe Enterprise Developer Support

  • How do i convert an image object to a byte array ?

    Hi
    how do i convert an image object into a byte array
    early reply apperciated

    Oh sorry my method and the other method need to have the pixels from the Image passed to them which you get my using pixelgrabber:
    //create width and height variables from image
              int w = img.getWidth(this);
              int h = img.getHeight(this);
              //retrive picture from image
              int[] pix = new int[w * h];
              PixelGrabber pg = new PixelGrabber(img, 0, 0, w, h, pix, 0, w);
              try{ pg.grabPixels();
              } catch (InterruptedException ioe) {
                   System.err.println("Interrupted");
              if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
              System.err.println("image fetch aborted or errored");
              }

  • Double byte chars in URI

    Is it possible to send double byte chars through a URI? Is this possible to send from a servlet to a client browser then the client browser will just forward it on back to a server. What would have to happen on the server and client side for this to happen?
    I guess I have basic non-understanding on how encoding works through http, using a client browser and also sending a response to a servlet container. Can anyone tell me how this process works? What are the default encodings, what is configurable on the client side or server side, etc.? Thanks.

    I believe the rule is that you first have to encode the string into UTF-8 bytes, then apply the URL-encoding rules to that array of bytes. At least, that's how I understand the most recent rules for HTTP. But it's likely that most browsers don't follow this rule properly, so be prepared for a rough ride if you try this.

  • Converting from unsigned int / short to byte[]

    Can anybody help me, I am trying to convert from:
    - unsigned int to byte[]
    - unsigned short to byte[]
    I will appreciate your help lots. thanks.

    @Op.
    This code converts an integer to a byte[], but you have to consider the byte order:
            int value = 0x12345678;
            byte[] result = new byte[4];
            for (int i=3; i>=0; i--) {
                result[i] = (byte)(value & 0xff);
                value = value >> 8;
            }This is another option:
            int dummy = 7;
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            os.write(dummy);
            byte[] bytes = os.toByteArray();Kaj

  • Difference between BYTE & CHAR

    hi all,
    In Oracle, As per below syntax, what is the difference between BYTE & CHAR used as datatype size for NAME column:
    CREATE TABLE CLIENT
    NAME VARCHAR2(11 BYTE),
    ID_CLIENT NUMBER
    and
    CREATE TABLE CLIENT
    NAME VARCHAR2(11 CHAR), -- or even VARCHAR2(11)
    ID_CLIENT NUMBER
    rgds,
    pc

    First of - do not use reserved words for columns (NAME).
    If the database character set is UTF-8, which I believe is the default in recent version of Oracle. In this case, some characters take more than 1 byte to store in the database.
    If you define the field as VARCHAR2(11 BYTE), Oracle will allocate 11 bytes for storage, but you may not actually be able to store 11 characters in the field, because some of them take more than one byte to store, e.g. non-English characters.
    By defining the field as VARCHAR2(11 CHAR) you tell Oracle to allocate enough space to store 11 characters, no matter how many bytes it takes to store each one. I believe that in Oracle 10g, 3 bytes per character were used.
    regards,
    Robert.

  • Byte[] -- char[]

    Hi,
    Without casting each member of the array, can we cast byte[] --> char[] ??
    thank you.

    Ok, common misconception. Just because you may be
    able to write
    char[] = byte[].toString();
    doesn't mean its any faster.But you can't write that :P Even if you call toCharArray() after you get the String, it's going to give you the hashcode, not a conversion.

  • DOUBLE BYTE chars

    Hi All,
    While uploading some multi-lingual text from a application
    server file, is there any way to treat DOUBLE BYTE characters
    as DOUBLE BYTE ?
    Currently, it is treated as SINGLE BYTE character.
    With Thanks and Regards,
    R.Nagarajan.
    We can -

    No response.

  • HOW can I convert int value char TO String

    I am trying to study Java by books, but sometimes it is quite difficult to find answers even to simple questions...
    I am writing a program that analyzes a Chinese text in Unicode. What I get from the text is CHAR int value (in decimals), and now I need to find them in another text file (with RegEx). But I can't find a way how to convert an INT value of a char into a String.
    Could you help me?
    Thank you in advance.

    You are confusing matters a bit. A char is a char is a char, no matter
    how you represent it. Have a look at this:char a= 'A';
    char b= 65;Both a and b have the same value. The representation of that value
    can be 'A' or 65 or even (char)('B'-1), because the decimal representation
    of 'B' is 66. Note the funny construct (char)(...). This construct casts
    the value ... back to the char type. Java performs all non-fraction
    arithmetic using four byte integers. The cast transforms it back to
    a two byte char type.
    Strings are just concatenations of zero or more chars. the charAt(i)
    method returns you the i-th char in a string. Have a look:String s= "AB";
    char a= 'A';
    char b= (char)(a+1);
    if (a == s.charAt(0)) System.out.println("yep");
    if (b == s.charAt(1)) System.out.println("yep");This piece of code prints "yep" two times. If you want to compare two
    Strings instead, you have to do this:String s= "AB";
    char a= 'A';
    char b= 'B';
    String t= ""+a+b;
    if (s.equals(t)) System.out.println("yep");Note the 'equals' method instead of the '==' operator. Also note that
    string t was constructed using those two chars. The above was a
    shorthand of something like this:StringBuffer sb= new StringBuffer("");
    sb.append(a);
    sb.append(b);
    String t= sb.toString();This is all handled by the compiler, for now, you can simply use the '+'
    operator if you want to append a char to a string. Note that it is not
    very efficient, but it'll do for now.
    Does this get your started?
    kind regards,
    Jos

  • Invalid byte 2 of 3-byte UTF-8 sequence.

    Hi All
    I have to read a xml file from a given URL, which consists some french characters in it. I am getting
    IOException :Invalid byte 2 of 3-byte UTF-8 sequence Exception.
    The code i am using is.
    SAXBuilder builder = new SAXBuilder();
    Document doc = builder.build(new URL(url));
    Thanks in Advance
    Amit Srivastava

    The original XML may have been coded in UTF-16, but then you have this code:xml.trim().getBytes()which says
    "Take that XML string and convert it to bytes, using my system's default encoding."
    The parser then attempts to parse those bytes, which are encoded in ISO-8859-1 or windows-1252 or some such. Since you didn't declare this fact in the XML's header, the parser assumes the bytes are encoded in UTF-8. When it comes to a sequence of bytes in the code that aren't valid UTF-8 encodings of anything then it complains.
    If you really have to convert the input to bytes then try this:xml.trim().getBytes("UTF-8")

  • Java – Regular Expressions – Finding any non digit byte in a multiple byte

    Hello,
    I’m new to JAVA and Regular Expressions; I’m trying to write a regular expression that will find any records that contain a non digit byte in a multiple byte field.
    I thought the following was the correct expression but it is only finding records that contain “all” non digit bytes.
    \D{1,}
    \D = Non Digit
    {1,} = at least 1 or more
    Below is my sample data. I would like the regular expression to find all of the records that are not all numeric. However when I use the regular expression \D{1,} it is only finding the 2 records that all bytes are non digits. (i.e. “ “ and “A “)
    “ 111229”
    “2 111229”
    “20091229”
    “200912c9”
    “201#1229”
    “20101229”
    “20110229”
    “20111*29”
    “20111029”
    “20111229”
    “20B11229”
    “A “
    “A0111229”
    Please note I have also tried \D{1,}+ and \D{1,}? And they also do not return my desired results
    Any assistance someone can provide would be greatly appreciated.

    You don't show the code you are using but I surmise you are using String.matches() which requires that the whole target must match the regular expression not just part of it. Instead you should create a Pattern and then a Matcher and use the Matcher.find() method. Check the Javadoc for Pattern and Matcher and look at the Java regex tutorial - http://docs.oracle.com/javase/tutorial/essential/regex/ .
    P.S. You can re-use the Pattern object - you don't have to create it every time you need one.
    P.P.S. Java regular expressions work with characters not bytes and characters are not not not bytes.

  • Java.io.UTFDataFormatException: Invalid byte 1 of 1-byte UTF-8 sequence.

    Hi,
    I see the below error when I try to import bunch of email templates.
    com.waveset.util.WavesetException: ==> java.io.UTFDataFormatException: Invalid byte 1 of 1-byte UTF-8 sequence.
    Can any one explain me why is this happenining?
    Thanks,
    Siddiqui

    Hi Siddiqui,
    It looks like u r importing some characters those are not valid UTF-8 character set and some time this type of error comes when u try to import characters like *<,>* so use *& lt;* for < and *>* for >.
    sorry those Characters r not display properly :-(
    Thanx
    Shant
    Edited by: Shant on Jan 18, 2008 6:19 AM
    Edited by: Shant on Jan 18, 2008 6:23 AM

  • "Invalid byte 1 of 1-byte UTF-8 sequence" exception trying to display image

    Hi there!
    Last night I updated my project to open the <wellcome-file>. So I put this in my web.xml file:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <web-app
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        id="WebApp_ID"
        version="2.5">
    <context-param>
        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.jspx</param-value>
    </context-param>
    <welcome-file-list>
        <welcome-file>faces/login.jspx</welcome-file>
    </welcome-file-list>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    [...]Now when I type http://localhost:8080/myproject the login.jspx is opened as expected.
    But after this change, exceptions started to shown when images from my template.jspx is loaded (?).
    Here's a piece of my template.jspx:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <jsp:root
         xmlns:jsp="http://java.sun.com/JSP/Page"
         xmlns:h="http://java.sun.com/jsf/html"
         xmlns:f="http://java.sun.com/jsf/core"
         xmlns:ui="http://java.sun.com/jsf/facelets"
         xmlns:r="http://richfaces.org/rich"
         xmlns:a4j="http://richfaces.org/a4j"
         version="2.0">
    <f:facet name="controls">
         <h:panelGroup>
              <h:graphicImage
                   value="../imagens/erro.png"
                   id="hidelink" />
         </h:panelGroup>
    </f:facet>
    [...]And here is the exception:
    SEVERE: Error Rendering View[/imagens/erro.png]
    com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence.
         at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(Unknown Source)
         at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(Unknown Source)
         at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(Unknown Source)
         at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.arrangeCapacity(Unknown Source)
         at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.skipString(Unknown Source)
         at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
         at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
         at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
         at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
         at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
         at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    [...]And, of course, the image is not displayed.
    The images from pages that uses template.jspx works fine (even the same image that causes the exception).
    Only images from my template.jspx and pages that I use with <ui:include> throws the exception.
    My directory structure:
    web
    |___templates
    |___imagens
    |___pages
    login.jspxI tried with ISO-8859-1 and UTF-8 as encoding and the problem is the same.
    I need some help. Any help.
    If any more info is needed, please just ask me.
    Thank you in advace!
    I'm using:
    JSF 1.2; Facelets 1.1.14; Richfaces 3.3; Tomcat 6, Java 6
    Yoshimit

    I got the same error. It was because my application's .java files were saved as UTF-8 but the .xhtml files were saved as cp1255 encoding. I have also added a filter to set the charset to each response like described [here |http://www.coderanch.com/t/211549/JSF/java/JSF-Character-Sets-UTF-mainly] .
    PS: I had another error after that which was caused by copying the Richfaces xmlns definitions from a PDf provided by Refcardz. The " symbol turend to something that the SAX parser could not process.
    Hope this helps.
    Pavel Myshkin

Maybe you are looking for