Convert a string to its unicode representation

how can I convert characters such as "ащщ"
to their unicode numbers (1072,1097,1097)? I know it's gotta be so
easy, but it's going over my head.

ogre11 wrote:
> when I give any Cyrillic character to a cf function it
gets converted into a
> question mark at some point before the function runs so
asc returns 63 on all
> cyrillic characters
encoding issue. where's the data coming from? if db, which
one? what driver? is
the data really unicode?
do you have a simple example showing the problem?

Similar Messages

  • Unicode representation

    Hi,
    I `m new in JAVA programming and I would like to know, how can I get the Unicode representation (Hexadecimal number of length 4) of a character.
    e.g. Given '0' as an input, the output should be 0030.

    Thanks but I was looking for a function or something which takes a chaarcter as an input and returns its unicode representation. You see I want to encode a text. If anybody has some idea please share it with me
    Thank You

  • Converting non-English characters to their unicode representation

    I have series of files/templates where each contains a locale specific language such as Chinese, Japanese or German. I need to find out how do I get their unicode representations so I can send as html formatted email?
    I can already send one for the English template as html formatted email w/out a problem. I was able to find a sample of unicode representation of Japanese and send that as a test. But how do I get the temaplates that I have and convert their contents into unicode?
    Thanks in advance.
    please dis-regard. I figured it out.
    chehrehk

    You need to know what character encoding was used for the template text.
    For example, you could have Japanese text encoded using UTF-8 or
    encoded using ISO-2022-JP and the same Japanese characters would
    be represented as a different sequence of bytes. Without knowing which
    charset was used, you won't be able to convert the byte sequence back
    into Unicode characters (e.g., to store in a Java String).
    If you do know which charset was used, java.io.Reader will convert the
    byte stream into Unicode characters.
    If the charset information is not available, there are heuristics that you
    can use to try to guess the correct charset, but by their nature they're
    going to be wrong sometimes.

  • Converting a hex String to its corresponding hex value...?

    Yeah, I'm having quite a bit of fun guessing this one... :p
    I have a string of n characters and have used Integer.toHexString( ( int )str.charAt( i ) ) to convert each character to a string representing its hex value. Now I need to USE that value for bit-wise operations, like, say, applying the AND, OR, etc. operators...
    Example:
    hexvalue &= 0xC000FFFF; //the second value is the one extracted from the string;
    How can achieve this...? Any help is greatly appreciated... :}

    Since a Java char is numerically a Java short, you can apply bitwise operators to chars directly - the conversion to hex simply changes the way that the char is viewed; the result can also be viewed as a number in other bases.
    For instance, the char 'A' can be also be represented as any of the following values:
    binary - 1000001
    octal - 101
    decimal - 65
    hex - 41
    Likewise, 'Z' can also be viewed as
    binary - 1011010
    octal - 132
    decimal - 90
    hex - 5A
    "Anding" the letter 'A' with 'Z' ('A' & 'Z') or doing the same using any of the other representations will result in (binary 1000000, octal 100, decimal 64, or hex 40) - the bit pattern is the same, only the representation of the result varies.

  • Converting Hex string to unicode

    I am reading in a hex representation of Unicode characters as a string.(for example: 004100200042)
    I want to convert the string from hex to unicode, and write the corresponding characters to a file. The output should look like follow:
    A B (0041 = Capital A, 0020 = space, 0042 = Capital B)
    Could you please assist?

    Problem solved, no need to look into it. Thank you

  • Unicode: Is it Possible to convert a string, or text, for Output?

    Can you take a string (or text) in Unicode (4 bytes each character),  and by using its string (or text), as input it to a Function Module, or Method, have the string's hex values converted into the old non-unicode value (2 bytes each character) to send to an external system?   
    I wish it were this easy, but am finding out it is not. Seems like whenever I run  a process to convert a field (4 bytes) in the new unicode system, to old non-unicode (2 bytes each), and move it back into a field in the unicode system, it automatically  converts it back to 4 bytes automatically?
    It is causing issues on the external tergat system that is not using unicode.
         Thank-You.

    Not that I know of. But you could convert your text to RAW or XSTRING, and send that value to the external system.
    Jan

  • Converting a string to Class object and calling its method

    I have recently moved to Java and I need help on this specific issue given below.
    I have to do this :
    ValModule1 val1 = new ValModule1();
    ValModule2 val2 = new ValModule2();
    if(val1.checkModule(xmlDocument)){
    $i++;
    There are many ValModule* classes and they all have the method called checkModule in them. I need to instantiate each class and run the checkMethod which returns true or false. My problem is that I am trying to get the name of the module (if it is ValModule1 or 2 or 3) from the user. What I get from the user is the name of the class for which I should call checkModule method on.
    how can I convert this string validationname given by the user and instantiate that class and call the method?
    I have tried this:
    String str="c:/xpathtest/src/Plugin_Config.xml";
    File xmlDocument = new File(str);
    String cls = "ValModule1"; // assuming this is what the user gave me
    Class t = Class.forName("ValModule1");
    Object o = t.newInstance();
    After that if I try
    if(o.checkModule(xmlDocument)){
    $i++;
    It gives me an error saying that it is not an existing method
    cannot resolve symbol
    [javac] symbol : method checkModule (java.io.File)
    [javac] location: class java.lang.Object
    [javac] if(o.checkModule(xmlDocument)){
    [javac] ^
    [javac] 1 error
    Can you please let me know where I am screwing up :-) ? If you need me to put both the programs I can do that too. Thanks in Anticipation

    I have recently moved to Java and I need help on this
    specific issue given below.
    I have to do this :
    ValModule1 val1 = new ValModule1();
    ValModule2 val2 = new ValModule2();
    if(val1.checkModule(xmlDocument)){
    $i++;
    There are many ValModule* classes and they all have
    the method called checkModule in them. I need to
    instantiate each class and run the checkMethod which
    returns true or false. My problem is that I am trying
    to get the name of the module (if it is ValModule1 or
    2 or 3) from the user. What I get from the user is
    the name of the class for which I should call
    checkModule method on.
    how can I convert this string validationname given by
    the user and instantiate that class and call the
    method?
    Define an interface containing the method all your classes have in common, cast the Object reference returned by newInstance to that interface, then you can call that method.
    Good Luck
    Lee

  • Problem in converting the String to Date with time zone GMT

    Hi,
    When I tried to convert the string 12/05/2009 to Date, the time zone is set to BST.On the other hand, for the date 12/12/2009, the time zone is set to GMT. What should I do to get the time zone as GMT all the time.?
    SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
    String dateString = "12/05/2009";
    System.out.println(myDate.toString());

    I think you are all missing the point. java.util.Date objects always alway always store the date as the number of milliseconds since 1/1/1970 UTC so the only TimeZone they have its the implicit UTC. When you use the Date.toString() method the toString() method gets the default time zone from your environment and formats the data accordingly. This means that the same Date object will, by default, produce a different result for France and Australia and the US.
    So, if you have the date "12/5/2009" as a String then to convert it to a java.util.Date you must specify what TimeZone is implied. If it is your system time zone then you can just create a SimpleDateFormat object with the correct format and then use the parse() method to create the java.util.Date object and this will automatically be converted to UTC. If the date String represents some other time zone then you must explicitly set the time zone of the SimpleDateFormat object before parsing the string.
    The same approach applies when converting a java.util.Date object to a String. If you want anything other than your system time zone then you must explicitly tell the SimpleDateFormat what time zone you want the result formatted for.

  • Convert from String to Int

    Hi,
    I have a question.
    How do I convert from String to Integer?
    Here is my code:
    try{
    String s="000111010101001101101010";
    int q=Integer.parseInt(s);
    answerStr = String.valueOf(q);
    catch (NumberFormatException e)
    answerStr="Error";
    but, everytime when i run the code, i always get the ERROR.
    is the value that i got, cannot be converted to int?
    i've done the same thing in c, and its working fine.
    thanks..

    6kyAngel wrote:
    actually it convert the string value into decimal value.In fact what it does is convert the (binary) string into an integer value. It's the String representation of integer quantities that have a base (two, ten, hex etc): the quantities themselves don't have a base.
    To take an integer quantity (in the form of an int) and convert it to a binary String, use the handy toString() method in the Integer class - like your other conversion, use the one that takes a radix argument.

  • Transform string to a unicode

    Hello all,
    I want to know how can we transform a string to a 16-bit unicode, please?
    ( i want to transform a string to look like "\u062a\u0635\u0628\u062d "
    and then store it in a string variable to use it).
    can you give me the code?
    it's urgent

    your right that I asked how to turn a String into UNICODE
    and if you noticed my code you will find that I used the code that turn a string retrieved from database into unicode then store in a PDF file,but my problem here is when I tried to store these data in the PDF File, it stored as it is, I mean it stored the unicode string as it is (string) not convert it to the equivalent character as in the following example.
    I used this way (turn a String into UNICODE) because I found an example of how to put data written in a language other than english in a PDF file.
    this is the example:
    import java.awt.Color;
    import java.io.FileOutputStream;
    import com.lowagie.text.Chunk;
    import com.lowagie.text.Document;
    import com.lowagie.text.Element;
    import com.lowagie.text.Font;
    import com.lowagie.text.PageSize;
    import com.lowagie.text.Phrase;
    import com.lowagie.text.pdf.BaseFont;
    import com.lowagie.text.pdf.ColumnText;
    import com.lowagie.text.pdf.PdfContentByte;
    import com.lowagie.text.pdf.PdfPCell;
    import com.lowagie.text.pdf.PdfPTable;
    import com.lowagie.text.pdf.PdfWriter;
    * Writing RTL text such as Arabic or Hebrew.
    public class RightToLeft {
    * Writing RTL text such as Arabic or Hebrew.
    * @param args no arguments needed
    public static void main(String[] args) {
    try {
         // step 1
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    // step 2
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("righttoleft.pdf"));
    // step 3
    document.open();
    // step 4
    PdfContentByte cb = writer.getDirectContent();
    BaseFont bf = BaseFont.createFont("c:\\windows\\fonts\\times.ttf", BaseFont.IDENTITY_H, true);
    Font f2 = new Font(bf, 24, Font.NORMAL, Color.BLUE);
    float llx = 100;
    float lly = 100;
    float urx = 500;
    float ury = 800;
    ColumnText ct = new ColumnText(cb);
    ct.setSimpleColumn(llx, lly, urx, ury, 24, Element.ALIGN_LEFT);
    ct.setSpaceCharRatio(PdfWriter.NO_SPACE_CHAR_RATIO);
    ct.setLeading(0, 1);
    ct.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
    ct.setAlignment(Element.ALIGN_CENTER);
    ct.addText(new Chunk(ar1, new Font(bf, 16)));
    ct.addText(new Chunk(ar2, new Font(bf, 16, Font.NORMAL, Color.red)));
    ct.go();
    ct.setAlignment(Element.ALIGN_JUSTIFIED);
    ct.addText(new Chunk(ar3, new Font(bf, 12)));
    ct.go();
    ct.setAlignment(Element.ALIGN_CENTER);
    ct.addText(new Chunk(ar4, new Font(bf, 14)));
    ct.go();
    ct.setSpaceCharRatio(PdfWriter.SPACE_CHAR_RATIO_DEFAULT);
    ct.setAlignment(Element.ALIGN_CENTER);
    ct.addText(new Chunk("\n\n\n", new Font(bf, 16)));
    ct.addText(new Chunk(he1, new Font(bf, 16)));
    ct.addText(new Chunk(he2, new Font(bf, 16, Font.NORMAL, Color.red)));
    ct.go();
    ct.setAlignment(Element.ALIGN_JUSTIFIED);
    ct.addText(new Chunk(he3, new Font(bf, 12)));
    ct.go();
    ct.setAlignment(Element.ALIGN_CENTER);
    ct.addText(new Chunk(he4, new Font(bf, 14)));
    ct.go();
    document.newPage();
    String atext = "\u062a\u0635\u0628\u062d ";
    PdfPTable table = new PdfPTable(5);
    table.setWidthPercentage(100);
    table.setRunDirection(PdfWriter.RUN_DIRECTION_NO_BIDI);
    for (int k = 0; k < 5; ++k) {
    PdfPCell cell = new PdfPCell(new Phrase(10, atext + k, f2));
    if (k == 2) {
    cell.setColspan(2);
    ++k;
    table.addCell(cell);
    table.setRunDirection(PdfWriter.RUN_DIRECTION_LTR);
    for (int k = 0; k < 5; ++k) {
    PdfPCell cell = new PdfPCell(new Phrase(10, atext + k, f2));
    if (k == 2) {
    cell.setColspan(2);
    ++k;
    table.addCell(cell);
    table.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
    for (int k = 0; k < 5; ++k) {
    PdfPCell cell = new PdfPCell(new Phrase(10, atext + k, f2));
    if (k == 2) {
    cell.setColspan(2);
    ++k;
    table.addCell(cell);
    document.add(table);
    // step 5
    document.close();
    catch (Exception e) {
    e.printStackTrace();
    /** arabic text */
    public static String ar1 = "\u0623\u0648\u0631\u0648\u0628\u0627, \u0628\u0631\u0645\u062c\u064a\u0627\u062a \u0627\u0644\u062d\u0627\u0633\u0648\u0628 + \u0627\u0646\u062a\u0631\u0646\u064a\u062a :\n\n";
    /** arabic text */
    public static String ar2 = "\u062a\u0635\u0628\u062d \u0639\u0627\u0644\u0645\u064a\u0627 \u0645\u0639 \u064a\u0648\u0646\u064a\u0643\u0648\u062f\n\n";
    /** arabic text */
    public static String ar3 = "\u062a\u0633\u062c\u0651\u0644 \u0627\u0644\u0622\u0646 \u0644\u062d\u0636\u0648\u0631 \u0627\u0644\u0645\u0624\u062a\u0645\u0631 \u0627\u0644\u062f\u0648\u0644\u064a " +
    "\u0627\u0644\u0639\u0627\u0634\u0631 \u0644\u064a\u0648\u0646\u064a\u0643\u0648\u062f, \u0627\u0644\u0630\u064a \u0633\u064a\u0639\u0642\u062f \u0641\u064a 10-12 \u0622\u0630\u0627\u0631 1997 " +
    "\u0628\u0645\u062f\u064a\u0646\u0629 \u0645\u0627\u064a\u0646\u062a\u0633, \u0623\u0644\u0645\u0627\u0646\u064a\u0627. \u0648\u0633\u064a\u062c\u0645\u0639 \u0627\u0644\u0645\u0624\u062a\u0645\u0631 " +
    "\u0628\u064a\u0646 \u062e\u0628\u0631\u0627\u0621 \u0645\u0646 \u0643\u0627\u0641\u0629 \u0642\u0637\u0627\u0639\u0627\u062a \u0627\u0644\u0635\u0646\u0627\u0639\u0629 \u0639\u0644\u0649 " +
    "\u0627\u0644\u0634\u0628\u0643\u0629 \u0627\u0644\u0639\u0627\u0644\u0645\u064a\u0629 \u0627\u0646\u062a\u0631\u0646\u064a\u062a \u0648\u064a\u0648\u0646\u064a\u0643\u0648\u062f, \u062d\u064a\u062b " +
    "\u0633\u062a\u062a\u0645, \u0639\u0644\u0649 \u0627\u0644\u0635\u0639\u064a\u062f\u064a\u0646 \u0627\u0644\u062f\u0648\u0644\u064a \u0648\u0627\u0644\u0645\u062d\u0644\u064a \u0639\u0644\u0649 " +
    "\u062d\u062f \u0633\u0648\u0627\u0621 \u0645\u0646\u0627\u0642\u0634\u0629 \u0633\u0628\u0644 \u0627\u0633\u062a\u062e\u062f\u0627\u0645 \u064a\u0648\u0646\u0643\u0648\u062f \u0641\u064a " +
    "\u0627\u0644\u0646\u0638\u0645 \u0627\u0644\u0642\u0627\u0626\u0645\u0629 \u0648\u0641\u064a\u0645\u0627 \u064a\u062e\u0635 \u0627\u0644\u062a\u0637\u0628\u064a\u0642\u0627\u062a " +
    "\u0627\u0644\u062d\u0627\u0633\u0648\u0628\u064a\u0629, \u0627\u0644\u062e\u0637\u0648\u0637, \u062a\u0635\u0645\u064a\u0645 \u0627\u0644\u0646\u0635\u0648\u0635 \u0648\u0627\u0644\u062d\u0648\u0633\u0628\u0629 " +
    "\u0645\u062a\u0639\u062f\u062f\u0629 \u0627\u0644\u0644\u063a\u0627\u062a.\n\n";
    /** arabic text */
    public static String ar4 = "\u0639\u0646\u062f\u0645\u0627 \u064a\u0631\u064a\u062f \u0627\u0644\u0639\u0627\u0644\u0645 \u0623\u0646 \u064a\u062a\u0643\u0644\u0651\u0645, \u0641\u0647\u0648 \u064a\u062a\u062d\u062f\u0651\u062b \u0628\u0644\u063a\u0629 \u064a\u0648\u0646\u064a\u0643\u0648\u062f\n\n";
    /** hebrew text */
    public static String he1 = "\u05d0\u05d9\u05e8\u05d5\u05e4\u05d4, \u05ea\u05d5\u05db\u05e0\u05d4 \u05d5\u05d4\u05d0\u05d9\u05e0\u05d8\u05e8\u05e0\u05d8:\n\n";
    /** hebrew text */
    public static String he2 = "Unicode \u05d9\u05d5\u05e6\u05d0 \u05dc\u05e9\u05d5\u05e7 \u05d4\u05e2\u05d5\u05dc\u05de\u05d9\n\n";
    /** hebrew text */
    public static String he3 = "\u05d4\u05d9\u05e8\u05e9\u05de\u05d5 \u05db\u05e2\u05ea \u05dc\u05db\u05e0\u05e1 Unicode \u05d4\u05d1\u05d9\u05e0\u05dc\u05d0\u05d5\u05de\u05d9 \u05d4\u05e2\u05e9\u05d9\u05e8\u05d9, \u05e9\u05d9\u05d9\u05e2\u05e8\u05da \u05d1\u05d9\u05df \u05d4\u05ea\u05d0\u05e8\u05d9\u05db\u05d9\u05dd " +
    "12\u05be10 \u05d1\u05de\u05e8\u05e5 1997, \u05d1\u05de\u05d9\u05d9\u05e0\u05e5 \u05e9\u05d1\u05d2\u05e8\u05de\u05e0\u05d9\u05d4. \u05d1\u05db\u05e0\u05e1 \u05d9\u05e9\u05ea\u05ea\u05e4\u05d5 \u05de\u05d5\u05de\u05d7\u05d9\u05dd \u05de\u05db\u05dc \u05e2\u05e0\u05e4\u05d9 \u05d4\u05ea\u05e2\u05e9\u05d9\u05d9\u05d4 " +
    "\u05d1\u05e0\u05d5\u05e9\u05d0 \u05d4\u05d0\u05d9\u05e0\u05d8\u05e8\u05e0\u05d8 \u05d4\u05e2\u05d5\u05dc\u05de\u05d9 \u05d5\u05d4\u05beUnicode, \u05d1\u05d4\u05ea\u05d0\u05de\u05d4 \u05dc\u05e9\u05d5\u05e7 \u05d4\u05d1\u05d9\u05e0\u05dc\u05d0\u05d5\u05de\u05d9 \u05d5\u05d4\u05de\u05e7\u05d5\u05de\u05d9, " +
    "\u05d1\u05d9\u05d9\u05e9\u05d5\u05dd Unicode \u05d1\u05de\u05e2\u05e8\u05db\u05d5\u05ea \u05d4\u05e4\u05e2\u05dc\u05d4 \u05d5\u05d1\u05d9\u05d9\u05e9\u05d5\u05de\u05d9\u05dd, \u05d1\u05d2\u05d5\u05e4\u05e0\u05d9\u05dd, \u05d1\u05e4\u05e8\u05d9\u05e1\u05ea \u05d8\u05e7\u05e1\u05d8 \u05d5\u05d1\u05de\u05d7\u05e9\u05d5\u05d1 " +
    "\u05e8\u05d1\u05be\u05dc\u05e9\u05d5\u05e0\u05d9.\n\n";
    /** hebrew text */
    public static String he4 = "\u05db\u05d0\u05e9\u05e8 \u05d4\u05e2\u05d5\u05dc\u05dd \u05e8\u05d5\u05e6\u05d4 \u05dc\u05d3\u05d1\u05e8, \u05d4\u05d5\u05d0 \u05de\u05d3\u05d1\u05e8 \u05d1\u05beUnicode\n\n";
    if you noticed this code, you will find that the data that he want to put it in a PDF file,he already know its unicode as in (ar1,ar2,ar3,.....) and when you run this code you will get a PDF file with an Arabic and hebrew language.
    that means he can convert the unicode to the equivalent character.
    but in my code that I put in the previous post does not do that.
    and this is my problem again:
    if you noticed these classes or objects :
    PdfPCell (class), table (object ), document (object)
    I used these classes from free library called (iText) if you know it.
    to help me store data that i retrieve it from database in a PDF file.
    my problem is when I used the above code as it is, it will stores the data that I retrieve it from database as "\u0030\u0039\u0061\u0041"
    and it didn't give me the equivalent word for this unicode.
    but if I changed the variable (w) in the following statement from the code:
    PdfPCell cell = new PdfPCell(new Phrase(w,f2));
    and put this string "\u0030\u0039\u0061\u0041" instead of it
    it will store the equivalent word for this unicode in the PDF file.
    what can I do now?
    and what is the problem in my code?
    is there any improvments can I do it ?
    please help
    Message was edited by:
    ahd292000

  • Converting a String to an Object

    Is there some way of converting a String (from a textfield) to an Object? What I want is something similar to the functionality offerred by a JTable. This is because I want the user to be able to input a value of any type to the textfield (e.g. String, int, boolean, etc) and get its object representation ...
    Would a simple cast do ?
    David

    dattard,
    A string is an object, when someone enters something into a JTextField, REGARDLESS of what it is (int, double, string, etc) it is stored in the string text in that text field (JTextField.getText()).
    So if someone enters in "123", its the STRING 123, not the number one hundred and twenty three... to GET the number 123, you'll need to do something like:
    int value = Integer.parseInt( myTextField.getText() );
    to have the string parsed for the value, if you want a double, same idea:
    double value = Double.parseDouble( myTextField.getText() );
    NOTE: The number wrapper classes (Integer, Double, Float, etc.) contain "parseXXXX" methods that allow you to parse a corresponding numeric value out of a String object.
    Also, when a user enters ANYTHING into a text input field of any type, its ALWAYS a String, if you want a different version of what they entered, its up to you to parse it and decide what it was.

  • Convert xml referenced entity to unicode?

    Hi,
    Anyone know how one converts all XML Referenced Entities, of the form "&#xxx;", which appear in a String object, to their unicode representation?
    For example:
    If String A contains the phrase "two letters: &#193; &#225;", I would like to get a new String which contains the phrase "two letters: � �"

    nobody71 wrote:
    I can write some code to do the conversion by parsing the string, finding each and every XML reference and then convert each to unicode... I know how to do that...Then go ahead and do it.
    but there must already be something that does this in Java's standard API/library...Actually there isn't.
    For example, when this type of XML entity reference is found in the text of an XML node, and this node is read into a java DOM object using java's API/library, there is some code somewhere which does the conversion I am inquiring about, because when I view the String representing that text, it now contains the unicode characters. So, there must be a quick and already existing way to do this.The code must exist somewhere, yes. It doesn't follow that the code must be encapsulated in a public method. It's a specialized requirement of XML parsers so there's really no need to make it available outside the parsers where it exists.
    I guess in the time it took me to write this post I could have written the converter... :-(Why do you need to do that, anyway? Why not just let an XML parser do it for you?

  • How to get a string or byte array representation of an Image/BufferedImage?

    I have a java.awt.Image object that I want to transfer to a server application (.NET) through a http post request.
    To do that I would like to encode the Image to jpeg format and convert it to a string or byte array to be able to send it in a way that the receiver application (.NET) could handle. So, I've tried to do like this.
    private void send(Image image) {
        int width = image.getWidth(null);
        int height = image.getHeight(null);
        try {
            BufferedImage buffImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
            ImageIcon imageIcon = new ImageIcon(image);
            ImageObserver observer = imageIcon.getImageObserver();
            buffImage.getGraphics().setColor(new Color(255, 255, 255));
            buffImage.getGraphics().fillRect(0, 0, width, height);
            buffImage.getGraphics().drawImage(imageIcon.getImage(), 0, 0, observer);
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            JPEGImageEncoder jpeg = JPEGCodec.createJPEGEncoder(stream);
            jpeg.encode(buffImage);
            URL url = new URL(/* my url... */);
            URLConnection connection = url.openConnection();
            String boundary = "--------" + Long.toHexString(System.currentTimeMillis());
            connection.setRequestProperty("method", "POST");
            connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
            String output = "--" + boundary + "\r\n"
                          + "Content-Disposition: form-data; name=\"myImage\"; filename=\"myFilename.jpg\"\r\n"
                          + "Content-Type: image/jpeg\r\n"
                          + "Content-Transfer-Encoding: base64\r\n\r\n"
                          + new String(stream.toByteArray())
                          + "\r\n--" + boundary + "--\r\n";
            connection.setDoOutput(true);
            connection.getOutputStream().write(output.getBytes());
            connection.connect();
        } catch {
    }This code works, but the image I get when I save it from the receiver application is distorted. The width and height is correct, but the content and colors are really weird. I tried to set different image types (first line inside the try-block), and this gave me different distorsions, but no image type gave me the correct image.
    Maybe I should say that I can display the original Image object on screen correctly.
    I also realized that the Image object is an instance of BufferedImage, so I thought I could skip the first six lines inside the try-block, but that doesn't help. This way I don't have to set the image type in the constructor, but the result still is color distorted.
    Any ideas on how to get from an Image/BufferedImage to a string or byte array representation of the image in jpeg format?

    Here you go:
      private static void send(BufferedImage image) throws Exception
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        ImageIO.write(image, "jpeg", byteArrayOutputStream);
        byte[] imageByteArray = byteArrayOutputStream.toByteArray();
        URL url = new URL("http://<host>:<port>");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setDoOutput(true);
        connection.setRequestMethod("POST");
        OutputStream outputStream = connection.getOutputStream();
        outputStream.write(imageByteArray, 0, imageByteArray.length);
        outputStream.close();
        connection.connect();
        // alternative to connect is to get & close the input stream
        // connection.getInputStream().close();
      }

  • Convert a string to JAva.sql.date..

    I am having a string with the value as follows..
    String fval="03-10-2001"..
    I am using this value in a rs.updateDate method where I need to convert it to a different format as
    2001-10-03...can anybody give me the syntax..

    You should hold dates as Date instances. But if you want to convert between Strings and Dates then you should use a DateFormat:
    String originalDateString = "31-10-2001";
    // Convert the original string to a date
    DateFormat originalDateFormat = new SimpleDateFormat("dd-MM-yyyy");
    Date date = originalDateFormat.parse(originalDateString);
    // Get a representation of the date in the new format
    DateFormat newDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    String newDateString = newDateFormat.format(date);(Excuse the quirky formatting that the Java code filter applies!)
    Hope this helps.

  • How to convert a string into a collection of KeyEvents

    I'm working on a program that must interact with a 3rd party application (closed to me, I have no access to the code or anything like that). I have been unable to send data to the program by getting its OutputStream. The only thing that has worked was using a Robot object to send individual key events (i.e. robot.keyPress(KeyEvent.VK_A);). Therefore I'm looking to convert a string (many different strings actually) into a collection of their associated KeyEvents so I can send them to the other application. Does anyone know a good way of doing it, or is anyone able to help me with using the OutputStream?
    Thank you!
    (The 3rd party application is Attachmate InfoConnect, a Unisys terminal emulation program that I have to use to access a mainframe).

    Here is a code sample.     public void checknumber(int vsize){
    int total;
    String anum;
    anum = tf2.getText();
    validnumber = true;
    lines2combine = 1;     //default (an integer)
    recs2make = 1;          //default
    try{
    lines2combine = Integer.parseInt(anum);
    catch (NumberFormatException e){
              System.out.println("Entry for lines to combine not numeric");
         validnumber = false;
         d1Title = "Data Entry Error";
         d1Txt = "For number for lines to combine;";
         d2Txt = "Enter a number.";
         doMessage();

Maybe you are looking for

  • Which tables are to be used to select all counters readings in SAP CRM 7.0?

    Hello, I need to create a request by SQ01 to extract all counter readings in the database. First I've found the table CRMD_MPK_READING but this one does not give the value of the counter. It only contains the GUID of the counters, some information ab

  • Emailing Photos in Iphoto '11 (emails prepopulating)

    how do I delete an email that is incorrect in the iphoto email application? I sent a picture to the wrong email by accident and now that email address keeps popping up when i try and type in the correct email because the two emails are very similar.

  • Recorded waveform not visible in region

    Hi. I had to re-record a backing vocal track on a song I am working on. I was experimenting with the Sample Editor on the original track and, basically destroyed it. However, the new track doesn't show a waveform in the region. It was visible while r

  • CC problem in RWB Component monitoring

    Hi people i am getting this error  in RWB component monitoring 1 communication channels have an error status0 communication channels inactive0 communication channels not providing any status information0 adapters logging communication-channel-indepen

  • Cs6 windows 8 after system refresh....installer fails to initialize

    hi i was using adobe cs6 suite on my toshiba windows 8 machine. i had a problem and refresh my pc.during the process, windows removed all my apps. after the refreshing, i am trying to install back my cs6 suite but anytime i try install i get this err