Attributes in a Serializable object in a file

Hello,
I have an application that stores a Serializable object into a file, but when I edit the file I can see the attributes from the stored object. And I thought that when you do that the stored data where bytes, instead of strings.
Can somebody explain me how can I store an object into a file that cannot be shown the content?
Here is my code:
String fichero_datos = "D:\\workspace2\\Cliente\\Datos.dat"; //That is the file
Cliente elCliente = new Cliente ("Fulanito"); //That is the object that stores a String
FileOutputStream fo = new FileOutputStream(fichero_datos);
ObjectOutputStream salida = new ObjectOutputStream(fo);
salida.writeObject(elCliente);
salida.flush();
salida.close();
fo.close();And the result file:
�..sr..ClienteJB``}\..L. nombreq..Ljava/lang/String;L ..Fulanito
I do not want the string �Fulanito� to be accesible by editing the file.
Thanks a lot for your attention,
- Susana

And I thought that when you do that the stored data where bytes, instead of strings. When encoded as UTF-8, String are made up of bytes. You cannot assume that because bytes are used, that the file should be completely unreadable.
You will have trouble editing the file in a text editor as the binary values will get changed and the the stream will appear to be corrupted.
The only way to ensure the data is unmodifyable is to encrypt the data.
If you want the data to be mearly unreadable, add a DeflatorOutputStream between the ObjectOutputStream and the FileOutputStream. This will compress the data and make it unreadbale unless you use an InflatorInputStream.

