Java Code Examples for java.io.StreamCorruptedException

The following examples show how to use java.io.StreamCorruptedException. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: jdk8u_jdk   Source File: StreamRemoteCall.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an output stream (may put out header information
 * relating to the success of the call).
 * @param success If true, indicates normal return, else indicates
 * exceptional return.
 * @exception StreamCorruptedException If result stream previously
 * acquired
 * @exception IOException For any other problem with I/O.
 */
public ObjectOutput getResultStream(boolean success) throws IOException {
    /* make sure result code only marshaled once. */
    if (resultStarted)
        throw new StreamCorruptedException("result already in progress");
    else
        resultStarted = true;

    // write out return header
    // return header, part 1 (read by Transport)
    DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
    wr.writeByte(TransportConstants.Return);// transport op
    getOutputStream(true);  // creates a MarshalOutputStream
    // return header, part 2 (read by client-side RemoteCall)
    if (success)            //
        out.writeByte(TransportConstants.NormalReturn);
    else
        out.writeByte(TransportConstants.ExceptionalReturn);
    out.writeID();          // write id for gcAck
    return out;
}
 
Example 2
Source Project: jdk1.8-source-analysis   Source File: Ser.java    License: Apache License 2.0 6 votes vote down vote up
private static Object readInternal(byte type, ObjectInput in) throws IOException, ClassNotFoundException {
    switch (type) {
        case DURATION_TYPE: return Duration.readExternal(in);
        case INSTANT_TYPE: return Instant.readExternal(in);
        case LOCAL_DATE_TYPE: return LocalDate.readExternal(in);
        case LOCAL_DATE_TIME_TYPE: return LocalDateTime.readExternal(in);
        case LOCAL_TIME_TYPE: return LocalTime.readExternal(in);
        case ZONE_DATE_TIME_TYPE: return ZonedDateTime.readExternal(in);
        case ZONE_OFFSET_TYPE: return ZoneOffset.readExternal(in);
        case ZONE_REGION_TYPE: return ZoneRegion.readExternal(in);
        case OFFSET_TIME_TYPE: return OffsetTime.readExternal(in);
        case OFFSET_DATE_TIME_TYPE: return OffsetDateTime.readExternal(in);
        case YEAR_TYPE: return Year.readExternal(in);
        case YEAR_MONTH_TYPE: return YearMonth.readExternal(in);
        case MONTH_DAY_TYPE: return MonthDay.readExternal(in);
        case PERIOD_TYPE: return Period.readExternal(in);
        default:
            throw new StreamCorruptedException("Unknown serialized type");
    }
}
 
Example 3
Source Project: hottub   Source File: StreamRemoteCall.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an output stream (may put out header information
 * relating to the success of the call).
 * @param success If true, indicates normal return, else indicates
 * exceptional return.
 * @exception StreamCorruptedException If result stream previously
 * acquired
 * @exception IOException For any other problem with I/O.
 */
public ObjectOutput getResultStream(boolean success) throws IOException {
    /* make sure result code only marshaled once. */
    if (resultStarted)
        throw new StreamCorruptedException("result already in progress");
    else
        resultStarted = true;

    // write out return header
    // return header, part 1 (read by Transport)
    DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
    wr.writeByte(TransportConstants.Return);// transport op
    getOutputStream(true);  // creates a MarshalOutputStream
    // return header, part 2 (read by client-side RemoteCall)
    if (success)            //
        out.writeByte(TransportConstants.NormalReturn);
    else
        out.writeByte(TransportConstants.ExceptionalReturn);
    out.writeID();          // write id for gcAck
    return out;
}
 
Example 4
Source Project: dubbox-hystrix   Source File: CompactedObjectInputStream.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected ObjectStreamClass readClassDescriptor() throws IOException,ClassNotFoundException
{
	int type = read();
	if( type < 0 )
		throw new EOFException();
	switch( type )
	{
		case 0:
			return super.readClassDescriptor();
		case 1:
			Class<?> clazz = loadClass(readUTF());
			return ObjectStreamClass.lookup(clazz);
		default:
			throw new StreamCorruptedException("Unexpected class descriptor type: " + type);
	}
}
 
