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.StoredFormatIds; 27 import org.apache.derby.iapi.services.io.FormatIdUtil; 28 import org.apache.derby.iapi.services.io.ArrayUtil; 29 import org.apache.derby.iapi.services.io.Formatable; 30 31 import org.apache.derby.iapi.services.sanity.SanityManager; 32 33 import java.io.ObjectOutput ; 34 import java.io.ObjectInput ; 35 import java.io.IOException ; 36 37 import java.lang.reflect.Array ; 38 39 43 public class FormatableArrayHolder implements Formatable 44 { 45 58 59 private Object [] array; 61 62 65 public FormatableArrayHolder() 66 { 67 } 68 69 75 public FormatableArrayHolder(Object [] array) 76 { 77 if (SanityManager.DEBUG) 78 { 79 SanityManager.ASSERT(array != null, 80 "array input to constructor is null, code can't handle this."); 81 } 82 83 this.array = array; 84 } 85 86 91 public void setArray(Object [] array) 92 { 93 if (SanityManager.DEBUG) 94 { 95 SanityManager.ASSERT(array != null, 96 "array input to setArray() is null, code can't handle this."); 97 } 98 99 this.array = array; 100 } 101 102 110 public Object [] getArray(Class inputClass) 111 { 112 Object [] outArray = (Object [])Array.newInstance(inputClass, array.length); 113 114 121 for (int i = 0; i < outArray.length; i++) 123 { 124 outArray[i] = array[i]; 125 } 126 127 return outArray; 128 } 129 130 142 public void writeExternal(ObjectOutput out) throws IOException 143 { 144 if (SanityManager.DEBUG) 145 { 146 SanityManager.ASSERT(array != null, "Array is null, which isn't expected"); 147 } 148 149 ArrayUtil.writeArrayLength(out, array); 150 ArrayUtil.writeArrayItems(out, array); 151 } 152 153 161 public void readExternal(ObjectInput in) 162 throws IOException , ClassNotFoundException 163 { 164 array = new Object [ArrayUtil.readArrayLength(in)]; 165 ArrayUtil.readArrayItems(in, array); 166 } 167 public void readExternal(ArrayInputStream in) 168 throws IOException , ClassNotFoundException 169 { 170 array = new Formatable[ArrayUtil.readArrayLength(in)]; 171 ArrayUtil.readArrayItems(in, array); 172 } 173 174 175 180 public int getTypeFormatId() { return StoredFormatIds.FORMATABLE_ARRAY_HOLDER_V01_ID; } 181 } 182 | Popular Tags |