Similar Messages

  • Appending Objects to a File using serialization

    hi,
    I was wondering if I can append objects in a single file. For example, suppose there are 2 .java files. 1st file creates the Serialized file caleed sl.dat, opens it, writes the object, close it down.
    The 2nd file nw open that same file, sl.dat, in append mode, writes one more object and close it down.
    next I want to read each object of the file. Will it work in this fashion?
    I found a quite interesting discussion here. but it says that it is not possible.. is that true?
    Any clue? Is there any other mean to achieve this?

    arin wrote:
    kajbj wrote:
    I've done it by subclassing ObjectOutputStream. I could then add a constructor that took an argument that indicated if a header should be written or not.Can you explain what I need to done here... I have a class which extends ObjectOutputStream but what to do after that? What do u mean by header in the constructor?? Please help meYou do know that you have the source code for the class if you have a JDK? The source for ObjectOutputStream is in the src.zip.
    The normal constructor calls writeStreamHeader, and that is the problem if you are going to append data since you don't want to get the stream header more than once. Create a constructor that takes a boolean as argument, and only calls writeStreamHeader if the boolean is true.
    Kaj

  • How to reference the Parent view Object attribute in Child View object

    Hi , I have the requirememt to generate Tree like struture to display Salary from joining date to retirement date in yearly form.I have writtent two Pl/SQL function to return parent node and child nodes(based on selected year).
    1.First function --> Input paramter (employee id, retirement date , joining date) --> return parent node row with start_date and end_date
    2. 2nd function --> input paarmter(employee id, startDate, end_date) --> return child node based on selected parent node i.e. start date and end date
    I have created two ADF view object based on two function return
    Parent Node --> select * from Table( EUPS.FN_GET_CONTR_SAL_BY_YR(employeeId,retirement Date, dateOf joining)) ;
    Child Node --> select * FROM TABLE( EUPS.FN_GET_CONTR_SAL_FOR_YEAR( employeId,startDate, endDate) ) based on selected parent node.
    I am giving binding variable as input for 2nd function (child node) . I don't know how to reference the binding variable value in child view from parent view.
    Like I have to refernce employeId,startDate, endDate values in 2nd function from parent view object. some thing like parentNode.selectedStart_date parentNode.employeeId.
    I know we can achive this writing the code in backing bean.But i want to know how can we refernce parent view object attribute values in child view object using Groovy or otherway?
    I will appreciate your help.
    Thanks

    I have two view com.ContractualSalaryByYearlyView for Parent Node and com.ContractualSalaryByYearlyView for child Node.
    I have created view link(ContractualSalYearlyByYearViewLink) betweem two view by giving common field empId, stDate , endDate.(below is the view link xml file).
    I tried give the binding attribute values using parent object reference like below in com.ContractualSalaryByYearlyView xml file but getting error
    Variable ContractualSalaryByYearlyView not recognized.I think i am using groovy expression.
    Thanks for quick response.
    com.ContractualSalaryByYearlyView xml
    <ViewObject
    <DesignTime>
    <Attr Name="_isExpertMode" Value="true"/>
    </DesignTime>
    <Variable
    Name="empId"
    Kind="where"
    Type="java.lang.Integer">
    <TransientExpression><![CDATA[adf.object.ContractualSalaryByYearlyView.EmpId]]></TransientExpression>
    </Variable>
    ContractualSalYearlyByYearViewLink.xml file
    <ViewLinkDefEnd
    Name="ContractualSalaryByYearlyView"
    Cardinality="1"
    Owner="com.ContractualSalaryByYearlyView"
    Source="true">
    <DesignTime>
    <Attr Name="_finderName" Value="ContractualSalaryByYearlyView"/>
    <Attr Name="_isUpdateable" Value="true"/>
    </DesignTime>
    <AttrArray Name="Attributes">
    <Item
    Value="com.ContractualSalaryByYearlyView.EmpId"/>
    <Item
    Value="com.ContractualSalaryByYearlyView.StDate"/>
    <Item
    Value="com.ContractualSalaryByYearlyView.EndDate"/>
    </AttrArray>
    </ViewLinkDefEnd>
    <ViewLinkDefEnd
    Name="ContractualSalaryForYearView"
    Cardinality="-1"
    Owner="com.ContractualSalaryForYearView">
    <DesignTime>
    <Attr Name="_finderName" Value="ContractualSalaryForYearView"/>
    <Attr Name="_isUpdateable" Value="true"/>
    </DesignTime>
    <AttrArray Name="Attributes">
    <Item
    Value="com.ContractualSalaryForYearView.EmpId"/>
    <Item
    Value="com.ContractualSalaryForYearView.StDate"/>
    <Item
    Value="com.ContractualSalaryForYearView.EndDate"/>
    </AttrArray>
    </ViewLinkDefEnd>

  • Custom Deserialization for a List of serializable objects

    I'm running into trouble creating custom deserialization using the readObject method.
    Here is the code the reads the blob from the database:
    Blob blob = rs.getBlob(idx++);
                InputStream iStream = blob.getBinaryStream();
                try {
                    ObjectInputStream oiStream = new ObjectInputStream(iStream);
                    Object object = oiStream.readObject();
                    List data = (List) object;
                    report.setData(data);
                catch (EOFException ignored) {}
                finally {
                    iStream.close();               
                }And my class:
    public class PerformanceReportRowInfo extends PerformanceInfo
        private static final long serialVersionUID = 20060406L;
        private String _dateStr;
        private long _queries;
        private void readObject (ObjectInputStream ois) throws IOException,
                ClassNotFoundException
            ObjectInputStream.GetField fields = ois.readFields();
            _dateStr = (String) fields.get("_dateStr", null);
            try {
                _queries = fields.get("_queries", 0L);
            } catch (IOException io) {
                int intQueries = fields.get("_queries", 0);
                _queries = (long) intQueries;
    }The reason custom deserialization is needed is because we are converting the "_queries" attribute from an int to a long, and do not want to have to replace all the blobs in our DB with long types.
    For some reason, however, the readObject method never gets called in the PerformanceReportRowInfo, and instead i continue to get the error message:
    java.io.InvalidClassException: PerformanceReportRowInfo; incompatible types for field _queries
    I even added logging to the readObject method to make sure it wasnt getting called, and my suspicion was confirmed, it was indeed not getting called. Is my problem related to the fact that it is extending another serializable object (in this case PerformanceInfo) that doesnt have a custom readObject method? Or is it because of how im converting the blob to a List in the first block of code? BTW, the exception occurs at this line:
    Object object = oiStream.readObject();
    Thanks for the help!

    It is Serializable and does not extend any other class (except Object of course), here is the full stack trace:
    Caused by: java.io.InvalidClassException: PerformanceReportRowInfo; incompatible types for field _queries
         at java.io.ObjectStreamClass.matchFields(ObjectStreamClass.java:2175)
         at java.io.ObjectStreamClass.getReflector(ObjectStreamClass.java:2070)
         at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:586)
         at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1552)
         at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1466)
         at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1552)
         at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1466)
         at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1699)
         at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1305)
         at java.io.ObjectInputStream.readObject(ObjectInputStream.java:348)
         at java.util.ArrayList.readObject(ArrayList.java:591)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:946)
         at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1809)
         at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1719)
         at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1305)
         at java.io.ObjectInputStream.readObject(ObjectInputStream.java:348)
         at MyClass.readReport(MyClass.java:332)

  • How do i copy (save) an object to a file

    hello
    i am a programmer (but do not have so much experience in java more c, c++ and matlab)
    i have a question
    how do i copy an object to a file?
    i have Object obj and i want to have a class with two methods save ( save it to a file') and load (open this saved file)
    class SaveFile {
    Object obj
    // other fields perhaps if it is necessary
    public save (Object obj) {
    //code if which i don't know how to write and i need help from you
    public load (object obj) {
    //code if which i don't know how to write and i need help from you
    i believe it is a standard think whith a standard solution so i hope people can show the complete code (or pseudocode) because i am not so good in java's io.package

    Here's a small example that uses no expert features:import java.io.*;
    public class Test {
        public static void main (String[] parameters) throws Exception {
            write (new TestObject ("Test"), "test.obj");
            System.out.println (((TestObject) read ("test.obj")).getName ());
        private static class TestObject implements Serializable {
            private String name;
            public TestObject (String name) {
                this.name = name;
            public String getName () {
                return name;
        private static void write (Serializable object, String filename) throws IOException {
            ObjectOutputStream out = null;
            try {
                out = new ObjectOutputStream (new FileOutputStream (filename));
                out.writeObject (object);
                out.flush ();
            } finally {
                if (out != null) {
                    try {
                        out.close ();
                    } catch (IOException exception) {}
        private static Object read (String filename) throws ClassNotFoundException, IOException {
            ObjectInputStream in = null;
            try {
                in = new ObjectInputStream (new FileInputStream (filename));
                return in.readObject ();
            } finally {
                if (in != null) {
                    try {
                        in.close ();
                    } catch (IOException exception) {}
    }

  • Cant write an image contained object to a file

    HI, I am trying to save Vector object to a file which contains an image as one element.But i am not able to do that can anybody tell how to write the program.
    i wrote the following program to do that task. but it's not working
    can anybody tell what changes i have to make my program to work properly
    my code as follows
    import java.util.*;
    import java.io.*;
    import java.awt.*;
    class ImageWrit implements Serializable
    Image img;
    public ImageWrit(){
    img= Toolkit.getDefaultToolkit().getImage("a9.bmp");
    class A{
    public static void main(String s[])
    FileOutputStream fout;
    ObjectOutputStream out ;
    Vector list = new Vector();
    list.add(new ImageWrit());
    try{
    fout = new FileOutputStream("a.txt");
    out = new ObjectOutputStream(fout);
    out.writeObject(list);
    System.out.println("object is saved");
    catch(Exception e)
    System.out.println("error");
    }

    It's easier to read your code (and help) when you use the code tags in you message...
    it's also helpfull to know why you are not able to do it, compiler error, or runtime error, or...
    third it's best to show a StackTrace in case of an Exception, like thatcatch(Exception e)
        System.out.println("error"); // this tell nothing about the Exception
        e.printStackTrace();
    }Maybe your problem is that the Image returned by ToolKit is not Serializable, you can search the internet for something like "java serializable image" for some hints... like making an ImageIcon of the image, which will be Serializable
        public ImageWrit() {
            img = new ImageIcon(Toolkit.getDefaultToolkit().getImage("a9.bmp"));
        }(also have a look at javax.imageio.ImageIO)

  • Inserting non-serializable objects

    Is there any way to insert non-serializable objects into a database? (Or to convert them to bytes?)

    Is there any way to insert non-serializable objectsinto a database?
    A joke right?No, it's not a joke. It would be a pretty bad one if it were.
    Yes, there is a way. Create a table that corresponds
    to the object where each attribute in the object
    corresponds to field in the object. Add a unique key
    if one doesn't exist.I wish it were that simple. I don't have access to those attributes...
    >
    To create an object insert a row into the table. To
    load the object use the unique key to query for the
    row. To 'delete' the object delete the row from the
    table.BTW, the object in question is the java.awt.geom.Area object (http://java.sun.com/j2se/1.3/docs/api/java/awt/geom/Area.html ).
    The only way I can think of to insert an object that doesn't map to a SQL type is to convert it to bytes through serialization, and insert it as RAW data.
    I've extended Area to add a name and made my class serializable. However, since Area is not serializable, the only data I can retrieve after deserializing is the name I added (from my understanding of serialization, I have to save Area's data myself, but can't since I don't have access to it, so the deserialization process calls the Area() constructor which initializes the object to empty).

  • 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

  • Object Count in File

    Hi Everyone,
    I need to read and write Employee objects from a data structure to a file. When I read these objects back in, is there any way to get a count of the number of objects in the file? I don't want readObject to throw an exception if there are no more objects left. Do I have to write this information to the file myself, or is there another way?
    Thx.
    Donna

    Huh?
    Serialization can store all binary data you want. It is not the best format if you want to know the number of objects in a file based on file size, nor does it have a header that tells the number of objects in the file.
    What do you mean by a map here? If you mean the java.util.Map then most of the classes that implement that interface also implement java.io.Serializable which means that you can use writeObject (mapInstance) and also readObject () to get it from a file.
    So since it seems that I do not understand your question, can you clarify?

  • Why cant i append objects to a file

    i'm amazed that i cannot append objects to a file
    as i did earlier in c++
    it gives StreamCorrupt error

    Ashutosh.options4u wrote:
    i'm amazed that i cannot append objects to a file
    as i did earlier in c++Whatever you did in C++ didn't involve ObjectOutputStream or Java Serialization. You can append anything but objects to a file in Java. The reasons are two:
    (a) ObjectOutputStream writes a header which ObjectInputStream expects to find at the beginning of the stream and nowhere else
    (b) closing an ObjectOutputStream and starting a new one to append to the same file breaks the specified semantics for preservation of object graphs under Serialization, which can only be implemented within a single instance of ObjectOutputStream.
    it gives StreamCorrupt errorI agree.

  • Saving An Object to a File

    I'm writing a group of Classes that handles manipulation of Plasmids (basically circular DNA sequences). My problem is that I want to save the objects to a file. I've been able to implement something that kindof works but has some problems. First what I have so far.
    public static Plasmid getPlasmidFromFile(File path) throws FileNotFoundException, IOException, ClassNotFoundException {
            FileInputStream fileIn = new FileInputStream(path);
            ObjectInputStream in = new ObjectInputStream(fileIn);
            return (Plasmid)in.readObject();
    public void savePlasmidToFile(File path) throws IOException {
            FileOutputStream fileOut = new FileOutputStream(path);
            ObjectOutputStream out = new ObjectOutputStream(fileOut);
            out.writeObject(this);
            out.close();
        }Now this works perfectly except for one thing. As part of the plasmid object there is two arrays of objects (Origin and Gene).
    Gene genes[] = new Gene[MAX_GENES];
    Origin origins[] = new Origin[MAX_ORIGINS];When I use my getPlasmidFromFile() method to load a file it does not load genes[] or origins[]. Both Origin and Gene implements java.io.Serializable (well and Plasmid).
    Any insight into what I'm doing wrong? Thanks in advance for any help.

    Thanks guys for your quick responses. Realized I was
    doing something really stupid.
    Niether Origin or Gene was declared static.
    However, both of them were extended from the Class
    DNASequenceOfInterest and that Class was not declared
    Serilalizable. Implementing that there fixed my
    problems. I've been trying to fix this sense last
    night with no success and now I just feel stupid :/Happens to all of us! At least you figured it out on your own.

  • Serialize object to MSQL database

    Hi
    Is it possible to serialize object to MSQL database instaed of file/Store?
    Please guide me...
    Thank you very much in advance
    PSL

    Somebody please throw some idea...Thank you very much

  • How to get attribute value from an object inside an object in Xpress

    Does anyone know how to get an attribute value from an object in Xpress in a workflow? I have an object structured as follows:
    <ResourceInfo accountId='mj628' tempId='3483372b787ce7dd:-5d99a0c5:130cb238483:-3600'>
    <ObjectRef type='Resource' name='Google Apps'/>
    </ResourceInfo>
    I need if possible to get the name='Google Apps', which is inside the ObjectRef, so I guess its an attribute value of an object inside an object.

    If the ResourceInfo object is accessible in a variable, i.e. named "myResInfo", you just have to check the Java API and call the relevant method:
    <invoke name='getResourceName'>
      <ref>myResInfo</ref>
    </invoke>

  • HELP! Second time...Some attributes of one or more of the files.

    I allready post this question in the morning, but got no answer.
    I want to know if someone have had this problem before.
    Maibe I didn't explain myself well, please let me know if you understand what is the problem I am having. I really need to sove this, I have more than 60 hours of material allready captured and I can't start editing until I solve this problem. I am working with two G5s and I have the same error in both of them.
    Here is the question again with some corrections to see if you guys undestand me:
    I am batch capturing a HUGE project that I logged on FCP 4.5, I am now working with FCP5. I have captured arround 70 hours of material. In some cases I captured the clips but it shows the clip as if it was offline. When I try to reconect the media the following mesage shows up:
    "Some attributes of one or more of the files you hace chosen do not match the attributes of the original. This may cause problems within the sequence that are dependent on them. The attributes that differed are the follows:
    - Media start and end
    Would you like to try to connect them again?"
    What does this mean?
    I do not have any sequence yet, am I going to have future problems with the sequence in the project?
    PLEASE HELP!!!!!
    Thanks a lot in advance.
    Jorge

    I haven't found an answer to this yet and wish I could give advice.
    However, I'm looking for it. And if you find anything - we'd love to know.
    I've got a very large progect - all the media was manually copied over (via the finder) to external lacie FW drives which were brought here to another satellite editing room. I recieve updated projects from the primary edit and relink the media - The audio files have tended to 'mismatch' when I reconnect the updates. And it appears this is increasing in frequency each time! (I relink to each new version of the project which is sent).
    At this point it seems all the audio files bring up the same "File Attribute Mismatch" window. Only in certain sections of the sequence is the audio out of sync (to a variable degree +/- 5 to 7 frames).
    This occours when I replicate the workflow on another machine.
    This does NOT happen when I've sent the projects back to the original edit suite - which has the original media. The reconnection is fine.
    So it appears this might be due to the media itself - and possibly when it was copied over.
    But I can't yet figure out why this problem appears to be increasing, occouring with more audio files.
    If anyone has any ideas to this - which sounds very similar to the original issue on this thread - we'd be obliged to reciprocate the help!
    Cheers
    G5 dual 2.3GHz power PC   Mac OS X (10.4.6)   FCP 5.0.4 / QT 7.1
    12 G4 PowerBook (1Ghz)   Mac OS X (10.4.1)  

  • Save different Objects in one file by two different streams

    Hi all,
    I have a issue to read two Objects from one file if I write those in two different streams.
    I open the ObjectOutputStream and save an Object to the file. Then I close this stream and file. Then I open the new ObjectOutputStream and save the second Object in the same file. It works Ok. Then I open the ObjectInputStream and try to read those two objects and get java.io.StreamCorruptedException.
    This exception happes only when app tryes to read the second Object.
    this is the code example:
    //Write part
    for (int i=0;i<2;i++)
    File file = new File("test.swp");
    FileOutputStream fileOut = new FileOutputStream(file,true);
    ObjectOutputStream objOut = new ObjectOutputStream(fileOut);
    JobObject jobObj = new JobObject();
    jobObj.setID(i);
    objOut.writeObject(jobObj);
    objOut.flush();
    objOut.close();
    fileOut.close();
    //Read part
    FileInputStream fileOut = new FileInputStream("test.swp");
    ObjectInputStream objOut = new ObjectInputStream(fileOut);
    for (int i=0;i<2;i++)
    JobObject jobObj = (JobObject)objOut.readObject();
    objOut.close();
    fileOut.close();
    Thank for any help.

    Maybe try closing the ObjectInputStream (and re-creating it as needed) within your for loop?
    - Saish
    "My karma ran over your dogma." - Anon

Maybe you are looking for

  • Thumb nails have red X

    After sending clips from FCP the first 50 clips in the timeline display a thumbnail and the last 50 display a red X although they do play properly. I've tried to reconnect the media but that doesn't seem to rectify the situation. Also, I can't seem t

  • Default date (current date - 1) on prompt

    Hi Everybody, I have BI 11.1.1.6.1 I have a Prompt in which there is a calender I need Defalut date to be set as (sysdate - 1). I tried Need default date (current date - 1) on prompt and How to create a prompt with default value as current_date? But

  • Submitting form by email

    Hi, I have created a form and sent it to a customer to test it before I distribute it to all my customers. He filled in the form and clicked submit by email. It opened his Microsoft Outlook and populating the email with the form as planned, but when

  • Using trial of Photoshop CC but when trying 3D get "Could not apply the workspace because the disk is not available." can anyone help?

    I am trying out Photoshop CC  specifically the 3D facility but every time i go to 3D I get "Could not apply the workspace because the disk is not available" I have searched online for answer but cannot resolve this, can anyone advise? regards Drew.

  • Sql Exam Question.

    Hi guys i m planning to give oracle exam for 1Z0-007 Introduction to Oracle9i SQL® . Request you to please suggest where would i get latest dump for it and are they free of cost.(I would be pleased if some one provide me latest actualtest document) I