Example 5
/**
 * Returns an output stream (may put out header information
 * relating to the success of the call).
 * @param success If true, indicates normal return, else indicates
 * exceptional return.
 * @exception StreamCorruptedException If result stream previously
 * acquired
 * @exception IOException For any other problem with I/O.
 */
public ObjectOutput getResultStream(boolean success) throws IOException {
    /* make sure result code only marshaled once. */
    if (resultStarted)
        throw new StreamCorruptedException("result already in progress");
    else
        resultStarted = true;

    // write out return header
    // return header, part 1 (read by Transport)
    DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
    wr.writeByte(TransportConstants.Return);// transport op
    getOutputStream(true);  // creates a MarshalOutputStream
    // return header, part 2 (read by client-side RemoteCall)
    if (success)            //
        out.writeByte(TransportConstants.NormalReturn);
    else
        out.writeByte(TransportConstants.ExceptionalReturn);
    out.writeID();          // write id for gcAck
    return out;
}
 
Example 6
Source Project: jdk8u-jdk   Source File: Ser.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static Object readInternal(byte type, ObjectInput in) throws IOException, ClassNotFoundException {
    switch (type) {
        case DURATION_TYPE: return Duration.readExternal(in);
        case INSTANT_TYPE: return Instant.readExternal(in);
        case LOCAL_DATE_TYPE: return LocalDate.readExternal(in);
        case LOCAL_DATE_TIME_TYPE: return LocalDateTime.readExternal(in);
        case LOCAL_TIME_TYPE: return LocalTime.readExternal(in);
        case ZONE_DATE_TIME_TYPE: return ZonedDateTime.readExternal(in);
        case ZONE_OFFSET_TYPE: return ZoneOffset.readExternal(in);
        case ZONE_REGION_TYPE: return ZoneRegion.readExternal(in);
        case OFFSET_TIME_TYPE: return OffsetTime.readExternal(in);
        case OFFSET_DATE_TIME_TYPE: return OffsetDateTime.readExternal(in);
        case YEAR_TYPE: return Year.readExternal(in);
        case YEAR_MONTH_TYPE: return YearMonth.readExternal(in);
        case MONTH_DAY_TYPE: return MonthDay.readExternal(in);
        case PERIOD_TYPE: return Period.readExternal(in);
        default:
            throw new StreamCorruptedException("Unknown serialized type");
    }
}
 
Example 7
Source Project: JDKSourceCode1.8   Source File: InputStreamHook.java    License: MIT License 6 votes vote down vote up
public void readData(InputStreamHook stream) throws IOException {
    org.omg.CORBA.ORB orb = stream.getOrbStream().orb();
    if ((orb == null) ||
            !(orb instanceof com.sun.corba.se.spi.orb.ORB)) {
        throw new StreamCorruptedException(
                             "Default data must be read first");
    }
    ORBVersion clientOrbVersion =
        ((com.sun.corba.se.spi.orb.ORB)orb).getORBVersion();

    // Fix Date interop bug. For older versions of the ORB don't do
    // anything for readData(). Before this used to throw
    // StreamCorruptedException for older versions of the ORB where
    // calledDefaultWriteObject always returns true.
    if ((ORBVersionFactory.getPEORB().compareTo(clientOrbVersion) <= 0) ||
            (clientOrbVersion.equals(ORBVersionFactory.getFOREIGN()))) {
        // XXX I18N and logging needed.
        throw new StreamCorruptedException("Default data must be read first");
    }
}
 
