public static void writeObjectArray(ObjectOutput out, Object[] array) throws IOException { if (array == null) out.writeInt(-1); else { int length = array.length; out.writeInt(length); int i = 0; try { for (; i < length; i++) writeObject(out, array[i]); } catch (IOException e) { throw new IOArrayException(i, "Failed to serialize item #" + i, e); } } }
public IOArrayException(int index, String message, IOException cause) { this(index, message); initCause(cause); }
private EntrySerializationException createPropertySerializationException(IOArrayException e, boolean isSerialize) { final int index = e.getIndex(); String message = "Failed to " + (isSerialize ? "serialize" : "deserialize") + " property #" + index; ITypeDesc typeDesc = getTypeDescriptor(); if (typeDesc != null) { int numOfProperties = typeDesc.getNumOfFixedProperties(); if (index < 0 || index >= numOfProperties) message += " (index out of bound: number of properties=" + numOfProperties + ")"; else { PropertyInfo property = typeDesc.getFixedProperty(index); message += " (Name=[" + property.getName() + "], Type=[" + property.getTypeName() + "])"; } } message += " in entry of type [" + this.getTypeName() + "]."; if (isSerialize) message += " Value=[" + String.valueOf(getFieldValue(index)) + "]"; return new EntrySerializationException(message, e.getCause()); }
public static Object[] readObjectArray(ObjectInput in) throws IOException, ClassNotFoundException { final int length = in.readInt(); if (length < 0) return null; Object[] array = new Object[length]; int i = 0; try { for (; i < length; i++) array[i] = readObject(in); } catch (IOException e) { throw new IOArrayException(i, "Failed to deserialize item #" + i, e); } return array; }
private void writeObjectArray(ObjectOutput out, Object[] array, IServerTypeDesc typeDesc, boolean isIndexesPart, boolean[] fixed_indexes) throws IOException { if (array == null) out.writeInt(-1); else { int length = array.length; out.writeInt(length); int i = 0; int noNullIndicators; try { for (; i < length; i++) { if (i % 7 == 0) //set the non null indicators { noNullIndicators = 0; int lim = Math.min(length, (i + 7)); for (int j = i; j < lim; j++) { if (!_phantom && array[j] != null && fixed_indexes[j] == isIndexesPart) noNullIndicators |= (1 << (j % 7)); } out.writeByte(noNullIndicators); } if (fixed_indexes[i] == isIndexesPart) writeObjectToStream(array[i], out, typeDesc, i); } } catch (IOException e) { throw new IOArrayException(i, "Failed to serialize item #" + i, e); } } }
public static Object[] readObjectArrayCompressed(ObjectInput in) throws IOException, ClassNotFoundException { Object[] array; final boolean isCompressed = in.readBoolean(); if (isCompressed) { final int length = in.readInt(); array = new Object[length]; final int numNonNullFields = in.readInt(); int i = 0; try { for (; i < numNonNullFields; i++) { int pos = in.readInt(); array[pos] = readObject(in); } } catch (IOException e) { throw new IOArrayException(i, "Failed to deserialize item #" + i, e); } } else array = readObjectArray(in); return array; }
public static void writeObjectArrayCompressed(ObjectOutput out, Object[] array) throws IOException { final int length = array.length; int numNonNullFields = 0; for (int i = 0; i < length; i++) if (array[i] != null) numNonNullFields++; final boolean isCompressed = numNonNullFields < length / 2; out.writeBoolean(isCompressed); if (isCompressed) { out.writeInt(length); out.writeInt(numNonNullFields); int i = 0; try { for (; i < length; i++) { if (array[i] != null) { out.writeInt(i); writeObject(out, array[i]); } } } catch (IOException e) { throw new IOArrayException(i, "Failed to serialize item #" + i, e); } } else writeObjectArray(out, array); }
private Object[] readObjectArray(ObjectInput in, IServerTypeDesc typeDesc, Object[] current) throws IOException, ClassNotFoundException { final int length = in.readInt(); if (length < 0) return current; Object[] array = current == null ? new Object[length] : current; int i = 0; try { int noNullIndicators = 0; for (; i < length; i++) { if (i % 7 == 0) //get the non null indicators noNullIndicators = in.readByte(); if ((noNullIndicators & (1 << (i % 7))) != 0) array[i] = readObjectFromStream(in, typeDesc, i); } } catch (IOException e) { throw new IOArrayException(i, "Failed to deserialize item #" + i, e); } return array; }