Hello Igniters!

When deserializing Externalizable cache entry it's impossible to use
ObjectInput#available method for checking is there anything left to
read in buffer. This is because OptimizedObjectInputStream#available
always returns -1 (hard-coded).

Does anyone know the reasons why this method is not fully implemented?
Is it acceptable to extend GridDataInput with method available() and
implement it by calling available() from underlying input stream?

I've faced with such problem when I tried to put additional field into
GridCacheSetHeader class. It should be able to read both the old and
new versions of this class, so, currently, I have to catch
EOFException to safely read the old one.

@Override public void readExternal(ObjectInput in) throws IOException {
    oldField = in.readInt();
    ...
    try {
        newField = in.readInt();
    }
    catch (EOFException e) {
        newField = DEFAULT_VALUE;
    }
}

With available() method this code will look like

@Override public void readExternal(ObjectInput in) throws IOException {
    oldField = in.readInt();
    ...
    if (in.available() > 0)
        newField = in.readInt();
    else
        newField = DEFAULT_VALUE;
}

Which case is preferred – to catch EOFException or to implement
available() at GridDataInput which looks obsolete?

Reply via email to