Example 8
public void readData(InputStreamHook stream) throws IOException {
    org.omg.CORBA.ORB orb = stream.getOrbStream().orb();
    if ((orb == null) ||
            !(orb instanceof com.sun.corba.se.spi.orb.ORB)) {
        throw new StreamCorruptedException(
                             "Default data must be read first");
    }
    ORBVersion clientOrbVersion =
        ((com.sun.corba.se.spi.orb.ORB)orb).getORBVersion();

    // Fix Date interop bug. For older versions of the ORB don't do
    // anything for readData(). Before this used to throw
    // StreamCorruptedException for older versions of the ORB where
    // calledDefaultWriteObject always returns true.
    if ((ORBVersionFactory.getPEORB().compareTo(clientOrbVersion) <= 0) ||
            (clientOrbVersion.equals(ORBVersionFactory.getFOREIGN()))) {
        // XXX I18N and logging needed.
        throw new StreamCorruptedException("Default data must be read first");
    }
}
 
Example 9
Source Project: Skript   Source File: YggXMLInputStream.java    License: GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("null")
private Class<?> getType(String s) throws StreamCorruptedException {
	int dim = 0;
	while (s.endsWith("[]")) {
		s = "" + s.substring(0, s.length() - 2);
		dim++;
	}
	Class<?> c;
	final Tag t = Tag.byName(s);
	if (t != null)
		c = t.c;
	else
		c = yggdrasil.getClass(s);
	if (c == null)
		throw new StreamCorruptedException("Invalid type " + s);
	if (dim == 0)
		return c;
	while (dim-- > 0)
		c = Array.newInstance(c, 0).getClass();
	return c;
}
 
Example 10
Source Project: jdk8u-jdk   Source File: StreamRemoteCall.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an output stream (may put out header information
 * relating to the success of the call).
 * @param success If true, indicates normal return, else indicates
 * exceptional return.
 * @exception StreamCorruptedException If result stream previously
 * acquired
 * @exception IOException For any other problem with I/O.
 */
public ObjectOutput getResultStream(boolean success) throws IOException {
    /* make sure result code only marshaled once. */
    if (resultStarted)
        throw new StreamCorruptedException("result already in progress");
    else
        resultStarted = true;

    // write out return header
    // return header, part 1 (read by Transport)
    DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
    wr.writeByte(TransportConstants.Return);// transport op
    getOutputStream(true);  // creates a MarshalOutputStream
    // return header, part 2 (read by client-side RemoteCall)
    if (success)            //
        out.writeByte(TransportConstants.NormalReturn);
    else
        out.writeByte(TransportConstants.ExceptionalReturn);
    out.writeID();          // write id for gcAck
    return out;
}
 
Example 11
private long approximateLastIndex(int cycle, SingleChronicleQueue queue,
                                  StoreTailer tailer) {
    try (SingleChronicleQueueStore wireStore = queue.storeForCycle(cycle, queue.epoch(), false, null)) {
        if (wireStore == null) {
            return noIndex;
        }

        long baseIndex = rollCycle.toIndex(cycle, 0);

        tailer.moveToIndex(baseIndex);

        long seq = wireStore.sequenceForPosition(tailer, Long.MAX_VALUE, false);
        long sequenceNumber = seq + 1;
        long index = rollCycle.toIndex(cycle, sequenceNumber);

        int cycleOfIndex = rollCycle.toCycle(index);
        if (cycleOfIndex != cycle) {
            throw new IllegalStateException(
                    "Expected cycle " + cycle + " but got " + cycleOfIndex);
        }

        return index;
    } catch (StreamCorruptedException | UnrecoverableTimeoutException e) {
        throw new IllegalStateException(e);
    }
}
 
Example 12
/**
 * Returns an output stream (may put out header information
 * relating to the success of the call).
 * @param success If true, indicates normal return, else indicates
 * exceptional return.
 * @exception StreamCorruptedException If result stream previously
 * acquired
 * @exception IOException For any other problem with I/O.
 */
public ObjectOutput getResultStream(boolean success) throws IOException {
    /* make sure result code only marshaled once. */
    if (resultStarted)
        throw new StreamCorruptedException("result already in progress");
    else
        resultStarted = true;

    // write out return header
    // return header, part 1 (read by Transport)
    DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
    wr.writeByte(TransportConstants.Return);// transport op
    getOutputStream(true);  // creates a MarshalOutputStream
    // return header, part 2 (read by client-side RemoteCall)
    if (success)            //
        out.writeByte(TransportConstants.NormalReturn);
    else
        out.writeByte(TransportConstants.ExceptionalReturn);
    out.writeID();          // write id for gcAck
    return out;
}
 
