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

Similar Messages

  • How can I convert table object into table record format?

    I need to write a store procedure to convert table object into table record. The stored procedure will have a table object IN and then pass the data into another stored procedure with a table record IN. Data passed in may contain more than one record in the table object. Is there any example I can take a look? Thanks.

    I'm afraid it's a bit labourious but here's an example.
    I think it's a good idea to work with SQL objects rather than PL/SQL nested tables.
    SQL> CREATE OR REPLACE TYPE emp_t AS OBJECT
      2      (eno NUMBER(4)
      3      , ename  VARCHAR2(10)
      4      , job VARCHAR2(9)
      5      , mgr  NUMBER(4)
      6      , hiredate  DATE
      7      , sal  NUMBER(7,2)
      8      , comm  NUMBER(7,2)
      9      , deptno  NUMBER(2));
    10  /
    Type created.
    SQL> CREATE OR REPLACE TYPE staff_nt AS TABLE OF emp_t
      2  /
    Type created.
    SQL> Now we've got some Types let's use them. I've only implemented this as one public procedure but you can see the principles in action.
    SQL> CREATE OR REPLACE PACKAGE emp_utils AS
      2      TYPE EmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE;
      3      PROCEDURE pop_emp (p_emps in staff_nt);
      4  END  emp_utils;
      5  /
    Package created.
    SQL> CREATE OR REPLACE PACKAGE BODY emp_utils AS
      2      FUNCTION emp_obj_to_rows (p_emps IN staff_nt) RETURN EmpCurTyp IS
      3          rc EmpCurTyp;
      4      BEGIN
      5          OPEN rc FOR SELECT * FROM TABLE( CAST ( p_emps AS staff_nt ));
      6          RETURN rc;
      7      END  emp_obj_to_rows;
      8      PROCEDURE pop_emp (p_emps in staff_nt) is
      9          e_rec emp%ROWTYPE;
    10          l_emps EmpCurTyp;
    11      BEGIN
    12          l_emps := emp_obj_to_rows(p_emps);
    13          FETCH l_emps INTO e_rec;
    14          LOOP
    15              EXIT WHEN l_emps%NOTFOUND;
    16              INSERT INTO emp VALUES e_rec;
    17              FETCH l_emps INTO e_rec;
    18          END LOOP;
    19          CLOSE l_emps;
    20      END pop_emp;   
    21  END;
    22  /
    Package body created.
    SQL>Looks good. Let's see it in action...
    SQL> DECLARE
      2      newbies staff_nt :=  staff_nt();
      3  BEGIN
      4      newbies.extend(2);
      5      newbies(1) := emp_t(7777, 'APC', 'CODER', 7902, sysdate, 1700, null, 40);
      6      newbies(2) := emp_t(7778, 'J RANDOM', 'HACKER', 7902, sysdate, 1800, null, 40);
      7      emp_utils.pop_emp(newbies);
      8  END;
      9  /
    PL/SQL procedure successfully completed.
    SQL> SELECT * FROM emp WHERE deptno = 40
      2  /
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM
        DEPTNO
          7777 APC        CODER           7902 17-NOV-05       1700
            40
          7778 J RANDOM   HACKER          7902 17-NOV-05       1800
            40
    SQL>     Cheers, APC

  • How can i convert the object to class~~~????

    recently i develop UML drawing tool for drawing UML diagram, i now design a program structure. now i have already defined many classes that represent each shape in UML. each class stores data of the related shape. then i use a vector to store all shape as follow;
    Vector shape = new Vector();
    shape.addElement(useCase); \\useCase is a Class i defined
    shape.addElement(actor);\\actor is a Class i defined
    now i want to use all shape's methods stored in the vector before how can i do that in general ways?
    i don't want to code like this;
    Object o = shape.elementAt(a);
    if (o instanceof UseCase)
    if (o instanceof Actor)
    because i have many classed!! can u all professional help me? i am just a beginer of java programming student

    Sounds like you need to use an inheritance structure...
    Setup a generic class that contains methods (probably blank) which each class (such as actor, useCase) will inherit from. Then make actor/useCase inherit from this base class and provide specific code in each of the general methods.
    Then when you retrieve your object from the class, you can cast it as your generic class and access the general methods without caring what the actual class is.
    Eg. Basic class "shape". has empty methods "draw" and "setPosition". Class "circle" and "square" both extend "shape" and provide specific implementations of setPosition and draw methods. You can then cast them as class type shape and do draw() and setPosition methods without caring about what type the object actually is.

  • How can you convert a live RTMP stream to RTMFP and vice versa in flash?

    Assume three computers: A, B, and C. A is streaming live video and audio to B through RTMP. How could that stream be converted to RTMFP and sent through B to C - while at the same time, still going to B as RTMP? How could a live stream from C be similarly sent to B as RTMFP and A as RTMP?
    It doesn't matter to me whether B converts it on the client side, or whether the FMS between A and B convert it. Part of the problem is that B can get streams to and from both A and C, but A and C are effectively disconnected from each other. Another part of the problem is that A has to be able to use RTMP, not necessarily RTMFP, whereas C is guaranteed to use RTMFP. All three clients still need to be able to connect to each other in a live video chat.
    Thanks!

    you don't have to completely redo your project but you will probably need to redo large parts of it.  in addition, there's no quick way of doing what you want and ensuring everything will work well unless you dig into the details of publishing for mobiles.
    it looks like your swf's background is transparent.  you assigned the wmode attribute in your embedding code to be transparent.

  • How can I convert an array off byte into an Object ?

    Hi folks...
    I�m developing an application that comunicates a PDA and a computer via Wi-Fi. I�m using a DataStream ( Input and Output ) to receive / send information from / to the computer. Most off the data received from him is in the byte[] type...
    How can I convert an array off byte ( byte[] ) into an Object using MIDP 2.0 / CLDC 1.1 ?
    I found on the web 2 functions that made this... but it uses a ObjectOutputStream and ObjectInputStream classes that is not provided by the J2ME plataform...
    How can I do this ?
    Waiting answers
    Rodrigo Kerkhoff

    There are no ObjectOutputStream and ObjectInputStream classes in CLDC. You must know what you are writing to and reading from the DataStream. You should write the primitives like int, String to the DataOutputstream at one end and read those in exactly the same sequence at the outher end using readInt(), readUTF() methods.

  • How can I convert DVD- video into Apple's format so that it can be played and streamed from my Mac?

    How can I convert DVD- video into Apple's format so that I can play the content on my Mac and also stream it to my Apple TV? A few years ago, I transferred all of my home videos onto DVD but now would really like to put these onto my Mac and stream them through Apple TV to watch on the "big screen". Any advice would be most welcome!! Thanks

    MPEG Streamclip.
    Apple do not have their "own" format. You need to convert your DVDs to H.264 though.

  • How can I convert stream to byte and byte to stream

    I got a IInputStream from BackgroundDownloader operation, how can I convert it to byte array? I try to convert it to buffer and after that to bytes, but it's always throw exception.
    function decryptStream(inputStream, totalBytes) {
    var reader = new Windows.Storage.Streams.DataReader(inputStream);
    var iBuffer = reader.readBuffer(totalBytes);
    var bytes = Windows.Security.Cryptography.CryptographicBuffer.copyToByteArray(iBuffer);
    Could I have examples about that?

    Hi Jeft,
    In my program, I have a BackgroundDownloader to download an image. When we have result, I will convert it to bytes array.
    if (p.hasResponseChanged && imageStream == null) {
    imageStream = operation.getResultStreamAt(0);
    if (!p.hasResponseChanged && imageStream != null) {
    decryptStream(imageStream, p['bytesReceived']);

  • How can I convert a layer into a smart object with Adobe Photoshop Elements 10?

    How can I convert a layer into a smart object with Adobe Photoshop Elements 10?

    That feature is only in PS. Elements as you buy it has only limited support for smart objects. If you use File>Place to add something to your image it will come in as a smart object (within the limits to which PSE understands smart layers). However, if you know someone who can write an action for you in PS you can install it in PSE, or you could look into something like elements+ from simplephotoshop.com.

  • How can I convert  an ArrayList to a String[]

    Hi,
    How can I convert an ArrayList (only with strings) to a String[] ?
    I've tried this :
         public static String listToString(List l) {
              StringBuffer sb = new StringBuffer();
              Iterator iter = l.iterator();
              while (iter.hasNext()) {
                   sb.append(iter.next().toString());
                   if (iter.hasNext()) {
                        sb.append(',');
              return sb.toString();
    But what I get is an array of xxxxx@435634 (for example).
    Thanks a lot !

    Strings are Objects but not all Objects are Strings and at least one of the elements in your List is not a String.

  • How can I convert a pages color document to a PDF Black and White doc.

    How can I convert a pages color document to a PDF Black and White doc.  Or, covert the color to B&W in a new doc?

    > How can I convert a pages color document to a PDF Black and White doc.  Or, covert the color to B&W in a new doc?
    The general idea is that you colour correct photographs once, archive, and convert with or without colour changes. The archived photograph is unchanged - or we would be colour correcting the same photographs again and again and again.
    If you have a photograph with a corrected exposure, you can open the photograph in the Apple ColorSync Utility, apply a colour space conversion to a grayscale appearance using the preinstalled ICC profile, save the photograph under another name, and place that in your pagination.
    If you have a paginated document with corrected exposures, and any such non-scalable bitmap or scalable spline graphics as you have chosen to add, you can render the pagination as a whole to PDF through the same ICC profile, carrying out the same colour space conversion on any and all objects.
    Caveat: If you intend the pagination for certain processes, in particular offset lithography, then you are probably  expected not to render the type to grayscale, but rather to render it to single ink solid black. No software can determine what printing process you intend, you have to understand a bit about printing, and how to set up general colour space conversions in software. Ask your prepress provider, and if the answer is not prompt and proficient, pick another provider.
    /hh

  • How can I convert the variable expression stored as string back to variable expression

    How can I convert the variable expression stored as string back to variable expression?
    I am storing the expression enterd in the TSExpresssionEditControl as simple string and want to convert back to expression since I want to get the data type of that expression.

    pritam,
    I'm not sure what you're trying to do exactly. If you are trying to get the value of a variable and you only have the name of value in a string, then you can use Evaluate() to get its value. If you want the data type, my advise is to use the GetPropertyObject() API method and just pass in the loop up string. Then you'll have a handle to the data object and then proceed from there.
    Regards,
    Song D
    Application Engineer
    National Instrument
    Regards,
    Song Du
    Systems Software
    National Instruments R&D

  • How can I write new objects to the existing file with already written objec

    Hi,
    I've got a problem in my app.
    Namely, my app stores data as objects written to the files. Everything is OK, when I write some data (objects of a class defined by me) to the file (by using writeObject method from ObjectOutputStream) and then I'm reading it sequencially by the corresponding readObject method (from ObjectInputStream).
    Problems start when I add new objects to the already existing file (to the end of this file). Then, when I'm trying to read newly written data, I get an exception:
    java.io.StreamCorruptedException
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.readObject(Unknown Source)
    Is there any method to avoid corrupting the stream? Maybe it is a silly problem, but I really can't cope with it! How can I write new objects to the existing file with already written objects?
    If anyone of you know something about this issue, please help!
    Jai

    Here is a piece of sample codes. You can save the bytes read from the object by invoking save(byte[] b), and load the last inserted object by invoking load.
    * Created on 2004-12-23
    package com.cpic.msgbus.monitor.util.cachequeue;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.RandomAccessFile;
    * @author elgs This is a very high performance implemention of Cache.
    public class StackCache implements Cache
        protected long             seed    = 0;
        protected RandomAccessFile raf;
        protected int              count;
        protected String           cacheDeviceName;
        protected Adapter          adapter;
        protected long             pointer = 0;
        protected File             f;
        public StackCache(String name) throws IOException
            cacheDeviceName = name;
            f = new File(Const.cacheHome + name);
            raf = new RandomAccessFile(f, "rw");
            if (raf.length() == 0)
                raf.writeLong(0L);
         * Whne the cache file is getting large in size and may there be fragments,
         * we should do a shrink.
        public synchronized void shrink() throws IOException
            int BUF = 8192;
            long pointer = getPointer();
            long size = pointer + 4;
            File temp = new File(Const.cacheHome + getCacheDeviceName() + ".shrink");
            FileInputStream in = new FileInputStream(f);
            FileOutputStream out = new FileOutputStream(temp);
            byte[] buf = new byte[BUF];
            long runs = size / BUF;
            int mode = (int) size % BUF;
            for (long l = 0; l < runs; ++l)
                in.read(buf);
                out.write(buf);
            in.read(buf, 0, mode);
            out.write(buf, 0, mode);
            out.flush();
            out.close();
            in.close();
            raf.close();
            f.delete();
            temp.renameTo(f);
            raf = new RandomAccessFile(f, "rw");
        private synchronized long getPointer() throws IOException
            long l = raf.getFilePointer();
            raf.seek(0);
            long pointer = raf.readLong();
            raf.seek(l);
            return pointer < 8 ? 4 : pointer;
         * (non-Javadoc)
         * @see com.cpic.msgbus.monitor.util.cachequeue.Cache#load()
        public synchronized byte[] load() throws IOException
            pointer = getPointer();
            if (pointer < 8)
                return null;
            raf.seek(pointer);
            int length = raf.readInt();
            pointer = pointer - length - 4;
            raf.seek(0);
            raf.writeLong(pointer);
            byte[] b = new byte[length];
            raf.seek(pointer + 4);
            raf.read(b);
            --count;
            return b;
         * (non-Javadoc)
         * @see com.cpic.msgbus.monitor.util.cachequeue.Cache#save(byte[])
        public synchronized void save(byte[] b) throws IOException
            pointer = getPointer();
            int length = b.length;
            pointer += 4;
            raf.seek(pointer);
            raf.write(b);
            raf.writeInt(length);
            pointer = raf.getFilePointer() - 4;
            raf.seek(0);
            raf.writeLong(pointer);
            ++count;
         * (non-Javadoc)
         * @see com.cpic.msgbus.monitor.util.cachequeue.Cache#getCachedObjectsCount()
        public synchronized int getCachedObjectsCount()
            return count;
         * (non-Javadoc)
         * @see com.cpic.msgbus.monitor.util.cachequeue.Cache#getCacheDeviceName()
        public String getCacheDeviceName()
            return cacheDeviceName;
    }

  • How can I convert an int to a string?

    Hi
    How can I convert an int to a string?
    /ad87geao

    Here is some the code:
    public class GUI
        extends Applet {
      public GUI() { 
        lastValue = 5;
        String temp = Integer.toString(lastValue);
        System.out.println(temp);
        showText(temp);
      private void showText(final String text) {
        SwingUtilities.invokeLater(new Runnable() {
          public void run() {
            tArea2.setText(text + "\n");
    }

  • How can I convert an InputStream to a FileInputStream ???

    How can I convert an InputStream to a FileInputStream ???

    Thanks for you reply, however, I am still stuck.
    I am trying to convert my application (which runs smoothly) to a signed applet. The following is the original (application) code:
    private void loadConfig() {
    String fileName = "resources/groupconfig";
    File name = new File(fileName);
    if(name.isFile()) {
    try {
         ObjectInputStream in = new ObjectInputStream(new FileInputStream(fileName));
         pAndGConfig = (PAGroupsConfig)in.readObject();
         in.close();
         return;
    } catch(ClassNotFoundException e) {
         System.err.println("++ERROR: "+e);
    } catch(IOException e) {
         System.err.println("++ERROR: "+e);
    System.out.println("Can't find file: " + fileName);
    Because all code and resources now reside in a Jar file (for the signed applet), I must use the following line to access the resources:
    InputStream is = this.getClass().getResourceAsStream(fileName);
    I then need to convert the 'InputStream' to 'ObjectInputStream' or 'FileInputStream' so that I can work with it.
    I would be very grateful if you could help shed some light on the matter - Cobram

  • How can I convert an OVM vm (.img) to VDI (virtualbox)?

    Hi,
    how can I convert an OVM vm (.img) to VDI (virtualbox)?
    Is .img format a raw image? If yes can I use "VBoxManage convertdd" to convert from .img to vdi?
    tnx & regards,
    S.

    Hi,
    "VBoxManage convertdd" solved.
    Regards,
    S.

Maybe you are looking for