Stream size in object serialization
hi everyone ,
Is there any way to know the size of a stream before starting to read the stream ?
Thanks
hi everyone ,
Is there any way to know the size of a stream
before starting to read the stream ?
ThanksYou could use a BufferedInputStream and use the available() method. It returns the number of bytes available on the stream.
Similar Messages
-
Try the Forte trace flag, trc:os:5:5.
It will tell you the size and number of objects in memory.
(Note: I don't think it well put together your entire object graph
for you.
(e.g. If you have pointers to other complex objects hanging
off of your object, I don't believe they are reflected in the
object size.)
Hope this helps!
-----Original Message-----
From: [email protected]
[<a href="mailto:[email protected]">mailto:[email protected]]On</a> Behalf Of
[email protected]
Sent: Thursday, October 01, 1998 12:55 PM
To: [email protected]
Subject: Size of Objects
I am trying to find the size of an object in memory. Can someone tell me
what the best way is?
If I store the object in a MemoryStream, the Size() method return the
total bytes in the stream, but
does this correspond to the size of the object in memory?
Regards,
Peter Kelly
To unsubscribe, email '[email protected]' with
'unsubscribe forte-users' as the body of the message.
Searchable thread archive <URL:<a href=
"http://pinehurst.sageit.com/listarchive/">http://pinehurst.sageit.com/listarchive/</a>>
>
To unsubscribe, email '[email protected]' with
'unsubscribe forte-users' as the body of the message.
Searchable thread archive <URL:<a href=
"http://pinehurst.sageit.com/listarchive/">http://pinehurst.sageit.com/listarchive/</a>>I used to serialize the object and inspect the size of
the file.
This way it worked fine for me.
Hope this helps!
Ajith Kallambella M
Forte Systems Engineer,
International Business Corporation.
I am trying to find the size of an object in memory.Can someone tell me
what the best way is?
If I store the object in a MemoryStream, the Size()method return the
total bytes in the stream, but
does this correspond to the size of the object inmemory?
Regards,
Peter Kelly-
To unsubscribe, email '[email protected]' with
'unsubscribe forte-users' as the body of the message.
Searchable thread archive<URL:http://pinehurst.sageit.com/listarchive/>
To unsubscribe, email '[email protected]' with
'unsubscribe forte-users' as the body of the message.
Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/> -
RE: RE : Size of Objects
According to Forte, the size of serialized object is smaller that object
size in the memory (in particular due to overhead necessary to support
garbage collector).
There is a way to calculate object size more or less precisely, but it
fairly complex and definitely undocumented. I'm not sure that I will
remember everything correctly (it was 1.5 years ago), so if somebody has
more up-to-date knowledge, please correct any errors.
There is, special flag cfg:?? (I do not remember it exactly), which
allows you to invoke so-called INTERNAL methods. One of such methods is
method getSize() on class Object. You can use it to receive object size
in the memory. After that you need to add all memory taken by object
simple type attributes, including implicit ones (e.g. for TextData
object you need execute getSize() and add result of getAllocatedSize(),
because string itself stored as separate entity). Result must be rounded
by modulo 8 and after that you need add another 8 bytes for garbage
collector information. After that you need calculate such size for all
complex attributes which are objects themselves.
Hope this will help.
WBR,
Nick Sakharov
CBSI
From: Ajith Kallambella M[SMTP:[email protected]]
Reply To: Ajith Kallambella M
Sent: Thursday, October 01, 1998 2:34 PM
To: [email protected]; ForteUsers
Subject: RE : Size of Objects
I used to serialize the object and inspect the size of
the file.
This way it worked fine for me.
Hope this helps!
Ajith Kallambella M
Forte Systems Engineer,
International Business Corporation.
I am trying to find the size of an object in memory.Can someone tell me
what the best way is?
If I store the object in a MemoryStream, the Size()method return the
total bytes in the stream, but
does this correspond to the size of the object inmemory?
Regards,
Peter Kelly-
To unsubscribe, email '[email protected]' with
'unsubscribe forte-users' as the body of the message.
Searchable thread archive<URL:http://pinehurst.sageit.com/listarchive/>
To unsubscribe, email '[email protected]' with
'unsubscribe forte-users' as the body of the message.
Searchable thread archive
<URL:http://pinehurst.sageit.com/listarchive/>
To unsubscribe, email '[email protected]' with
'unsubscribe forte-users' as the body of the message.
Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>I used to serialize the object and inspect the size of
the file.
This way it worked fine for me.
Hope this helps!
Ajith Kallambella M
Forte Systems Engineer,
International Business Corporation.
I am trying to find the size of an object in memory.Can someone tell me
what the best way is?
If I store the object in a MemoryStream, the Size()method return the
total bytes in the stream, but
does this correspond to the size of the object inmemory?
Regards,
Peter Kelly-
To unsubscribe, email '[email protected]' with
'unsubscribe forte-users' as the body of the message.
Searchable thread archive<URL:http://pinehurst.sageit.com/listarchive/>
To unsubscribe, email '[email protected]' with
'unsubscribe forte-users' as the body of the message.
Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/> -
Hi I would like to implement a size of method in Java. I know it is impossible but I also know that there are turn arounds to the problem using methods such as gc and serialization which give satiffactory results.
In my case acurracy is not of utmost importance but speed is. The sizeOf method will be used in a object caching service and will be called each time an object is put in the cache.
I thought that serialization would be a good option. Do you guys think it is the best one? And if yes how can I go around finding the size of the serializaed stream without writing it to disk.
My main goal would be to turn the following code to write the serialzation to a String instead of the file in order to eliminate disk
IO.
BaseCacheReference B = new BaseCacheReference(new Attributes());
FileOutputStream f_out = new FileOutputStream ("C:\\myobject.data");
ObjectOutputStream obj_out = new ObjectOutputStream (f_out);
obj_out.writeObject (B);
Can anyone help me?
Thanks in Advance
Nick.Thanks guys and girls,
TO SYLVIA:
I am trying to create a cache engine with different policies such as GC based using soft references
and also my own using LRU, LFU methods. The cache will be used to cache objects that are expensive
to create. Thus it is simple object caching. (theOCS4J specification is similar to what I have in mind)
The cache will be sub-divided into what I called regions of memory
sizes specfied by the user. Each region uses one of the above policies to clear the cache when it reaches its limit.
Now my problem is how can I determine if my region has reached the limit without knowing the size of the objects
being added to the cache.
TO forumNazi:
DO YOU GET THE POINT forumNazi or where you simply just stoned when you read the message? Anyway
could you pls avoid writing useless messages in the near fututure pls since they don'nt get
any of us in a better position.
Back to the problem!! I tried using the ByteArrayOutputStream as DrJohnFoster said
and created the following function:
public int sizeOf(CacheReference CacheObject)
try
ByteArrayOutputStream baos = new
ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(baos);
out.writeObject(CacheObject);
out.flush();
// Subtract 4 bytes from the length, because the serialization
// magic number (2 bytes) and version number (2 bytes) are
// both written to the stream before the object
return baos.toByteArray().length - 4;
catch(IOException e)
System.out.println(e);
return 0;
Since you said that serialization includes stuff such as class names, field names then I guess
I could either find an aprroximation to the size of the object by trying to calculate the
amount of mem used in field names, OR I could resort reflection.
I don'nt know if it is possible but could you post me a copy of the code of the sizeOf() using
reflection sylvia.
Thanks to ALL -
Hey guys, im new at this so i dont know almost anything about serialization, so here's my problem:
Got an array of an object "Article" that i defined, wanna write it to a file but i get the "NotSerializableException",
here's my object's constructor:
Article (String n, int u, float p)
name = n;
amount = u;
price = p;
fmt = new DecimalFormat ("0.##");
by the way, all of the variables are private, i dont have any problem storing several articles in my array, i just get my exception at runtime here:
public static void save(Object obj, String nombrearch) throws IOException
ObjectOutputStream objstream = new ObjectOutputStream(new FileOutputStream(nombrearch));
objstream.writeObject(obj);
objstream.close();
apologizing for inconviniences, hope you can help me work this outsanu018 wrote:
When ever u are writing to a stream all the objects that u r exporting should be serializable. Primitive types are as such non serializable so replace all those int with Integer type objects.Absolute total rubbish. Just pure bullshit.
If you don't have a clue what you're talking about then please don't offer "advice" on these forums. -
Customizing Forte object serialization
Forte supports serialization of arbitrary object graphs into streams.
However, there do not seem to be any well documented ways to customize
this serialization, e.g. by using a different encoding scheme. It would
seem there must be some support in there somewhere. I suppose at the
very least, one could parse a serialized object (once one decoded the
Forte encoding scheme) and do the conversion from that. That seems
suboptimal, though.
Has anyone done this? Any thoughts on how it might be done?
Regards,
Coty
To unsubscribe, email '[email protected]' with
'unsubscribe forte-users' as the body of the message.
Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/forte>JavaFunda wrote:
Object serialization is the process of saving an object's state to a sequence of bytes. Does it saves only the instance variable or also the object methods(like getter and setter methods) ? Only the state--the instance variables. It doesn't save the class definition. That has to be available separately (via classloader) at deserilaization time. In other words, you cannot deserialize an instance of a class that is not on your classpath.
Once we we write the object to outputstream or some text file, how does it get transmitted over network?The same way any other bytes get transmitted. You have a Socket. You get its OutputStream. You wrap that in an ObjectOutputStream. When you write to the ObjectOutputStream, that writes through to the Socket's OutputStream, which is responsible for putting the bytes on the wire.
Does we write the java object to text file only duuring serialization?We write the objects to wherever the other end of the ObjectOutputStream is connected to. Just like any other I/O. -
How to change Font Size of Object Explorer in "SQL Server Management Studio"
Dear Team,
"SQL Server Management Studio" is a fantastic IDE for the database.
There are so many customization options available but one thing many users missing is that " How to change Font Size of Object Explorer?"
Can you please accumulate this feature in IDE ASAP?
Many Thanks,
BhaveshIts there
Go to Tools -> Options
Then under Environment you've fonts and colors tab where you can specify a higher font size.
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page -
How to view the physical size of objects
Hi
Please advise how to view the physical size of objects like tables, indexes, materialize views etc.
Wishes
JawadTo see the physical size of objects like tables, indexes, use
USER_SEGMENTS where SEGMENT_TYPE=table/index/partition etc.
But for views/packages/java/trigger, you can only see rough estimate in USER_OBJECT_SIZE -
Still not supporting relative size of objects?
Hi everybody!
Am I blind? Just downloaded and installed iWork '09, hoping they added the possibility to adjust the size of objects like pictures in a relative manner, finally.
Let's say, you have some screenshots for creating a documentary. All of different sizes. You want all of them to appear in your Pages document at 50 % of their original size. How can you manage this? I still didn't find a way for this simple task.
Have I really to use Word for Pages can't help me with this?
Regards,
OlafApple deliver with the operating system several scripts allowing us to manipulate our pictures.
Here is one of them edited to divide the pictures dimensions by two.
--[SCRIPT Half_size}
property done_foldername : "Reduced Images"
property originals_foldername : "Original Images"
property newimage_extension : "jpg"
-- the list of file types which will be processed
-- eg: {"PICT", "JPEG", "TIFF", "GIFf"}
property type_list : {"TIFF", "GIFf", "PNGf", "PICT", "JPEG"}
-- since file types are optional in Mac OS X,
-- check the name extension if there is no file type
-- NOTE: do not use periods (.) with the items in the name extensions list
-- eg: {"txt", "text", "jpg", "jpeg"}, NOT: {".txt", ".text", ".jpg", ".jpeg"}
property extension_list : {"tif", "tiff", "gif", "png", "pict", "pct", "jpeg", "jpg"}
on adding folder items to this_folder after receiving these_items
tell application "Finder"
if not (exists folder done_foldername of this_folder) then
make new folder at this_folder with properties {name:done_foldername}
end if
set the results_folder to (folder done_foldername of this_folder) as alias
if not (exists folder originals_foldername of this_folder) then
make new folder at this_folder with properties {name:originals_foldername}
set current view of container window of this_folder to list view
end if
set the originals_folder to folder originals_foldername of this_folder
end tell
try
repeat with i from 1 to number of items in these_items
set this_item to item i of these_items
set the item_info to the info for this_item
if (alias of the item_info is false and the file type of the item_info is in the type_list) or (the name extension of the item_info is in the extension_list) then
tell application "Finder"
--set name of this_item to "YK#" & (text -4 thru -1 of ("0000" & i))
my resolveconflicts(thisitem, originals_folder, "")
set the new_name to my resolveconflicts(thisitem, results_folder, newimage_extension)
set the source_file to (move this_item to the originals_folder with replacing) as alias
end tell
processitem(sourcefile, new_name, results_folder)
end if
end repeat
on error error_message number error_number
if the error_number is not -128 then
tell application "Finder"
activate
display dialog error_message buttons {"Cancel"} default button 1 giving up after 120
end tell
end if
end try
end adding folder items to
on resolveconflicts(thisitem, target_folder, new_extension)
tell application "Finder"
set the file_name to the name of this_item
set file_extension to the name extension of this_item
if the file_extension is "" then
set the trimmed_name to the file_name
else
set the trimmed_name to text 1 thru -((length of file_extension) + 2) of the file_name
end if
if the new_extension is "" then
set target_name to file_name
set target_extension to file_extension
else
set target_extension to new_extension
set target_name to (the trimmed_name & "." & target_extension) as string
end if
if (exists document file target_name of target_folder) then
set the name_increment to 1
repeat
set the new_name to (the trimmed_name & "." & (name_increment as string) & "." & target_extension) as string
if not (exists document file new_name of the target_folder) then
-- rename to conflicting file
set the name of document file target_name of the target_folder to the new_name
exit repeat
else
set the name_increment to the name_increment + 1
end if
end repeat
end if
end tell
return the target_name
end resolve_conflicts
-- this sub-routine processes files
on processitem(sourcefile, new_name, results_folder)
-- NOTE that the variable this_item is a file reference in alias format
-- FILE PROCESSING STATEMENTS GOES HERE
try
-- the target path is the destination folder and the new file name
set the target_path to ((results_folder as string) & new_name) as string
with timeout of 900 seconds
tell application "Image Events"
launch -- always use with Folder Actions
set this_image to open file (source_file as string)
scale this_image by factor 0.5
save this_image as JPEG in file target_path with icon
close this_image
end tell
end timeout
on error error_message
tell application "Finder"
activate
display dialog error_message buttons {"Cancel"} default button 1 giving up after 120
end tell
end try
end process_item
--[/SCRIPT]
If you don't know the way we use that, enter the Finder's Help and search for "folder action".
Yvan KOENIG (from FRANCE vendredi 16 janvier 2009 20:26:11) -
hi , is there any way we can determine the size of objects in java ,like we have sizeof() in C. because till now I have only found functions in runtime class to determie the mem. as total OR max. OR free
In Java 1.5 is the Instrumentation package which can provide something like Object sizes. Never used it myself, though.
-
2D objects Serialization problem
Welcome!
I'm making a net game using RMI and I have this problem.
When I'm trying to join my client with the server an error occures:
Error: error marshalling arguments; nested exception is:
java.io.NotSerializableException: java.awt.geom.Ellipse2D$Double
My client contains an Object extending a JPanel class. There are 2D object used to make the map, and that's why this error occures.
It's a funny thing, cause I'm not sending a whole Object of my client, but only it's refference (using "this" in the join() method) so I dont know why does the 2D object need to be serialized and sent :|?
Any way, my question is how to make 2D objects serializable!? I have jdk1.5.0_06 and as far as I remember they should be srializable in this version. Mabey I'm dooing something wrong!? Mabey it's nessesary to ad an appropreate code-line or import sth... i don't know
please help me... I have little time to finish my project, and this thing is blocking my work.
Big thanks to anybodey who will help.
regards floWI'll tel u the whole story then, my problem is as follows:
public class BounceThread{
public static void main(String[] args) {
JFrame ramka = new BounceFrame();
ramka.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ramka.setVisible(true);
class BounceFrame extends JFrame{
public BounceFrame()
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
setTitle("MiniGolf v 1.0");
panel = new BallPanel(); // this contains maps made with 2D objects
panel.setBackground(Color.green);
panel.setVisible(panel.czy_widać_panel());
add(panel, BorderLayout.CENTER);
// I add a menu bar, that starts a net game:
JMenuBar pasekMenu = new JMenuBar();
setJMenuBar(pasekMenu);
JMenu menuGra = new JMenu("Game");
// and so on... and finaly I add an option:
menuGame_Nowa.add(new
AbstractAction("Net game")
public void actionPerformed(ActionEvent event)
net_game(panel);
// here i write my net_game method:
public void net_game(BallPanel aPanel)
//here, i make an Client object, and connect him with my server
client = new mgClient(panel);
client.join();
// I give panel as a paramete, cause I cant think of another way of leting my server to uce it's (panels) methods
// If I join only a name of my client, then how can I change the panel in my BounceFrame from the Clients method
// "shouted" by the server!? It has to be a field in the client's object.
// Is there any other way out!?
// Class BouceFrame holds the panel as a field:
private mgClient client;
private BallPanel panel;
//and so on...
}and that's the real problem I'm facing here. Is there any solution!? I think, that making a Client's field out of my panel is the only way ot. And that means I need those 2D objects serialized... :(
Please help if u can.
Regards floW -
Servlet and Object Serialization
Hi,
I am developing a routing server in Java
2 Instances of the same server will be running in 2 different data centers.
The servers have a Jetty server embedded with a Servlet inside.
Server 1 will use a GET method to talk to the Server 2 -> Servlet which will write the state of an object back which will read by Server 1 and reconstruct the object back.
Do you find any issues in Object Serialization/DeSerialization in the Servlet.
What are the factors that I need to consider in this case?
Regards,
JanaMake sure that your servlet handles the transaction in the same thread that doPost() or doGet() is called in.
I ended up porting some old ServerSocket based code to a servlet, and was handing off the request and response objects to a handler thread on the server side. I ended up with a ton of intermittent errors like this.
Once I started handling the transactions in the same thread things worked heartbreakingly well. -
Hi,
Could someone explain the concept of Runtime Object Serialization with a simple example?
Thanksimport java.io.*;
/* you NEED to make the class implement Serializable */
class Client implements Serializable {
private String name;
private String address;
public String getName() { return name; }
public String getAddress() { return address; }
public void setName(String name) { this.name = name; }
public void setAddress(String address) { this.address = address; }
public String toString() { return "name='" + name + "' and address= " + address + "'"; }
public class Test17 {
public static void main(String[] args) throws Exception {
ObjectOutputStream oos = new ObjectOutputStream (new FileOutputStream ("test.bin"));
Client myClient = new Client();
myClient.setName("Steve Jobs");
myClient.setAddress("1 Infinite Loop; Cupertino, CA 95014");
System.out.println (myClient);
oos.writeObject (myClient);
oos.close();
ObjectInputStream ois = new ObjectInputStream (new FileInputStream ("test.bin"));
Client yourClient = (Client) ois.readObject();
System.out.println (yourClient);
}Run the program above. It creates an object of the class "Client", serializes it into a file named "test.bin" and recreates the object reading it from the same file.
Dumping the binary file you get this:
0000 AC ED 00 05 73 72 00 06 43 6C 69 65 6E 74 F1 D7 ....sr..Client..
0010 74 76 C4 64 FD 43 02 00 02 4C 00 07 61 64 64 72 tv.d.C...L..addr
0020 65 73 73 74 00 12 4C 6A 61 76 61 2F 6C 61 6E 67 esst..Ljava/lang
0030 2F 53 74 72 69 6E 67 3B 4C 00 04 6E 61 6D 65 71 /String;L..nameq
0040 00 7E 00 01 78 70 74 00 24 31 20 49 6E 66 69 6E .~..xpt.$1 Infin
0050 69 74 65 20 4C 6F 6F 70 3B 20 43 75 70 65 72 74 ite Loop; Cupert
0060 69 6E 6F 2C 20 43 41 20 39 35 30 31 34 74 00 0A ino, CA 95014t..
0070 53 74 65 76 65 20 4A 6F 62 73 Steve JobsYou can see a lot of things in the serialization of the object Client - the name of the class is written, the names of the fields, the type (java/lang/String), and the values of the fields as UTF-8 encoded strings. -
Determining movie stream size in javascript
Hi guys,
Is it possible to determine flash movie stream size of any movie using JavaScript only?
Thanks!JProg,
I am relatively new to programming so I am having some
conceptual difficulties with your suggestion, it
sounds really good, but I can't honestly say that I
understand this fully.
When you say "dump a java class on the server that
will serve as a local file metadata querier" I am a
little stumped. I have a basic understanding of what a
metadata querier is (basically something that gets
info off the server for you) however there are two
things that I would appreciate help with:
1). How does one go about dumping a java class onto
the server?
2). What class would one use?
If you can provide any help with these two points it
will be greatly appreciated. Thanks for the advice so
far.
Regards
Davo
What I meant is create a Java Class that queries File MetaData. Compile it, then put it on the server.
Create an RMI server on the server-side that you would use as a proxy for this class.
From the client-side, call the proxy via the RMI Stubs that were generated when you compiled rmi server. Pass the file name, the stub will send the filename to the querier proxy that serves as RMI server, then this proxy will call the actual file meta data querier passing to it the filename, get the metadata in return, and sends them back to the client. -
Hi,
When writing a vector of my own objects out to a file, do the objects need to be serializable even though it is actually the vector I am outputting?
Also, each of my objects in this vector have a field that is a vector of other objects...do I need to declare those objects serializable also?I think you still need to implement serializable on objects contained in the vector. I tried serializing a hashmap and my hashmap contained objects which needed to be serialized before the hashmap could be stored in a file.
Maybe you are looking for
-
Can not find a table in DBA_TAB_PRIVS and ROLE_TAB_PRIVS
I get a table 'KNA1', a table of SAP R3 ERP application, and tried to find out all privileges granted to 'KNA1'. Using the SQL statement below, I am sure 'KNA1' is existing. SQL> SELECT * FROM DBA_OBJECTS WHERE OBJECT_NAME = 'KNA1'; OWNER OBJECT_NAME
-
Mighty Mouse scroll ball defective.
Well, my second Mighty Mouse no longer scrolls up. The first no longer scrolls down. That makes my experience with this product two for two on the scroll ball going bad within a few months use. Anyone know of a scroll ball mouse that gives the 360 de
-
Row chaining and row migration in Oracle 10g R2/11g R2
Hi, Due to the business rule changes, one of the numeric column in a large table (20 millions rows) will be expanded from number(8) to number(10). Also, the values of this column of each row will be updated from 6 digits to 10 digits. All the indexes
-
Data element description not changing in ALV output
Hi Friends I changed the description of the data element from xx to yy,but this is not reflecting in the alv output, It is still showing xx,After activating everything and running the report I get the same problem, Can any one help?
-
Coming from years of analogue recording I've been used to riding fader levels quite high (slamming the tape, etc.) However, I've noticed that in the DAW world this is actaully NOT such good practice! I was wondering, though, if it was typical to have