Example 13
Source Project: openjdk-jdk9   Source File: Ser.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static Object readInternal(byte type, ObjectInput in) throws IOException, ClassNotFoundException {
    switch (type) {
        case DURATION_TYPE: return Duration.readExternal(in);
        case INSTANT_TYPE: return Instant.readExternal(in);
        case LOCAL_DATE_TYPE: return LocalDate.readExternal(in);
        case LOCAL_DATE_TIME_TYPE: return LocalDateTime.readExternal(in);
        case LOCAL_TIME_TYPE: return LocalTime.readExternal(in);
        case ZONE_DATE_TIME_TYPE: return ZonedDateTime.readExternal(in);
        case ZONE_OFFSET_TYPE: return ZoneOffset.readExternal(in);
        case ZONE_REGION_TYPE: return ZoneRegion.readExternal(in);
        case OFFSET_TIME_TYPE: return OffsetTime.readExternal(in);
        case OFFSET_DATE_TIME_TYPE: return OffsetDateTime.readExternal(in);
        case YEAR_TYPE: return Year.readExternal(in);
        case YEAR_MONTH_TYPE: return YearMonth.readExternal(in);
        case MONTH_DAY_TYPE: return MonthDay.readExternal(in);
        case PERIOD_TYPE: return Period.readExternal(in);
        default:
            throw new StreamCorruptedException("Unknown serialized type");
    }
}
 
Example 14
Source Project: openjdk-jdk8u-backup   Source File: Ser.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static Object readInternal(byte type, ObjectInput in) throws IOException, ClassNotFoundException {
    switch (type) {
        case DURATION_TYPE: return Duration.readExternal(in);
        case INSTANT_TYPE: return Instant.readExternal(in);
        case LOCAL_DATE_TYPE: return LocalDate.readExternal(in);
        case LOCAL_DATE_TIME_TYPE: return LocalDateTime.readExternal(in);
        case LOCAL_TIME_TYPE: return LocalTime.readExternal(in);
        case ZONE_DATE_TIME_TYPE: return ZonedDateTime.readExternal(in);
        case ZONE_OFFSET_TYPE: return ZoneOffset.readExternal(in);
        case ZONE_REGION_TYPE: return ZoneRegion.readExternal(in);
        case OFFSET_TIME_TYPE: return OffsetTime.readExternal(in);
        case OFFSET_DATE_TIME_TYPE: return OffsetDateTime.readExternal(in);
        case YEAR_TYPE: return Year.readExternal(in);
        case YEAR_MONTH_TYPE: return YearMonth.readExternal(in);
        case MONTH_DAY_TYPE: return MonthDay.readExternal(in);
        case PERIOD_TYPE: return Period.readExternal(in);
        default:
            throw new StreamCorruptedException("Unknown serialized type");
    }
}
 
Example 15
Source Project: jdk8u-jdk   Source File: StreamRemoteCall.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an output stream (may put out header information
 * relating to the success of the call).
 * @param success If true, indicates normal return, else indicates
 * exceptional return.
 * @exception StreamCorruptedException If result stream previously
 * acquired
 * @exception IOException For any other problem with I/O.
 */
public ObjectOutput getResultStream(boolean success) throws IOException {
    /* make sure result code only marshaled once. */
    if (resultStarted)
        throw new StreamCorruptedException("result already in progress");
    else
        resultStarted = true;

    // write out return header
    // return header, part 1 (read by Transport)
    DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
    wr.writeByte(TransportConstants.Return);// transport op
    getOutputStream(true);  // creates a MarshalOutputStream
    // return header, part 2 (read by client-side RemoteCall)
    if (success)            //
        out.writeByte(TransportConstants.NormalReturn);
    else
        out.writeByte(TransportConstants.ExceptionalReturn);
    out.writeID();          // write id for gcAck
    return out;
}
 
