01: // IPTemplatesAttribute.java
02: // $Id: IPTemplatesAttribute.java,v 1.4 2000/08/16 21:37:55 ylafon Exp $
03: // (c) COPYRIGHT MIT and INRIA, 1996.
04: // Please first read the full copyright statement in file COPYRIGHT.html
05:
06: package org.w3c.tools.resources.upgrade;
07:
08: import java.io.DataInputStream;
09: import java.io.DataOutputStream;
10: import java.io.IOException;
11:
12: /**
13: * The IPTemplates attribute description.
14: * Maintains a list of IP templates (short arrays, to allow for the splash).
15: */
16:
17: public class IPTemplatesAttribute extends Attribute {
18:
19: /**
20: * Is the given value a valid IPTemplates value ?
21: * @param obj The object to test.
22: * @exception IllegalAttributeAccess If the provided value doesn't pass the
23: * test.
24: */
25:
26: public boolean checkValue(Object obj) {
27: return ((obj == null) || (obj instanceof short[][]));
28: }
29:
30: /**
31: * Get the number of bytes required to save that attribute value.
32: * @param The value about to be pickled.
33: * @return The number of bytes needed to pickle that value.
34: */
35:
36: public final int getPickleLength(Object value) {
37: return ((short[][]) value).length * 2 + 4;
38: }
39:
40: /**
41: * Pickle an array of IP templates to the given output stream.
42: * @param out The output stream to pickle to.
43: * @param obj The object to pickle.
44: * @exception IOException If some IO error occured.
45: */
46:
47: public void pickle(DataOutputStream out, Object obj)
48: throws IOException {
49: short ips[][] = (short[][]) obj;
50: out.writeInt(ips.length);
51: for (int i = 0; i < ips.length; i++) {
52: out.writeShort(ips[i][0]);
53: out.writeShort(ips[i][1]);
54: out.writeShort(ips[i][2]);
55: out.writeShort(ips[i][3]);
56: }
57: }
58:
59: /**
60: * Unpickle an array of IP templates from the given input stream.
61: * @param in The input stream to unpickle from.
62: * @return An instance of short[][].
63: * @exception IOException If some IO error occured.
64: */
65:
66: public Object unpickle(DataInputStream in) throws IOException {
67: int cnt = in.readInt();
68: short ips[][] = new short[cnt][];
69:
70: for (int i = 0; i < cnt; i++) {
71: ips[i] = new short[4];
72: ips[i][0] = in.readShort();
73: ips[i][1] = in.readShort();
74: ips[i][2] = in.readShort();
75: ips[i][3] = in.readShort();
76: }
77: return ips;
78: }
79:
80: public IPTemplatesAttribute(String name, short defs[][],
81: Integer flags) {
82: super (name, defs, flags);
83: this .type = "[[S";
84: }
85:
86: }
|