Char to byte translation

If I would like to use the new java.util.logging.FileHandler and I would like to use this FH to log binary data, that is plain data, not text (by means of a "BinaryFormatter" that wraps the byte[] into a String), how can I make sure that the outputfile generated contains exactly the bytes as wrapped into the string and not a result of a conversion (char->byte) that is a result of the encoding defined in
Sys.prop. file.encoding.
Of course I can write my own FileHandler etc. but I would like to use the std. stuff as much as possible.
In short it comes down to: what characterset has a one-to-one mapping
for every value [0..255]?
Greetings,
Gouweloos

In short it comes down to: what characterset has a one-to-one mapping for every value [0..255]?You can play with this:
char[] chrs = new char[255];  // or 256
for(int j=0;j<chrs.length;j++){
     chrs[j]=(char)j;
String str = new String(chrs);
byte[] byts = str.getBytes("UTF8");//here is the point:  try many other character sets
System.out.print("byte array length: ");
System.out.println(byts.length);
for(int j=0;j<byts.length;j++){
  System.out.print(byts[j]);
  System.out.print(" ");
System.out.println();

Similar Messages

  • How can i convert an object to stream of chars or bytes?

    how can i convert an object to stream of chars or bytes?

    One way is the serialization mechanism. There are examples and explanations of it in the Java tutorial: http://java.sun.com/docs/books/tutorial/essential/io/serialization.html

  • Conversion from char to byte

    can anybody to convert char which is unicode in java as one byte. i want to print that byte as ascii.
    i tried below method.
    char temp='s';
    ByteBuffer buff= ByteBuffer.wrap(some byte array of some size);
    buff.putChar(temp);
    out.writeByte(buff.getChar()); // out is my dataoutput stream which
    // stores in some file by using
    // fileoutputstream.
    in some case i got right output like: s
    but in some case i got: sX where X=white space.
    so it's still writing as unicode eventhough i called writeByte.
    i want to change my program little bit by putting char as byte and not as char in bytebuffer and i want to do something like this after i store my chars as byte
    out.writeByte(buff.getByte());
    do you have any method to convert char to byte and store it in buff?
    thanks a lot.

    Try the toBytes() method of the String class.

  • Invalid UTF-8 middle byte 0x6f (at char #3309, byte #2895)

    Hello Oracle Support/ SOA Experts,
    Please guide me on how to resolve this issue.
    Issue Description : We are using ATG,Oracle SoA SUite 11g as the Front and Middleware applications for our current website project.The project is basically for latin america(Portuguese Language) and we are facing encoding issue while sending the request from ATG(Front End) to SOA (Middleware).We have an SOA-xsd [customer.xsd) that contains FirstName,LastName,MiddleName as elements.Front End application(ATG) sends the customer xsd in ISO-8859-1 encoding format as we understood that only encoding format for sending the portuguese names is this format.Front is able to send the request to SOA Without any issues however the only format which SOA Suite accepts in our BPEL process is UTF-8 and hence we are seeing this invalid UTF-8 error.Can anyone of you please explain us on how to resolve this issue or please guide us which encoding format can we use for passing portuguese characters from front end to SOA Suite.
    *Exception*:
                java.lang.RuntimeException: [com.ctc.wstx.exc.WstxLazyException] com.ctc.wstx.exc.WstxIOException: Invalid UTF-8 middle byte 0x6f (at char #3309, byte #2895): [com.ctc.wstx.exc.WstxLazyException] com.ctc.wstx.exc.WstxIOException: Invalid UTF-8 middle byte 0x6f (at char #3309, byte #2895)
    What we tried :
    Since ATG or front end is using the ISO-8859-1 format to send the request to SOA,we tried to use the encoding format in all the SOA BPEL XSD but we are unable to deploy after changing the encoding and we see the below error :
    Exception:
    Redeploying on /Farm_soa2_domain/soa2_domain/soa_server1 ...
    Redeploying on "/Farm_soa2_domain/soa2_domain/soa_server1" failed!
    Error during deployment/undeployment: oracle.mds.transfer.TransferException:
    MDS-00001: exception in Metadata Services layer
    MDS-00521: error while reading document /deployed-composites/default/ManageCustomerOrderOrchestration_rev1.0/xsd/ManageContract.xsd from metadata repository
    IS0-8859-1
    IS0-8859-1
    MDS-00001: exception in Metadata Services layer
    MDS-00521: error while reading document /deployed-composites/default/ManageCustomerOrderOrchestration_rev1.0/xsd/ManageContract.xsd from metadata repository
    IS0-8859-1
    IS0-8859-1

    Hello Oracle Support/ SOA Experts,
    Please guide me on how to resolve this issue.
    Issue Description : We are using ATG,Oracle SoA SUite 11g as the Front and Middleware applications for our current website project.The project is basically for latin america(Portuguese Language) and we are facing encoding issue while sending the request from ATG(Front End) to SOA (Middleware).We have an SOA-xsd [customer.xsd) that contains FirstName,LastName,MiddleName as elements.Front End application(ATG) sends the customer xsd in ISO-8859-1 encoding format as we understood that only encoding format for sending the portuguese names is this format.Front is able to send the request to SOA Without any issues however the only format which SOA Suite accepts in our BPEL process is UTF-8 and hence we are seeing this invalid UTF-8 error.Can anyone of you please explain us on how to resolve this issue or please guide us which encoding format can we use for passing portuguese characters from front end to SOA Suite.
    *Exception*:
                java.lang.RuntimeException: [com.ctc.wstx.exc.WstxLazyException] com.ctc.wstx.exc.WstxIOException: Invalid UTF-8 middle byte 0x6f (at char #3309, byte #2895): [com.ctc.wstx.exc.WstxLazyException] com.ctc.wstx.exc.WstxIOException: Invalid UTF-8 middle byte 0x6f (at char #3309, byte #2895)
    What we tried :
    Since ATG or front end is using the ISO-8859-1 format to send the request to SOA,we tried to use the encoding format in all the SOA BPEL XSD but we are unable to deploy after changing the encoding and we see the below error :
    Exception:
    Redeploying on /Farm_soa2_domain/soa2_domain/soa_server1 ...
    Redeploying on "/Farm_soa2_domain/soa2_domain/soa_server1" failed!
    Error during deployment/undeployment: oracle.mds.transfer.TransferException:
    MDS-00001: exception in Metadata Services layer
    MDS-00521: error while reading document /deployed-composites/default/ManageCustomerOrderOrchestration_rev1.0/xsd/ManageContract.xsd from metadata repository
    IS0-8859-1
    IS0-8859-1
    MDS-00001: exception in Metadata Services layer
    MDS-00521: error while reading document /deployed-composites/default/ManageCustomerOrderOrchestration_rev1.0/xsd/ManageContract.xsd from metadata repository
    IS0-8859-1
    IS0-8859-1

  • How can I check the field char can be translate into num type?

    Hi
    when I import Excel file into sap . I create one table to save the column and there are one column who's tpye is num . as we all know ,all the fields from excel are char type, the sap system will
    automatic translate char to num . but if the field can not translate char to num. then the program
    will be crush down
    such as : qty type char : 500 in excel then in tab qty type num :500 ok
    qty type char : 50A in excel then crash
    Is there any function that can deal with this matter?

    You may [CATCH|http://help.sap.com/abapdocu/en/ABAPCATCH_SYSTEM-EXCEPT_SHORTREF.htm] the error.
    CATCH SYSTEM-EXCEPTIONS convt_no_number = 1
                            conversion_errors = 2.
      MOVE char TO num.
    ENDCATCH.
    IF sy-subrc EQ 0.
      " converted
    ELSEIF sy-subrc EQ 1.
      " not numeric
    ELSEIF sy-subrc EQ 2.
      " not converted, other error
    ENDIF.
    Regards

  • Form English Char ( Single Byte  ) TO Double Byte ( Japanese Char )

    Hello EveryOne !!!!
    I need Help !!
    I am new to Java ,.... I got assignment where i need to Check the String , if that string Contains Any Non Japanse Character ( a~z , A~Z , 0 -9 ) then this should be replaced with Double Byte ( Japanese Char )...
    I am using Java 1.2 ..
    Please guide me ...
    thanks and regards
    Maruti Chavan

    hello ..
    as you all asked Detail requirement here i an pasting C code where 'a' is passed as input character ..after process it is giving me Double Byte Japanese "A" .. i want this to be Done ..using this i am able to Convert APLHA-Numeric from singale byte to Doubel Byte ( Japanse ) ...
    Same program i want to Java ... so pleas guide me ..
    #include <stdio.h>
    int main( int argc, char *argv[] )
    char c[2];
    char d[3];
    strcpy( c, "a" ); // a is input char
    d[0] = 0xa3;
    d[1] = c[0] + 0x80;
    printf( ":%s:\n", c ); // Orginal Single byte char
    printf( ":%s:\n", d ); // Converted Double Byte ..
    please ..
    thax and regards
    Maruti Chavan

  • Char * to byte[]

    suppose i have a char * being passed into a C function. I then want to convert that to a byte[] to pass into my JNI call, which is done in the same function. how do i do that? i have tons of ideas, but i can't get them to coagulate. thanks

    JNI gives you functions for constructing java arrays. The function you are after is
    jbyteArray NewByteArray(env, length);
    Once you have done this, you should be able to loop through the char* and the byte array, populating the array.
    There is a certain amount of handwaving in this explanation. You will have to read up on accessing array elements.
    A good book on all this JNI stuff is
    essential JNI, by Rob Gordon.

  • OWB-Import does not distinguish between nls_length_semantics char and byte.

    We have a 10g-DB with UTF8 charset and nls_length_semantics=char and we've created an OWB warehouse module for 10g with several tables in it. After deploy operation for a table the column length attributs are looking nice. But if we re-import this table the varchar fields have the threefold length!
    This makes life hard for us, because sometimes it's necessary to reconcile discrepancies in development cycle and some tables have about 150 columns.
    Does anybody have suggestions?
    The OWB version is 10.1.0.3.0.
    Regards
    Ralf

    Ralf,
    Oracle stores the length of VARCHAR columns in two ways in its metadata. One is the length as required by the application, and the other is the length required to store UTF data.
    One UTF character can take upto 3 characters of storage. When OWB reads in the definition from data dictionary, it uses the actual characters allocated to the column, and thus u see a three fold increase in VARCHAR columns.
    Try this for your table
    select
    column_name, data_length, char_length
    from
    user_tab_columns
    where
    table_name='nameOfTable'
    And that is how Oracle designed the database, but unfortunately OWB does not have that twin way of seeing things.
    - Jojo

  • Is a char 1 byte or 2 bytes in java ???

    Is it one or two ???
    Thank you

    Is it one or two ???A char in Java is a 16-bit Unicode 2.0 character.
    It's a fundamental fact of the Java language. It you
    haven't access to this kind of basic information you
    can as well stop trying.the 1.4.1 API says 3.0
    Character information is based on the Unicode
    Standard, version 3.0.The Java Language specification states: "The integral types are .......... and char, whose values are 16-bit unsigned integers representing Unicode characters". So the version number isn't in the specification. I guess there will be a version 4.0 some day.

  • Difference between CHAR & BYTE with respect to Storage

    Hi,
    I HAVE CREATED THREE TABLES WITH DIFFERENT STORAGE FORMATS.
    SQL> CREATE TABLE A
    2 (ENAME CHAR);
    Table created.
    SQL> CREATE TABLE AA
    2 (ENAME CHAR(1 CHAR));
    Table created.
    SQL> CREATE TABLE AAA
    2 (ENAME CHAR(1 BYTE));
    WHEN I AM TRYING TO INSERT THE VALUES
    CASE1) INSERTING A SINGLE CHARACTER ONLY
    SQL> INSERT INTO A
    2 VALUES
    3 ('A');
    1 row created.
    SQL> INSERT INTO AA
    2 VALUES
    3 ('A');
    1 row created.
    SQL> INSERT INTO AAA
    2 VALUES
    3 ('A');
    1 row created.
    INSERTING MORE THAN ONE CHARACTER IN AAA TABLE
    SQL> INSERT INTO AA
    2 VALUES
    3 ('AA');
    ('AA')
    ERROR at line 3:
    ORA-12899: value too large for column "RAVI1"."AA"."ENAME" (actual: 2, maximum:
    1)
    SQL> INSERT INTO AAA
    2 VALUES
    3 ('AAA');
    ('AAA')
    ERROR at line 3:
    ORA-12899: value too large for column "RAVI1"."AAA"."ENAME" (actual: 3,
    maximum: 1)
    please can any one tell me the differences.
    Thanks & Regards
    SAI***BABA

    This one might help: Re: What is the difference between VARCHAR2(5 BYTE) & VARCHAR2(5 CHAR)?
    Jim P.

  • How to wrapper char [1] ?

    Hi,
    I have a structure in which a member is defined as :
    char data[1]
    How do I wrapper this correctly?
    I have tried pointer to char but I think that a pointer is 4 bytes.
    I also tried array[1] of char (which is translated into array[0..0) of
    char when I import the code)., but then when I do data[0] = some value,
    I get the following exception :
    SYSTEM ERROR: Attempt to index a NIL array object with index 0.
    Traceback:
    Driver.ConnectToApi at offset 360
    C++ Method(s)
    Class: qqos_SystemException
    Error #: [901, 51]
    Thanks in advance,
    Steven
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>

    Oracle's SQL Datatypes are limited to NUMBER, BINARY_FLOAT and BINARY_DOUBLE.
    There's a few others through PL/SQL including BINARY_INTEGER.
    If you look in USER_ARGUMENTS you can see it is defined slightly differently.
    Don't know whether / how .Net infers datatypes, but it is worth a shot.
    create or replace function v (p number) return  binary_integer is
    begin
    return p;
    end;
    /

  • Help needed in understanding conversion alghorithm from byte to hex

    Hi, I'm studying the following code:
    public static char[] byteToHex(byte[] data) {
      char[] retValue = new char[data.length * 2];
      int value = 0;
      int highIndex = 0;
      int lowIndex = 0;
      for (int i = 0; i < retValue.length; i++) {
        value = (data[i] + 256) % 256;
        highIndex = value >> 4;
        lowIndex = value & 0x0f;
        retValue[i * 2 + 0] = hexTable[highIndex];
        retValue[i * 2 + 1] = hexTable[lowIndex];
      return retValue;
    }There are few things (the most important) which I don't understand about the above code.
    I understood that what's returned has got double size related to what's passed in because a char takes 16 bits while a byte takes 8.
    1) I don't understand why each byte must be first added 256 and then % with 256 (returning the same value - Is this to eliminate negative values?)
    2) I do understand that each byte is transformed in two hexadecimal values: one is the highIndex (first 8 bits) and the second is the lowerIndex (last 8 bits) and that each value is tranformed in its hexadecimal value from the array of hex values.
    3) What I don't really understand is why the highIndex is calculated as: value >> 4
    and the lowest index is calculated as value 0x0f (is this last also to eliminate negative values?)
    If someone could clarify this for me, I'd be very grateful.
    Thanks.
    Marco

    So, does this mean that we add 256 to eliminate the sign?No. You need the whole line to convert a signed byte into an int between 0 and 255.
    A simpler way to do this would be
    value = data[i] & 0xFF;
    This moves down the higher bits so that it turnsinto lower bits. i.e. we need it to >be between 0 and
    15.
    Is this shifted of 4 because Math.pow(2, 4) = 16.0?Doing in this case, x >>4 is the same as x / 16
    This leaves only the lowest 4 bits.Is the following what happens?There are no char values produced. Using 0000 as an example is not a good idea as you can change it in many ways and it is still 0000
    >
    Received as initial value:
    byte: 0000 0000
    What we need to obtain:
    char: 0000 0000 0000 0000
    The first 4 bits of the above byte are shifted of 4
    positions to find the hexadecimal equivalent (if from
    2 I want to get to 16 I have to do the opposite of
    powering a number by 4); The last four bits of the
    byte are extracted because of the '&' operator with
    0x0f (which in binary is 1111 - Therefore all the '1'
    are kept)?Yes.

  • How to calculate byte size of a string

    Hi forum;
    Can you tell me how can I calculate byte count of a string.

    Tahir wrote:
    I read somewhere that string 0123456789ABCDEFFEDCBA987654321089ABCDEF01234567 is 192 bit. Where as it is 48 Byte (one char = 1 byte) or 384 Bits. But 192*2=384. So whats this math? Any pointer?It depends what you mean by "byte count", because it's likely to depend on the character encoding you choose, but the definitive answer is probably to use getBytes(). For example:
    String s = "0123456789ABCDEFFEDCBA987654321089ABCDEF01234567";
    System.out.println(s.getBytes("utf8").length);displays 48, but
    System.out.println(s.getBytes("unicode").length);displays 98.
    Not quite sure why the extra 2 bytes, but I'm sure someone else will know.
    Winston

  • Replace char on String

    Hi All,
    String strValue = "ABC TPT 0694";
    My String is as shown above, I am looking for a way to replace char at byte 6 (position 6) with another Char in String.
    For example at location 6 it is "T" I want to replace it with char "O". can any one tell me how to do this

    String strValue = "ABC TPT 0694";
    char[] chars = strValue.toCharArray();
    chars[5] = 'O';
    strValue = String.valueOf(chars);

  • Exchanging non ASCII bytes by socket tcp

    Hello:
    I'm trying to exchange characters between 0-255 of ascii characters table. I'm using the CharToByteConverter and ByteToCharConverter classes on my client/server programs, but I can't get it.
    The client/server programs use socket tcp, but I'm not sure the data structures that I must to use in order to send bytes with these characteristics (0-255 ascii characters)
    For example I need to send the next array to server program:
    char[] car = new char[15];
    car[0] = (char)129;
    car[1] = (char)12;
    car[2] = (char)201;
    car[3] = (char)1;
    car[4] = (char)48;
    car[5] = (char)48;
    car[6] = (char)1;
    car[7] = (char)1;
    car[8] = (char)95;
    car[9] = (char)4;
    car[10] = (char)17;
    car[11] = (char)3;
    car[12] = (char)22;
    car[13] = (char)38;
    car[14] = (char)53;
    Note: In UDP protocol (socket UDP) the interchange data and the conversions work correctly.
    Any comment will be appreciated, regads,
    Ulises

    You are right. The modem is a device that works (send
    and recive) with tcp/ip or UDP/IP protocol (is a
    modem GPRS). So, I can simulate him with a java
    program sending data by socket tcp/ip. In this case
    is the same.
    The format message is a fact. I can't to choose it.Then that is the message that you are dealing with.
    Presumably this is because you are only writing the client or server and not both.
    >
    My problem is that, for example, I'm waiting (my java
    program with server socket tcp/ip actually) for a
    byte 129 how first byte, but instead of it, I receive
    a byte 63.
    Then one of the following is true.
    - You are using a class that you should not be, like DataInputStream or String.
    - Your understanding of the message protocol is incorrect (perhaps because the spec is wrong.)
    - Or the message that is being sent is wrong but presumably there is nothing that you can do about that.
    Sockets send and receive bytes. They don't send and receive characters.
    Now it could be that the data being sent is indeed characters but that has nothing to do with the socket. It doesn't transform them, map them, nor touch them in any way.
    In addition, depending of the data structure used
    (char [] or byte []) how buffer, I lose some bytes.Then either you are doing something wrong (like using the buffer size rather than the read size) or the message protocol is very ill defined. If the second then you will have to develope a fuzzy algorithm to guess at the correct behavior.

Maybe you are looking for

  • How do i back up my iphone to an external hard drive and not my computer

    How do I back up my iphone to an external hard drive attached to my pc and not my pc?  My disk on my pc is almost full and even though I selected the external hard drive it still seems to try to back it up to my computer, then says I don't have suffi

  • Inherit metadata not working when content is moved from one folder to another

    Hi All, I have a unique situation for which i would like to know if there is any solution. We have WebCenter Content 11.1.1.8.0 installed with Framework folders, Accounts and RoleEntityACL (Access Control List-ACL) enabled. We are not using Accounts,

  • Language key not defined (CIF)

    Hi experts, currently we get an error message "Language key not defined" during the transfer of a customer from ERP to EWM (CIF - CFM1/CFM2). Therefore no business partner in EWM is created. I read something about "One-time account" (1957563 and 1975

  • Edit Display Templates missing controls

    Hi, I'm having problems working with Search Display Templates on SharePoint Online. It started when I uploaded and published two new templates. When I edit the properties of a Search Results Web Part to use these templates, they are not appearing in

  • Systems not appearing/Cannot search for systems

    Greetings, I have defined two systems that call BAPI's (via RFC) on an instance of SAP that we utilize for testing. Using Visual Composer 7.0, we were able to use the "Find Data" option to search our portal instance for systems, but this feature does