Serializing an object

hi,
is it possible to serialize a file and send it across a network, something like a ftp? i know file objects are serializable but can i just transfer them across from one program to another, via rmi? i'm trying to find another way to doing this rather than reading the data into a buffer and sending it across that way. just want to see if i can transfer the entire file in one shot.
Thanks.

Don't confuse a File object with the data in the file it refers to; there may not even be such a file. I'm assuming you want to send the contents of the file across the network? If you only want to send the file's name, then just send a String containing the name. But if you want to send the contents, then read them in and send them some way (there are many ways).

Similar Messages

  • The Proper way to go - Passing Serialized Java Objects vs. Web Services?

    The team which I am apart of in our little "community" is trying to convince some "others" (management) that we should not use web services to communicate (move large data) within the same application (allbeit a huge application spanning across many servers).
    Furthermore these "others" are trying to tell us that in this same application when two small apps. inside of this large app. are both java we should not communicate via serialized java objects but instead we should use Web Services and XML. We are trying to convince them that the simplest way is best.
    They have asked us to provide them with proof that passing serialized java objects back and forth between two smaller java applications inside of a larger one is an Industry Standard. Can anyone help either straighten my fellow workers and I out or help us convince the "others" of the proper way to go?

    When I was a consultant we always gave the client what they wanted. Even if it was the wrong choice. Suck it up.
    I'm glad I wasn't one of those customers. Although I agree that a customer is the one who decides what to do, when I pay someone for consultancy, I expect them to consult me. If they know I'm trying to do something that I shouldn't be doing, I expect a good consultant to be able to show me that there's a better way (not just tell me I'm not doing it right, mind you).
    We pass a lot of data using XML and we don't have any transmission or processing speed issues.
    Then you either have a much better network than our customer did, or we're not talking about the same amounts of data here.
    I used the JAX-RPC RI ...
    That's cool... our customer was, unfortunately, infected with Borland products, so we had to use BES. The web services on BES were run by Axis.
    How large were these messages?
    Huge... each element had about 15 attributes, so 1,200 elements would require 19,200 XML nodes (envelope not included). By comparison, the serialized messages weren't even a quarter that size. It's not just about what you send across the network; it's also the effort of parsing XML compared to desrializing Java objects. Our web service wasn't exactly the only process running at the server.
    Anyone who understand the fundamental difference between ASCII (XML) and binary (serialized) formats realizes that no web service can possibly achieve the performance of binary Java services. Why do you think that work is being put into binary web services? I'm not saying XML is never a good thing; just that it's not The Holy Grail that a lot of people are making it look like.
    http://issues.apache.org/jira/browse/AXIS-688
    Ouch.

  • Un-serializing java objects.

    Hi,
    I have a serialized java object.How can I convert it to a normal object or string object?
    Thanks
    Vivek

    Hi,
    I am not writing object into a file.I am
    just creating a objectoutputstream object.I have to
    convert it to string which i guess can be done using
    objectInputstream object .So is there any way out?
    Thanks
    vivekI'm confused by what you are trying to accomplish. An ObjectOutputStream is intended to write objects to a file. You can't convert an ObjectOutputStream to a String, they aren't related. Are you trying to write the objects to a String? I don't see the point of that.

  • Serializing & Deserializing objects through ObjectMessage

    Hi,
    I'm having trouble sending objects/instances of a class (Data) through the message queue. I also made Data to be serializable.
    public class Data implements Serializable {
    }The following are snippets of code from the Message producer side:
    objectMessage = mySess.createObjectMessage();
    MessageProducer myMsgProducer = mySess.createProducer(myQueue);
    Data e = new Data();
    objectMessage.setObject(e);
    myMsgProducer.send(objectMessage);And the following are snippets of code from the message consumer:
    public void onMessage(Message message) {
                 if(message instanceof ObjectMessage ){
             try{
                  ObjectMessage objMsg = (ObjectMessage) message;
                  Data myData = (Data)objMsg.getObject();
             catch(JMSException e){
                  System.out.println("Exception occured: " + e.toString());
    }The result of attempting to cast the objMsg to a Data is an exception thrown.
    i did noticed however, that when I was debugging the message consumer, that the byteArrayInputStream values for both message and objMsg are null meaning that the data is not being sent or received. Any help would be greatly appreciated, thanks!
    Edited by: 883631 on Sep 13, 2011 4:09 PM
    Edited by: EJP on 14/09/2011 09:22: added {noformat}{noformat} tags. Please use them.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Sorry, the exception thrown is:
    Exception occured: com.sun.messaging.jms.MessageFormatException: [C4015]: Deserialize message failed. - cause: java.lang.ClassNotFoundException: MsgSender.Data
    Sep 14, 2011 8:53:50 AM com.sun.messaging.jmq.jmsclient.ExceptionHandler logCaughtException
    WARNING: [I500]: Caught JVM Exception: java.lang.ClassNotFoundException: MsgSender.Data
    where MsgSender is the name of the project that produces the messages to the queue.
    Data is the class that is both on the sender and receiver side, and the exception is thrown as a result of casting the object message back into a type Data.
    Data myData = (Data)objMsg.getObject();
    I hope this isn't too confusing. What I'm wondering is if there are extra steps to serializing your object or if the ObjectMessage's setObject method automatically does that for you so as long as you declare your class to implement Serializable. And if that's the case, how do you deserialize it back to the original object?
    Thank you

  • How to use Java NIO to implement disk cache for serialized java objects

    Hi,
    I have a cache (implemented as hahstable etc.) that contains java objects (mostly strings) and swaps objects from runtime memory to the disk and back based on some algorithms. Currently, the reading and writing from the disk is implemented using java.io.* package i.e. fileInputstream and FileOutputStream. Essentially, I serialize the java object and write to the disk and the deserialize and give it back to the Hashtable cache.
    The performance of swapping from disk to memory is kinda slow. I have read that memory mapping would improve the performance.
    My idea is to do the following:
    Have one big file mapped to memory. I write the serialized objects to different portions of the file and then read those portions when needed. I can use the MappedByteBuffer for that but then I have the following questions. I will not store objects in the hashtable anymore.
    1. How do I delete things from the cache in the above design i.e. how do I delete portions of a mapped file?
    2. How do I serialize objects using ByteBuffers and then deserialize them? I guess this shouldn't be hard but just want to confirm.
    Do you think this is the right design or should I change? Right now using the old io package, I have a separate file for each object. When using the NIO package, I want to store all objects in a single file in different portions of the file, is that the right way to go?
    As you can see, I am beginner in memory mapped io and need help.

    Have one big file mapped to memory. I write the serialized objects to different portions of the file and then read those portions when needed. I can use the MappedByteBufferThis is a good idea, one that I have worked on. It involves quite a bit of manipulation with temporary buffers and a deep working knowledge of object serialization.
    1. How do I delete things from the cache in the above design i.e. how do I delete portions of a mapped file?The best way to handle this is do a two-step process, cutting the file into two pieces and gluing it back together where the original one is...
    2. How do I serialize objects using ByteBuffers and then deserialize them? I guess this shouldn't be hard but just want to confirm.It is hard. Wrapping the streams and making the IO work properly is not the challenge however. The hard part comes in hacking the object streams. The object input/output streams use a ClassDescriptor object which only gets written once/ read once. This shouldn't be a problem if you will read/write the entire file at once, but will bring you grief if you want random access to your objects. You will also need an indexing mechanism to support random access.
    Do you think this is the right design or should I change? Right now using the old io package, I have a separate file for each object. When using the NIO package, I want to store all objects in a single file in different portions of the file, is that the right way to go?I guess it depends on your needs. Do you require random access to objects? NIO provides some performance gains, but mostly for very large amounts of data (>10M in my experience).
    You can always write all your objects into the same file using normal io techniques and you can still generate an index and acheive random access. It might be easier...
    Good luck

  • StackOverflowError serializing POF objects

    Hi,
    I have run into an issue while attempting to store objects in the cache that results in a StackOverflowError. The situation is that I have a number of classes that reference each other so while storing one the other is serialized which in turn attempts to serialize the other. An example is as follows:
    public class DeskSerializer extends AbstractVersionedDomainEntitySerializer<DeskImpl> {
         private static final int NAME = 11;
         private static final int REGION = 12;
         private static final int COUNTRIES = 13;
         private static final int BOOKS = 14;
         private static final int DESK_ID = 15;
         @Override
         protected DeskImpl createInstance() {
              return new DeskImpl();
         public void serialize(PofWriter out, Object o) throws IOException {
              DeskImpl obj = (DeskImpl) o;
              super.serialize(out, obj);
              out.writeString(NAME, obj.getName());
              out.writeObject(REGION, obj.getRegion());
              out.writeCollection(COUNTRIES, obj.getCountries());
              out.writeCollection(BOOKS, obj.getBooks());
              out.writeLong(DESK_ID, obj.getDeskId());
              out.writeRemainder(null);
         @SuppressWarnings("unchecked")
         public Object deserialize(PofReader in) throws IOException {
              DeskImpl obj = (DeskImpl) super.deserialize(in);
              obj.setName(in.readString(NAME));
              obj.setRegion((Region) in.readObject(REGION));
              obj.setCountries((Set<Country>) in.readCollection(COUNTRIES, new HashSet<Country>()));
              obj.setBooks((Set<Book>) in.readCollection(BOOKS, new HashSet<Book>()));
              obj.setDeskId(in.readLong(DESK_ID));
              in.readRemainder();
              return obj;
    public class BookSerializer extends AbstractVersionedDomainEntitySerializer<BookImpl> {
         private static final int NAME = 11;
         private static final int PORTFOLIO_SWAPS = 12;
         private static final int DESK = 13;
         private static final int LEGAL_ENTITY = 14;
         private static final int CLIENT = 15;
         private static final int BOOK_ID = 16;
         private static final int BUSINESS_UNIT_ID = 17;
         private static final int PORTFOLIO_ID = 18;
         private static final int NM_PRTF = 19;
         private static final int BOBOOK_ID = 20;
         @Override
         protected BookImpl createInstance() {
              return new BookImpl();
         public void serialize(PofWriter out, Object o) throws IOException {
              BookImpl obj = (BookImpl) o;
              super.serialize(out, obj);
              out.writeString(NAME, obj.getName());
              //out.writeCollection(PORTFOLIO_SWAPS, obj.getPortfolioSwaps());
              out.writeObject(DESK, obj.getDesk());
              //out.writeObject(LEGAL_ENTITY, obj.getLegalEntity());
              //out.writeObject(CLIENT, obj.getClient());
              out.writeLong(BOOK_ID, obj.getBookId());
              out.writeString(BUSINESS_UNIT_ID, obj.getBusinessUnitId());
              out.writeInt(PORTFOLIO_ID, obj.getPortfolioId());
              out.writeString(NM_PRTF, obj.getNmPrtf());
              out.writeString(BOBOOK_ID, obj.getBoBookId());
              out.writeRemainder(null);
         @SuppressWarnings("unchecked")
         public Object deserialize(PofReader in) throws IOException {
              BookImpl obj = (BookImpl) super.deserialize(in);
              obj.setName(in.readString(NAME));
              //obj.setPortfolioSwaps((Set<PortfolioSwap>) in.readCollection(PORTFOLIO_SWAPS, new HashSet<PortfolioSwap>()));
              obj.setDesk((Desk) in.readObject(DESK));
              //obj.setLegalEntity((LegalEntity) in.readObject(LEGAL_ENTITY));
              //obj.setClient((Client) in.readObject(CLIENT));
              obj.setBoBookId(in.readString(BOOK_ID));
              obj.setBusinessUnitId(in.readString(BUSINESS_UNIT_ID));
              obj.setPortfolioId(in.readInt(PORTFOLIO_ID));
              obj.setNmPrtf(in.readString(NM_PRTF));
              obj.setBoBookId(in.readString(BOBOOK_ID));
              in.readRemainder();
              return obj;
    }in the above classes DeskSerializer tries to serialize a collection of Books which in turn try to serialize a Desk. This then just goes round and round until the exception is thrown.
    Is there a neat solution to this situation? I can't change the domain objects as this is a legacy system so the only thing I could come up with would be to add a set of CoherenceDomainObjects that store the keys of the objects instead of the objest themselves and deconstruct the real objects into the Coherence version on the way in and reconstruct on the way out. Any ideas?

    Hi Willy,
    the problem is that you have a circle in your object graph which you are trying to serialize.
    That needs to be broken, because POF does not support breaking the circle on its own, and you need to write custom PofSerializers for these classes which are able to deal with this problem. The problem is if you can not break the circle easily and traverse the full graph without entering into circles without recording references as you go then this is not going to be fast (this is the same reason why Java serialization is slow) or limit traversal of the graph.
    Best regards,
    Robert

  • Convert Serialized Java Objects to XML

    I have seen numerous ways that you can modify a java application to serlialize it's data as XML rather than a binary stream. Does anyone know if there are any utilities, libraries, DLLS, tools, whatever to convert an already serialized binary stream to an XML file.
    At the moment I am working on a script to do this, and it works for simple objects, but I am hitting snags as I test with more complicated class heirachies. I would love to find something that already does this for me.

    I want to read data serialized by a java program in a C++ application. I don't want to have to modify the java application, but I do want to make it's data available in other applications.
    I could modify the java app and serialize it's data in XML, but that isn't the prefered solution. :)

  • Static fields in serialized Vector objects

    just a curious question:
    If I have a Vector filled with Objects of all the same type, and the Object contains a static field, and I then Serialize the Vector, will it still give better performance than if the field wasn't static? Thanks,
    Max

    nevermind - found out the hard way that static fields won't get Serialized

  • Serializing/Deserializing Objects..Urgent !!!

    Hello Everyone,
    Out of the blue I got an exception like
    java.io.StreamCorruptedException: invalid stream header
         at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
         at java.io.ObjectInputStream.<init>(Unknown Source)
    I am implementing "Applet to Servlet communication".
    Actually i am trying to deserialize the object which was passed to the servlet.But when i read it back i am geting the above exception.
    Can anyone throw some light on it?
    Her is my code
    APPLET CODE:
    private void interactWithServlet() {
    WBObject result = null;
    try {
    // Create an object we can use to communicate with the servlet
    URL servletURL = new URL(sURL);
    URLConnection servletConnection = servletURL.openConnection();
    servletConnection.setDoOutput(true);
    servletConnection.setUseCaches(false);
    servletConnection.setRequestProperty("Content-Type", "application/octet-stream;charset=utf-8");
    ObjectOutputStream request = new ObjectOutputStream(
    new BufferedOutputStream(servletConnection.getOutputStream()));
    WBObject wbObj=m_whiteBoardComponent.getDesignPanel().getWBObject();
    int size=wbObj.getChildren().size();
    for(int i=0;i<size;i++){
    PickObject pick=(PickObject)wbObj.getChildren().get(i);
    System.out.println("the pick object name is"+pick.getName());
    int count=pick.getChildren().size();
    for(int j=0;j<count;j++){
    ItemObject item=(ItemObject)pick.getChildren().get(j);
    System.out.println("the item object name is"+item.getName());
    request.writeObject(wbObj);
    request.flush();
    request.close();
    ObjectInputStream response = new ObjectInputStream(
    new BufferedInputStream(servletConnection.getInputStream()));
    result = (WBObject)response.readObject();
    System.out.println("The object is"+(result instanceof WBObject));
    response.close();
    } catch (Exception e) {
    e.printStackTrace();
    SERVLET CODE:
    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
    IOException {
    WBObject o = null;
    ObjectInputStream inputStream = new ObjectInputStream(
    new BufferedInputStream(req.getInputStream()));
    try {
    o = (WBObject)inputStream.readObject();
    inputStream.close();
    } catch( ClassNotFoundException ex ) {
    ex.printStackTrace();
    // send response
    resp.setStatus(HttpServletResponse.SC_OK);
    resp.setContentType("application/octet-stream;charset=utf-8");
    ObjectOutputStream oos = new ObjectOutputStream(
    new BufferedOutputStream(resp.getOutputStream()));
    oos.writeObject(o);
    oos.close();
    Best Regards
    Ashish

    client
    URLConnection servletConnection = servletURL.openConnection();try
    HttpURLConnection servletConnection = (HttpURLConnection)servletURL.openConnection();server
    // send response
    resp.setStatus(HttpServletResponse.SC_OK);
    resp.setContentType("application/octet-stream;charset=utf-8");
    ObjectOutputStream oos = new ObjectOutputStream(
    new BufferedOutputStream(resp.getOutputStream()));
    oos.writeObject(o);
    oos.close();try
    // send response
    //resp.setStatus(HttpServletResponse.SC_OK);
    //resp.setContentType("application/octet-stream;charset=utf-8");
    ObjectOutputStream oos = new ObjectOutputStream(
    new BufferedOutputStream(resp.getOutputStream()));
    oos.writeObject(o);
    oos.flush();
    oos.close();

  • Serializing Java Objects to XML files

    Hi,
    We looking for SAP library which can serialize Java Objects into XML files.
    Can you point us were to find it ?
    We have found such open source library called "XStream" at the following link
    http://www.xml.com/pub/a/2004/08/18/xstream.html
    Is it allowed to use that library inside SAP released software ?
    Thanks
    Orit

    How about https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/webcontent/uuid/83f6d2fb-0c01-0010-a2ba-a2ec94ba08f4 [original link is broken] [original link is broken]? Depends on your use cases...
    Both are supported in SAP NW CE 7.1.
    HTH!
    -- Vladimir

  • Exchange XML document containing serialized DDIC objects

    Hi,
    Suppose you have an itab "z_table" with generic linetype. The table may contain any ddic structure or table.
    Furhter you want to exchange the itab "z_table" between the Systems A and B using XML.
    We are using the following code to serialize the itab "z_table" in system A:
      DATA: g_ixml TYPE REF TO if_ixml,
            g_stream_factory TYPE REF TO if_ixml_stream_factory,
            g_encoding TYPE REF TO if_ixml_encoding,
            ostream TYPE REF TO if_ixml_ostream.
      CONSTANTS: encoding TYPE string VALUE 'utf-8'.
      g_ixml = cl_ixml=>create( ).
      g_stream_factory = g_ixml->create_stream_factory( ).
      g_encoding = g_ixml->create_encoding(
        character_set = encoding
        byte_order = 0 ).
      ostream = g_stream_factory->create_ostream_xstring( string = ex_xml_string ).
      ostream->set_encoding( encoding = g_encoding ).
      CALL TRANSFORMATION id_indent
        SOURCE z_table = z_table
        RESULT XML xml_string
        OPTIONS data_refs = 'heap'
                xml_header = 'full'.
    And the following code to deserialize the itab in system B:
      CALL TRANSFORMATION id_indent
        SOURCE XML xml_string
        RESULT z_table = z_table.
    The serialization in System A creates an XML document containing <dic:z_structure> tags. If you now try to deserialize this document ("z_table")
    in System B, the deserialization fails in case z_table contains DDIC structures which are not known in system B.
    Is there any way to have the definition (e.g. type + length) of those ddic structures included in the XML document, so that
    a deserialization is possible even if the ddic structure is not known in system B? e.g. Rendered into a XML scheme, or directly as an
    attribute into the <dic:..> tag for instance?
    Any ideas are appreciated..
    Best regards,
    Georg

    Hello Raja,
    many thanks first for your answer. I tried the FM and got a table with the definition details I want.
    Unfortunately, I'm not really sure, how to continue working with the definition details. There are still some questions open:
    - How do I proficient include these table details into my xml with my original table z_table? Would it be possible to include the table details in a way, that a "call transformation" can easily deserialize my z_table with this table details?
    - How do I convert the lt_dfies table definition details back to a ddic object that I can use? Can this be done in memory only, so that I don't have to create real ddic objects on the target system?
    Many thanks and kind regards, Oliver<b></b><b></b>

  • Serializing large objects

    Dear All,
    I am trying to serialize a HashMap containing Strings as keys and and ArrayLists as values. This works fine when the number of entries is small, but does not work when the number of entries are really large, in which case an java.lang.OutOfMemoryError: Java heap space is thrown. This happens when the number of entries is about 50,000 and the total number of objects stored in the lists exceed 500,000.
    Some posts suggest that this should have been fixed in Java 1.6 but it still doesn't seem to work. Do I need to provide the "-mx" flag to get this to work, or is there another way to serialize large objects? Any thoughts welcome.
    Cheers,
    Fred

    How about implementing custom serialization (by implementing Externalizable), and writing the values as zippied entries. As keys are strings, they can be easily zipped and the array list values should be zipped. Is it possible? ...am I crazy????. Just give it a try :-)

  • Serializing unserializable objects - serious

    We are currently implementing a replacement for an existing communication infrastructure.
    Part of the service is to make remote method calls via message oriented middleware. Unfortunately some of the parameters of these methods are not serializable, and we cannot change these classes.
    Is there any way (i.e. API, product) to marshal these objects to a byte array?

    When you say that you can't change the class, does this mean that you cannot extend it either?

  • Urgent: Problem serializing server objects

    hi there
    i have deployed an application in jboss. it uses instances of javax.media.rtp.RTPManager which is not serializable. now jboss requires each in-memory object to be Serializable. and i have to accomplish the transmission task on server side. so whats the solution? because trying these objects to serialize server throws NotSerializableException
    thanx in advance
    ra4a

    Maybe you can define:
    Class MyRTPManager extends javax.media.rtp.RTPManager implements Serializable {
    You can have this empty definition and then replace all RTPManager with myRTPManager.
    PC

  • Serializing Connection Object ???

    hi,
    i wanna serialize a sun.jdbc.odbc.JdbcOdbcConnection object but it cant be .. as the exception says
    java.io.NotSerializableException: sun.jdbc.odbc.JdbcOdbcConnection
    Now my problem is that i m having 15 classes which are accessing to the same dataBase but different 15 tables .. and each class is creating a new connection object. I want any way through which instead of having 15 connection objects .. all classes access the one connetion object
    I m using JFrames and Access DBase ... plus 5 workstations will be using this application

    i have developed an application that will be used for data entry from 5 network terminals . ...
    The application is having 15 clases that are hitting the database to retrive data from 15 diffrerent tables .. so they are creating 15 connection objects ..
    Though its working fine but i was thinking to use the ONE CONNECTION object for all these clasess
    But the most serious issue i m facing now is the
    EXCEPTION_ACCESS_VIOLATION which i have also posted in the forum to find the remedy

  • Can any boby send me a snippet of code telling mw how to "store serialized java object in iplanet directory services

     

    You will find everything you need to know including code samples in the JNDI Tutorial :
    http://java.sun.com/products/jndi/tutorial/objects/index.html
    Regards,
    Ludovic.

Maybe you are looking for

  • I HAVE SEVERAL IPHOTO LIBRARIES

    Hi, I am not sure how i accomplished this but I have several iphoto libraries on my computer. On my desktop i have iphoto library and iphoto library 1 then in my pictures folder i have iphoto library 10.10.06. I believe the last is a rebuilt library

  • S-Video to Digital TVA RCA ports

    I have a V5000 3 yr old Compaq Presario notebook and I am trying to connect a 4 pin S video cable (with an audio line) from the notebook s-video jack to the RCA ports on a sony digital TV.  The sound comes through, but no picture.  When I hit functio

  • Tnsping issues for oracle 10g standby setup

    Hi All, i'm setting up standby database, i'm getting below error while doing tnsping after made all the necessary entries in listene.ora and tnsnames.ora, in both server listener is up and running. Please suggest me on this to resolve the issue, Prim

  • Create folders and navigate through server folder structure in Linux

    Hello, I want to know if there are any examples on how to reate folders and navigate through server folder structure in Linux OS. I currently can navigate trough Windows, but need to be able to do it in Linux, by using a GUI for it. Any suggestions?

  • Updating Microsoft Office using ARD's Send UNIX Command

    Is there a command similar to "softwareupdate -i -a" that can be sent via ARD to all Mac to run Microsoft AutoUpdate to update Microsoft Office 2004. And if not, is Microsoft planning to fix that in Office 2008. Having to run to all the Mac to update