Mercurial > hg > blitz_condensed
comparison src/org/dancres/blitz/mangler/EntrySizer.java @ 0:3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
author | Dan Creswell <dan.creswell@gmail.com> |
---|---|
date | Sat, 21 Mar 2009 11:00:06 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3dc0c5604566 |
---|---|
1 package org.dancres.blitz.mangler; | |
2 | |
3 import java.io.IOException; | |
4 import java.io.ByteArrayOutputStream; | |
5 import java.io.ObjectOutputStream; | |
6 | |
7 import net.jini.core.entry.Entry; | |
8 | |
9 /** | |
10 <p>Utility class to compute a rough indication of the number of bytes an | |
11 Entry will consume once written to a Blitz JavaSpace instance (persistent | |
12 or transient).</p> | |
13 | |
14 <p>Basic usage is to construct an instance of EntrySizer and then invoke | |
15 computeSize for each Entry you're interested in.</p> | |
16 */ | |
17 public class EntrySizer { | |
18 private EntryMangler theMangler = new EntryMangler(); | |
19 | |
20 public EntrySizer() { | |
21 } | |
22 | |
23 public int computeSize(Entry anEntry) throws IOException { | |
24 MangledEntry myEntry = theMangler.mangle(anEntry); | |
25 | |
26 ByteArrayOutputStream myBAOS = new ByteArrayOutputStream(); | |
27 ObjectOutputStream myOOS = new ObjectOutputStream(myBAOS); | |
28 | |
29 myOOS.writeObject(myEntry); | |
30 myOOS.close(); | |
31 | |
32 return myBAOS.size(); | |
33 } | |
34 } |