private BlockUnmarshaller getBlockUnmarshaller() { final BlockUnmarshaller blockUnmarshaller = this.blockUnmarshaller; return blockUnmarshaller == null ? this.blockUnmarshaller = new BlockUnmarshaller(this) : blockUnmarshaller; }
void readBlockHeader(int leadByte) throws IOException { switch (leadByte) { case Protocol.ID_START_BLOCK_SMALL: remaining = riverUnmarshaller.readUnsignedByte(); return; case Protocol.ID_START_BLOCK_MEDIUM: remaining = riverUnmarshaller.readUnsignedShort(); return; case Protocol.ID_START_BLOCK_LARGE: final int len = riverUnmarshaller.readInt(); if (len < 0) { throw new StreamCorruptedException("Invalid block length"); } remaining = len; return; case Protocol.ID_END_BLOCK_DATA: remaining = -1; return; default: throw badLeadByte(leadByte); } }
public int read(final byte[] b) throws IOException { return read(b, 0, b.length); }
public <T> T readObject(final Class<T> type) throws ClassNotFoundException, IOException { final Object obj = readObject(false); try { return type.cast(obj); } catch (ClassCastException e) { throw wrongType(e, type, obj.getClass()); } }
void readToEndBlockData() throws IOException, ClassNotFoundException { for (;;) { while (remaining > 0) { skipBytes(remaining); } final int b = riverUnmarshaller.read(); switch (b) { case -1: remaining = -1; return; case Protocol.ID_END_BLOCK_DATA: remaining = -1; return; case Protocol.ID_START_BLOCK_SMALL: case Protocol.ID_START_BLOCK_MEDIUM: case Protocol.ID_START_BLOCK_LARGE: readBlockHeader(b); break; default: // consume object... or whatever riverUnmarshaller.doReadObject(b, false, true); break; } } }
blockUnmarshaller.readToEndBlockData(); blockUnmarshaller.unblock(); blockUnmarshaller.readToEndBlockData(); blockUnmarshaller.unblock(); } else { // typeid == ID_SERIALIZABLE_CLASS if (obj != null) info.callReadObject(obj, objectInputStream); objectInputStream.finish(restoreState); blockUnmarshaller.restore(objectInputStream.getRestoreIdx()); blockUnmarshaller.readToEndBlockData(); blockUnmarshaller.unblock();
instanceCache.add(obj); obj.readExternal(blockUnmarshaller); blockUnmarshaller.readToEndBlockData(); blockUnmarshaller.unblock(); final Object resolvedObject = objectResolver.readResolve(serializableClass.hasReadResolve() ? serializableClass.callReadResolve(obj) : obj); if (unshared) { obj = externalizer.createExternal(type, blockUnmarshaller); instanceCache.set(idx, obj); blockUnmarshaller.readToEndBlockData(); blockUnmarshaller.unblock(); final Object resolvedObject = objectResolver.readResolve(serializableClass.hasReadResolve() ? serializableClass.callReadResolve(obj) : obj); if (unshared) {
public long readLong() throws IOException { if (remaining < 8) { return (long) readUnsignedByte() << 56L | (long) readUnsignedByte() << 48L | (long) readUnsignedByte() << 40L | (long) readUnsignedByte() << 32L | (long) readUnsignedByte() << 24L | (long) readUnsignedByte() << 16L | (long) readUnsignedByte() << 8L | (long) readUnsignedByte(); } else { remaining -= 8; return riverUnmarshaller.readLong(); } }
public int readUnsignedByte() throws IOException { while (remaining == 0) { readBlockHeader(riverUnmarshaller.readUnsignedByte()); } if (remaining == -1) { throw new EOFException(); } remaining--; return riverUnmarshaller.readUnsignedByte(); }
public float readFloat() throws IOException { return Float.intBitsToFloat(readInt()); }
public double readDouble() throws IOException { return Double.longBitsToDouble(readLong()); }
public Object readObject() throws ClassNotFoundException, IOException { return readObject(false); }
blockUnmarshaller.readToEndBlockData(); blockUnmarshaller.unblock(); blockUnmarshaller.readToEndBlockData(); blockUnmarshaller.unblock(); } else { // typeid == ID_SERIALIZABLE_CLASS if (obj != null) info.callReadObject(obj, objectInputStream); objectInputStream.finish(restoreState); blockUnmarshaller.restore(objectInputStream.getRestoreIdx()); blockUnmarshaller.readToEndBlockData(); blockUnmarshaller.unblock();
public <T> T readObjectUnshared(final Class<T> type) throws ClassNotFoundException, IOException { final Object obj = readObject(true); try { return type.cast(obj); } catch (ClassCastException e) { throw wrongType(e, type, obj.getClass()); } }
private Class<?> readClassTableClass() throws IOException, ClassNotFoundException { if (version == 1) { final BlockUnmarshaller blockUnmarshaller = getBlockUnmarshaller(); final Class<?> type = classTable.readClass(blockUnmarshaller); blockUnmarshaller.readToEndBlockData(); blockUnmarshaller.unblock(); return type; } else { // v2 does not require a block for this return classTable.readClass(this); } }
public int readInt() throws IOException { if (remaining < 4) { return readUnsignedByte() << 24 | readUnsignedByte() << 16 | readUnsignedByte() << 8 | readUnsignedByte(); } else { remaining -= 4; return riverUnmarshaller.readInt(); } }
public boolean readBoolean() throws IOException { while (remaining == 0) { readBlockHeader(riverUnmarshaller.readUnsignedByte()); } if (remaining == -1) { throw new EOFException(); } remaining--; return riverUnmarshaller.readBoolean(); }
public String readUTF() throws IOException { final int len = readInt(); if (len < 0) { throw new StreamCorruptedException("Invalid string length"); } return UTFUtils.readUTFBytes(this, len); }
public double readDouble() throws IOException { return Double.longBitsToDouble(readLong()); }
public Object readObjectUnshared() throws ClassNotFoundException, IOException { return readObject(true); }