use of java.io.InvalidObjectException in project guava by hceylan.
the class ImmutableSetMultimap method readObject.
@GwtIncompatible("java.io.ObjectInputStream")
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
stream.defaultReadObject();
int keyCount = stream.readInt();
if (keyCount < 0) {
throw new InvalidObjectException("Invalid key count " + keyCount);
}
ImmutableMap.Builder<Object, ImmutableSet<Object>> builder = ImmutableMap.builder();
int tmpSize = 0;
for (int i = 0; i < keyCount; i++) {
Object key = stream.readObject();
int valueCount = stream.readInt();
if (valueCount <= 0) {
throw new InvalidObjectException("Invalid value count " + valueCount);
}
Object[] array = new Object[valueCount];
for (int j = 0; j < valueCount; j++) {
array[j] = stream.readObject();
}
ImmutableSet<Object> valueSet = ImmutableSet.copyOf(array);
if (valueSet.size() != array.length) {
throw new InvalidObjectException("Duplicate key-value pairs exist for key " + key);
}
builder.put(key, valueSet);
tmpSize += valueCount;
}
ImmutableMap<Object, ImmutableSet<Object>> tmpMap;
try {
tmpMap = builder.build();
} catch (IllegalArgumentException e) {
throw (InvalidObjectException) new InvalidObjectException(e.getMessage()).initCause(e);
}
FieldSettersHolder.MAP_FIELD_SETTER.set(this, tmpMap);
FieldSettersHolder.SIZE_FIELD_SETTER.set(this, tmpSize);
}
use of java.io.InvalidObjectException in project hibernate-orm by hibernate.
the class StatefulPersistenceContext method deserialize.
/**
* Used by the owning session to explicitly control deserialization of the persistence context.
*
* @param ois The stream from which the persistence context should be read
* @param session The owning session
*
* @return The deserialized StatefulPersistenceContext
*
* @throws IOException deserialization errors.
* @throws ClassNotFoundException deserialization errors.
*/
public static StatefulPersistenceContext deserialize(ObjectInputStream ois, SessionImplementor session) throws IOException, ClassNotFoundException {
final boolean tracing = LOG.isTraceEnabled();
if (tracing) {
LOG.trace("Deserializing persistence-context");
}
final StatefulPersistenceContext rtn = new StatefulPersistenceContext(session);
SessionFactoryImplementor sfi = session.getFactory();
try {
rtn.defaultReadOnly = ois.readBoolean();
// todo : we can actually just determine this from the incoming EntityEntry-s
rtn.hasNonReadOnlyEntities = ois.readBoolean();
int count = ois.readInt();
if (tracing) {
LOG.trace("Starting deserialization of [" + count + "] entitiesByKey entries");
}
rtn.entitiesByKey = new HashMap<>(count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count);
for (int i = 0; i < count; i++) {
rtn.entitiesByKey.put(EntityKey.deserialize(ois, sfi), ois.readObject());
}
count = ois.readInt();
if (tracing) {
LOG.trace("Starting deserialization of [" + count + "] entitiesByUniqueKey entries");
}
rtn.entitiesByUniqueKey = new HashMap<>(count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count);
for (int i = 0; i < count; i++) {
rtn.entitiesByUniqueKey.put(EntityUniqueKey.deserialize(ois, session), ois.readObject());
}
count = ois.readInt();
if (tracing) {
LOG.trace("Starting deserialization of [" + count + "] proxiesByKey entries");
}
// noinspection unchecked
rtn.proxiesByKey = new ConcurrentReferenceHashMap<>(count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count, .75f, 1, ConcurrentReferenceHashMap.ReferenceType.STRONG, ConcurrentReferenceHashMap.ReferenceType.WEAK, null);
for (int i = 0; i < count; i++) {
final EntityKey ek = EntityKey.deserialize(ois, sfi);
final Object proxy = ois.readObject();
if (proxy instanceof HibernateProxy) {
((HibernateProxy) proxy).getHibernateLazyInitializer().setSession(session);
rtn.proxiesByKey.put(ek, proxy);
} else {
// otherwise, the proxy was pruned during the serialization process
if (tracing) {
LOG.trace("Encountered pruned proxy");
}
}
}
count = ois.readInt();
if (tracing) {
LOG.trace("Starting deserialization of [" + count + "] entitySnapshotsByKey entries");
}
rtn.entitySnapshotsByKey = new HashMap<>(count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count);
for (int i = 0; i < count; i++) {
rtn.entitySnapshotsByKey.put(EntityKey.deserialize(ois, sfi), ois.readObject());
}
rtn.entityEntryContext = EntityEntryContext.deserialize(ois, rtn);
count = ois.readInt();
if (tracing) {
LOG.trace("Starting deserialization of [" + count + "] collectionsByKey entries");
}
rtn.collectionsByKey = new HashMap<>(count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count);
for (int i = 0; i < count; i++) {
rtn.collectionsByKey.put(CollectionKey.deserialize(ois, session), (PersistentCollection) ois.readObject());
}
count = ois.readInt();
if (tracing) {
LOG.trace("Starting deserialization of [" + count + "] collectionEntries entries");
}
rtn.collectionEntries = IdentityMap.instantiateSequenced(count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count);
for (int i = 0; i < count; i++) {
final PersistentCollection pc = (PersistentCollection) ois.readObject();
final CollectionEntry ce = CollectionEntry.deserialize(ois, session);
pc.setCurrentSession(session);
rtn.collectionEntries.put(pc, ce);
}
count = ois.readInt();
if (tracing) {
LOG.trace("Starting deserialization of [" + count + "] arrayHolders entries");
}
rtn.arrayHolders = new IdentityHashMap<>(count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count);
for (int i = 0; i < count; i++) {
rtn.arrayHolders.put(ois.readObject(), (PersistentCollection) ois.readObject());
}
count = ois.readInt();
if (tracing) {
LOG.trace("Starting deserialization of [" + count + "] nullifiableEntityKey entries");
}
rtn.nullifiableEntityKeys = new HashSet<>();
for (int i = 0; i < count; i++) {
rtn.nullifiableEntityKeys.add(EntityKey.deserialize(ois, sfi));
}
} catch (HibernateException he) {
throw new InvalidObjectException(he.getMessage());
}
return rtn;
}
use of java.io.InvalidObjectException in project fqrouter by fqrouter.
the class DNSName method readObject.
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
byte[] bytes;
if ((bytes = this.bytes) == null)
throw new InvalidObjectException("bytes: null");
if (bytes.length <= 0 || lengthOf(bytes, 0) != bytes.length)
throw new InvalidObjectException("Bad resource name");
}
use of java.io.InvalidObjectException in project fqrouter by fqrouter.
the class DNSRecord method readObject.
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
DNSName rName;
byte[] rDataBytes;
if ((rName = this.rName) == null)
throw new InvalidObjectException("rName: null");
if ((rDataBytes = this.rDataBytes) == null)
throw new InvalidObjectException("rDataBytes: null");
if ((rDataBytes.length & ~RDATA_LEN_MASK) != 0)
throw new InvalidObjectException("rDataBytes length: " + UnsignedInt.toString(rDataBytes.length, false));
}
use of java.io.InvalidObjectException in project Stringlate by LonamiWebs.
the class TranslateActivity method getCreateExportRoot.
private File getCreateExportRoot() {
String path;
try {
path = getString(R.string.app_name) + "/" + mRepo.toOwnerRepo();
} catch (InvalidObjectException ignored) {
path = getString(R.string.app_name);
}
File root = new File(Environment.getExternalStorageDirectory(), path);
if (root.isDirectory())
root.mkdirs();
return root;
}
Aggregations