1 21 22 package org.apache.derby.iapi.services.io; 23 24 import org.apache.derby.iapi.services.io.ArrayInputStream; 25 26 import org.apache.derby.iapi.services.io.FormatIdUtil; 27 import org.apache.derby.iapi.services.io.Formatable; 28 import org.apache.derby.iapi.services.io.StoredFormatIds; 29 30 import java.util.Enumeration ; 31 import java.util.Properties ; 32 33 import java.io.IOException ; 34 import java.io.ObjectOutput ; 35 import java.io.ObjectInput ; 36 37 41 public class FormatableProperties extends Properties implements Formatable 42 { 43 56 57 60 public FormatableProperties() 61 { 62 this(null); 63 } 64 65 71 public FormatableProperties(Properties defaults) 72 { 73 super(defaults); 74 } 75 76 82 public void clearDefaults() { 83 defaults = null; 84 } 85 86 100 public void writeExternal(ObjectOutput out) throws IOException 101 { 102 out.writeInt(size()); 103 for (Enumeration e = keys(); e.hasMoreElements(); ) 104 { 105 String key = (String )e.nextElement(); 106 out.writeUTF(key); 107 out.writeUTF(getProperty(key)); 108 } 109 } 110 111 118 public void readExternal(ObjectInput in) 119 throws IOException 120 { 121 int size = in.readInt(); 122 for (; size > 0; size--) 123 { 124 put(in.readUTF(), in.readUTF()); 125 } 126 } 127 128 public void readExternal(ArrayInputStream in) 129 throws IOException 130 { 131 int size = in.readInt(); 132 for (; size > 0; size--) 133 { 134 put(in.readUTF(), in.readUTF()); 135 } 136 } 137 138 143 public int getTypeFormatId() { return StoredFormatIds.FORMATABLE_PROPERTIES_V01_ID; } 144 } 145 | Popular Tags |