Example 16
Source Project: openjdk-8   Source File: Ser.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Object readInternal(byte type, DataInput in) throws IOException, ClassNotFoundException {
    switch (type) {
        case ZRULES:
            return ZoneRules.readExternal(in);
        case ZOT:
            return ZoneOffsetTransition.readExternal(in);
        case ZOTRULE:
            return ZoneOffsetTransitionRule.readExternal(in);
        default:
            throw new StreamCorruptedException("Unknown serialized type");
    }
}
 
Example 17
Source Project: openjdk-jdk8u   Source File: MBeanInfo.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Deserializes an {@link MBeanInfo} from an {@link ObjectInputStream}.
 * @serialData
 * For compatibility reasons, an object of this class is deserialized as follows.
 * <p>
 * The method {@link ObjectInputStream#defaultReadObject defaultReadObject()}
 * is called first to deserialize the object except the field
 * {@code descriptor}, which is not serialized in the default way. Then the method
 * {@link ObjectInputStream#read read()} is called to read a byte, the field
 * {@code descriptor} is deserialized according to the value of the byte value:
 *    <ul>
 *    <li>1. The method {@link ObjectInputStream#readObject readObject()}
 *       is called twice to obtain the field names (a {@code String[]}) and
 *       the field values (a {@code Object[]}) of the {@code descriptor}.
 *       The two obtained values then are used to construct
 *       an {@link ImmutableDescriptor} instance for the field
 *       {@code descriptor};</li>
 *    <li>0. The value for the field {@code descriptor} is obtained directly
 *       by calling the method {@link ObjectInputStream#readObject readObject()}.
 *       If the obtained value is null, the field {@code descriptor} is set to
 *       {@link ImmutableDescriptor#EMPTY_DESCRIPTOR EMPTY_DESCRIPTOR};</li>
 *    <li>-1. This means that there is no byte to read and that the object is from
 *       an earlier version of the JMX API. The field {@code descriptor} is set to
 *       {@link ImmutableDescriptor#EMPTY_DESCRIPTOR EMPTY_DESCRIPTOR}.</li>
 *    <li>Any other value. A {@link StreamCorruptedException} is thrown.</li>
 *    </ul>
 *
 * @since 1.6
 */

private void readObject(ObjectInputStream in)
    throws IOException, ClassNotFoundException {

    in.defaultReadObject();

    switch (in.read()) {
    case 1:
        final String[] names = (String[])in.readObject();

        final Object[] values = (Object[]) in.readObject();
        descriptor = (names.length == 0) ?
            ImmutableDescriptor.EMPTY_DESCRIPTOR :
            new ImmutableDescriptor(names, values);

        break;
    case 0:
        descriptor = (Descriptor)in.readObject();

        if (descriptor == null) {
            descriptor = ImmutableDescriptor.EMPTY_DESCRIPTOR;
        }

        break;
    case -1: // from an earlier version of the JMX API
        descriptor = ImmutableDescriptor.EMPTY_DESCRIPTOR;

        break;
    default:
        throw new StreamCorruptedException("Got unexpected byte.");
    }
}
 
Example 18
Source Project: lazythreetenbp   Source File: LazyZoneRulesProvider.java    License: Apache License 2.0 5 votes vote down vote up
private ZoneRules loadData(InputStream in) throws Exception {
    DataInputStream dis = new DataInputStream(in);
    if (dis.readByte() != 1) {
        throw new StreamCorruptedException("File format not recognised");
    }

    String groupId = dis.readUTF();
    if (!"TZDB-ZONE".equals(groupId)) {
        throw new StreamCorruptedException("File format not recognised");
    }
    return ZoneRulesCompat.readZoneRules(dis);
}
 
Example 19
void readFields(java.util.Map fieldToValueMap)
    throws InvalidClassException, StreamCorruptedException,
           ClassNotFoundException, IOException {

    if (mustUseRemoteValueMembers()) {
        inputRemoteMembersForReadFields(fieldToValueMap);
    } else
        inputCurrentClassFieldsForReadFields(fieldToValueMap);
}
 
Example 20
Source Project: Bytecoder   Source File: Beans.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Loader must be non-null;
 */

public ObjectInputStreamWithLoader(InputStream in, ClassLoader loader)
        throws IOException, StreamCorruptedException {

    super(in);
    if (loader == null) {
        throw new IllegalArgumentException("Illegal null argument to ObjectInputStreamWithLoader");
    }
    this.loader = loader;
}
 
Example 21
Source Project: JDKSourceCode1.8   Source File: Ser.java    License: MIT License 5 votes vote down vote up
private static Object readInternal(byte type, DataInput in) throws IOException, ClassNotFoundException {
    switch (type) {
        case ZRULES:
            return ZoneRules.readExternal(in);
        case ZOT:
            return ZoneOffsetTransition.readExternal(in);
        case ZOTRULE:
            return ZoneOffsetTransitionRule.readExternal(in);
        default:
            throw new StreamCorruptedException("Unknown serialized type");
    }
}
 
Example 22
Source Project: jenetics   Source File: Serial.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void writeExternal(final ObjectOutput out) throws IOException {
	out.writeByte(_type);
	switch (_type) {
		case PROGRAM_CHROMOSOME: ((ProgramChromosome)_object).write(out); break;
		default:
			throw new StreamCorruptedException("Unknown serialized type.");
	}
}
 
Example 23
Source Project: Skript   Source File: Yggdrasil.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void excessiveField(final Object o, final FieldContext field) throws StreamCorruptedException {
	for (final FieldHandler h : fieldHandlers) {
		if (h.excessiveField(o, field))
			return;
	}
	throw new StreamCorruptedException("Excessive field " + field.id + " in class " + o.getClass().getCanonicalName() + " was not handled");
}
 
Example 24
Source Project: dragonwell8_jdk   Source File: Ser.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Object readInternal(byte type, ObjectInput in) throws IOException, ClassNotFoundException {
    switch (type) {
        case CHRONO_TYPE: return AbstractChronology.readExternal(in);
        case CHRONO_LOCAL_DATE_TIME_TYPE: return ChronoLocalDateTimeImpl.readExternal(in);
        case CHRONO_ZONE_DATE_TIME_TYPE: return ChronoZonedDateTimeImpl.readExternal(in);
        case JAPANESE_DATE_TYPE:  return JapaneseDate.readExternal(in);
        case JAPANESE_ERA_TYPE: return JapaneseEra.readExternal(in);
        case HIJRAH_DATE_TYPE: return HijrahDate.readExternal(in);
        case MINGUO_DATE_TYPE: return MinguoDate.readExternal(in);
        case THAIBUDDHIST_DATE_TYPE: return ThaiBuddhistDate.readExternal(in);
        case CHRONO_PERIOD_TYPE: return ChronoPeriodImpl.readExternal(in);
        default: throw new StreamCorruptedException("Unknown serialized type");
    }
}
 
Example 25
Source Project: dragonwell8_jdk   Source File: Ser.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Object readInternal(byte type, DataInput in) throws IOException, ClassNotFoundException {
    switch (type) {
        case ZRULES:
            return ZoneRules.readExternal(in);
        case ZOT:
            return ZoneOffsetTransition.readExternal(in);
        case ZOTRULE:
            return ZoneOffsetTransitionRule.readExternal(in);
        default:
            throw new StreamCorruptedException("Unknown serialized type");
    }
}
 
Example 26
Source Project: JobX   Source File: CompactedObjectInputStream.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException {
    int type = read();
    if (type < 0)
        throw new EOFException();
    switch (type) {
        case 0:
            return super.readClassDescriptor();
        case 1:
            Class<?> clazz = loadClass(readUTF());
            return ObjectStreamClass.lookup(clazz);
        default:
            throw new StreamCorruptedException("Unexpected class descriptor type: " + type);
    }
}
 
Example 27
Source Project: Skript   Source File: WorldGuard7FAWEHook.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void deserialize(final Fields fields) throws StreamCorruptedException, NotSerializableException {
    final String r = fields.getAndRemoveObject("region", String.class);
    fields.setFields(this);
    RegionManager regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world));
    final ProtectedRegion region = regionManager.getRegion(r);
    if (region == null)
        throw new StreamCorruptedException("Invalid region " + r + " in world " + world);
    this.region = region;
}
 
Example 28
Source Project: jdk8u_jdk   Source File: Beans.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Loader must be non-null;
 */

public ObjectInputStreamWithLoader(InputStream in, ClassLoader loader)
        throws IOException, StreamCorruptedException {

    super(in);
    if (loader == null) {
        throw new IllegalArgumentException("Illegal null argument to ObjectInputStreamWithLoader");
    }
    this.loader = loader;
}
 
Example 29
/**
 * Deserializes an {@link MBeanFeatureInfo} from an {@link ObjectInputStream}.
 * @serialData
 * For compatibility reasons, an object of this class is deserialized as follows.
 * <p>
 * The method {@link ObjectInputStream#defaultReadObject defaultReadObject()}
 * is called first to deserialize the object except the field
 * {@code descriptor}, which is not serialized in the default way. Then the method
 * {@link ObjectInputStream#read read()} is called to read a byte, the field
 * {@code descriptor} is deserialized according to the value of the byte value:
 *    <ul>
 *    <li>1. The method {@link ObjectInputStream#readObject readObject()}
 *       is called twice to obtain the field names (a {@code String[]}) and
 *       the field values (a {@code Object[]}) of the {@code descriptor}.
 *       The two obtained values then are used to construct
 *       an {@link ImmutableDescriptor} instance for the field
 *       {@code descriptor};</li>
 *    <li>0. The value for the field {@code descriptor} is obtained directly
 *       by calling the method {@link ObjectInputStream#readObject readObject()}.
 *       If the obtained value is null, the field {@code descriptor} is set to
 *       {@link ImmutableDescriptor#EMPTY_DESCRIPTOR EMPTY_DESCRIPTOR};</li>
 *    <li>-1. This means that there is no byte to read and that the object is from
 *       an earlier version of the JMX API. The field {@code descriptor} is set
 *       to {@link ImmutableDescriptor#EMPTY_DESCRIPTOR EMPTY_DESCRIPTOR}</li>
 *    <li>Any other value. A {@link StreamCorruptedException} is thrown.</li>
 *    </ul>
 *
 * @since 1.6
 */
private void readObject(ObjectInputStream in)
    throws IOException, ClassNotFoundException {

    in.defaultReadObject();

    switch (in.read()) {
    case 1:
        final String[] names = (String[])in.readObject();

        final Object[] values = (Object[]) in.readObject();
        descriptor = (names.length == 0) ?
            ImmutableDescriptor.EMPTY_DESCRIPTOR :
            new ImmutableDescriptor(names, values);

        break;
    case 0:
        descriptor = (Descriptor)in.readObject();

        if (descriptor == null) {
            descriptor = ImmutableDescriptor.EMPTY_DESCRIPTOR;
        }

        break;
    case -1: // from an earlier version of the JMX API
        descriptor = ImmutableDescriptor.EMPTY_DESCRIPTOR;

        break;
    default:
        throw new StreamCorruptedException("Got unexpected byte.");
    }
}
 
Example 30
Source Project: JDKSourceCode1.8   Source File: Beans.java    License: MIT License 5 votes vote down vote up
/**
 * Loader must be non-null;
 */

public ObjectInputStreamWithLoader(InputStream in, ClassLoader loader)
        throws IOException, StreamCorruptedException {

    super(in);
    if (loader == null) {
        throw new IllegalArgumentException("Illegal null argument to ObjectInputStreamWithLoader");
    }
    this.loader = loader;
}