Java Code Examples for java.io.StreamCorruptedException

The following are top voted examples for showing how to use java.io.StreamCorruptedException. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: EatDubbo   File: CompactedObjectInputStream.java   Source Code and License 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 2
Project: neoscada   File: ObjectSerializationInputStream.java   Source Code and License 6 votes vote down vote up
public Object readObject() throws ClassNotFoundException, IOException {
    int objectSize = in.readInt();
    if (objectSize <= 0) {
        throw new StreamCorruptedException("Invalid objectSize: " + objectSize);
    }
    if (objectSize > maxObjectSize) {
        throw new StreamCorruptedException("ObjectSize too big: " + objectSize + " (expected: <= " + maxObjectSize
                + ')');
    }

    IoBuffer buf = IoBuffer.allocate(objectSize + 4, false);
    buf.putInt(objectSize);
    in.readFully(buf.array(), 4, objectSize);
    buf.position(0);
    buf.limit(objectSize + 4);

    return buf.getObject(classLoader);
}
 
Example 3
Project: dubbo2   File: CompactedObjectInputStream.java   Source Code and License 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 4
Project: hekate   File: CodecUtils.java   Source Code and License 6 votes vote down vote up
/**
 * Reads a value that was encoded via {@link #writeVarLongUnsigned(long, DataOutput)}.
 *
 * @param in Data input.
 *
 * @return Value.
 *
 * @throws IOException if failed to read value.
 */
// Code borrowed from 'stream-lib' (Apache 2.0 license) - see https://github.com/addthis/stream-lib
public static long readVarLongUnsigned(DataInput in) throws IOException {
    long value = 0L;
    int i = 0;
    long b;

    while (((b = in.readByte()) & 0x80L) != 0) {
        value |= (b & 0x7F) << i;

        i += 7;

        if (i > 63) {
            throw new StreamCorruptedException("Variable length size is too long");
        }
    }

    return value | b << i;
}
 
Example 5
Project: hekate   File: CodecUtils.java   Source Code and License 6 votes vote down vote up
/**
 * Reads a value that was encoded via {@link #writeVarIntUnsigned(int, DataOutput)}.
 *
 * @param in Data input.
 *
 * @return Value.
 *
 * @throws IOException if failed to read value.
 */
// Code borrowed from 'stream-lib' (Apache 2.0 license) - see https://github.com/addthis/stream-lib
public static int readVarIntUnsigned(DataInput in) throws IOException {
    int value = 0;
    int i = 0;
    int b;

    while (((b = in.readByte()) & 0x80) != 0) {
        value |= (b & 0x7F) << i;

        i += 7;

        if (i > 35) {
            throw new StreamCorruptedException("Variable length size is too long");
        }
    }

    return value | b << i;
}
 
Example 6
Project: OpenJSharp   File: IIOPInputStream.java   Source Code and License 6 votes vote down vote up
private void skipCustomUsingFVD(ValueMember[] fields,
                                com.sun.org.omg.SendingContext.CodeBase sender)
                                throws InvalidClassException, StreamCorruptedException,
                                       ClassNotFoundException, IOException
{
    readFormatVersion();
    boolean calledDefaultWriteObject = readBoolean();

    if (calledDefaultWriteObject)
        throwAwayData(fields, sender);

    if (getStreamFormatVersion() == 2) {

        ((ValueInputStream)getOrbStream()).start_value();
        ((ValueInputStream)getOrbStream()).end_value();
    }
}
 
Example 7
Project: OpenJSharp   File: InputStreamHook.java   Source Code and 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
Project: OpenJSharp   File: Ser.java   Source Code and License 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 9
Project: OpenJSharp   File: StreamRemoteCall.java   Source Code and License 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 10
Project: dubbox-hystrix   File: CompactedObjectInputStream.java   Source Code and License 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 11
Project: jdk8u-jdk   File: Ser.java   Source Code and License 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 12
Project: jdk8u-jdk   File: StreamRemoteCall.java   Source Code and License 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 13
Project: openjdk-jdk10   File: IIOPInputStream.java   Source Code and License 6 votes vote down vote up
private boolean invokeObjectReader(ObjectStreamClass osc, Object obj, Class aclass)
    throws InvalidClassException, StreamCorruptedException,
           ClassNotFoundException, IOException
{
    try {
        return osc.invokeReadObject( obj, this ) ;
    } catch (InvocationTargetException e) {
        Throwable t = e.getTargetException();
        if (t instanceof ClassNotFoundException)
            throw (ClassNotFoundException)t;
        else if (t instanceof IOException)
            throw (IOException)t;
        else if (t instanceof RuntimeException)
            throw (RuntimeException) t;
        else if (t instanceof Error)
            throw (Error) t;
        else
            // XXX I18N, logging needed.
            throw new Error("internal error");
    }
}
 
Example 14
Project: openjdk-jdk10   File: IIOPInputStream.java   Source Code and License 6 votes vote down vote up
private void skipCustomUsingFVD(ValueMember[] fields,
                                com.sun.org.omg.SendingContext.CodeBase sender)
                                throws InvalidClassException, StreamCorruptedException,
                                       ClassNotFoundException, IOException
{
    readFormatVersion();
    boolean calledDefaultWriteObject = readBoolean();

    if (calledDefaultWriteObject)
        throwAwayData(fields, sender);

    if (getStreamFormatVersion() == 2) {

        ((ValueInputStream)getOrbStream()).start_value();
        ((ValueInputStream)getOrbStream()).end_value();
    }
}
 
Example 15
Project: openjdk-jdk10   File: InputStreamHook.java   Source Code and 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 16
Project: openjdk-jdk10   File: Ser.java   Source Code and License 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 17
Project: openjdk-jdk10   File: Properties.java   Source Code and License 6 votes vote down vote up
@Override
void readHashtable(ObjectInputStream s) throws IOException,
        ClassNotFoundException {
    // Read in the threshold and loadfactor
    s.defaultReadObject();

    // Read the original length of the array and number of elements
    int origlength = s.readInt();
    int elements = s.readInt();

    // Validate # of elements
    if (elements < 0) {
        throw new StreamCorruptedException("Illegal # of Elements: " + elements);
    }

    // create CHM of appropriate capacity
    map = new ConcurrentHashMap<>(elements);

    // Read all the key/value objects
    for (; elements > 0; elements--) {
        Object key = s.readObject();
        Object value = s.readObject();
        map.put(key, value);
    }
}
 
Example 18
Project: openjdk-jdk10   File: StreamRemoteCall.java   Source Code and License 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 19
Project: dubbocloud   File: CompactedObjectInputStream.java   Source Code and License 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 20
Project: openjdk9   File: IIOPInputStream.java   Source Code and License 6 votes vote down vote up
private void skipCustomUsingFVD(ValueMember[] fields,
                                com.sun.org.omg.SendingContext.CodeBase sender)
                                throws InvalidClassException, StreamCorruptedException,
                                       ClassNotFoundException, IOException
{
    readFormatVersion();
    boolean calledDefaultWriteObject = readBoolean();

    if (calledDefaultWriteObject)
        throwAwayData(fields, sender);

    if (getStreamFormatVersion() == 2) {

        ((ValueInputStream)getOrbStream()).start_value();
        ((ValueInputStream)getOrbStream()).end_value();
    }
}
 
Example 21
Project: openjdk9   File: InputStreamHook.java   Source Code and 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 22
Project: openjdk9   File: Ser.java   Source Code and License 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 23
Project: openjdk9   File: StreamRemoteCall.java   Source Code and License 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 24
Project: Java8CN   File: Ser.java   Source Code and License 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 25
Project: jahhan   File: CompactedObjectInputStream.java   Source Code and License 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 26
Project: lookaside_java-1.8.0-openjdk   File: Ser.java   Source Code and License 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 27
Project: Skript   File: YggdrasilInputStream.java   Source Code and License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
	private final Object readEnum() throws IOException {
		final Class<?> c = readEnumType();
		final String id = readEnumID();
		if (Enum.class.isAssignableFrom(c)) {
			return Yggdrasil.getEnumConstant((Class) c, id);
		} else if (PseudoEnum.class.isAssignableFrom(c)) {
			final Object o = PseudoEnum.valueOf((Class) c, id);
			if (o != null)
				return o;
//			if (YggdrasilRobustPseudoEnum.class.isAssignableFrom(c)) {
//				// TODO create this and a handler (for Enums as well)
//			}
			throw new StreamCorruptedException("Enum constant " + id + " does not exist in " + c);
		} else {
			throw new StreamCorruptedException(c + " is not an enum type");
		}
	}
 
Example 28
Project: dubbos   File: CompactedObjectInputStream.java   Source Code and License 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 29
Project: gemfirexd-oss   File: T_Undoable.java   Source Code and License 6 votes vote down vote up
public void readExternal(ObjectInput in) 
	throws IOException,ClassNotFoundException
	{
//MsgTrace.traceString("{{{tu.readExternal");
		try
		{
			tid = (GlobalTransactionId)in.readObject();
			tranSeq = in.readInt();
			recordSeq = in.readInt();
			removeWhat = in.readInt();
			LWMTranSeq = in.readInt();
			rollBack = in.readBoolean();
			lastRecord = in.readInt();
			lastTransaction = in.readBoolean();
			optionalDataLen = in.readInt();
		}

		catch ( ClassCastException exception ) {
//MsgTrace.traceString("{{{tu.readExternal---exception");
			throw new StreamCorruptedException();
		}
//MsgTrace.traceString("}}}tu.readExternal");
	}
 
Example 30
Project: dubbo-comments   File: CompactedObjectInputStream.java   Source Code and License 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 31
Project: dubbox   File: CompactedObjectInputStream.java   Source Code and License 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 32
Project: dubbo   File: CompactedObjectInputStream.java   Source Code and License 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 33
Project: dubbo3   File: CompactedObjectInputStream.java   Source Code and License 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 34
Project: jdk8u_jdk   File: StreamRemoteCall.java   Source Code and License 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 35
Project: Skript   File: Direction.java   Source Code and License 6 votes vote down vote up
@Override
public boolean excessiveField(@NonNull final FieldContext field) throws StreamCorruptedException {
	if (field.getID().equals("mod")) {
		final double[] mod = field.getObject(double[].class);
		if (mod == null)
			return true;
		if (mod.length != 3)
			throw new StreamCorruptedException();
		set("pitchOrX", mod[0]);
		set("yawOrY", mod[1]);
		set("lengthOrZ", mod[1]);
		return true;
	} else if (field.getID().equals("pitch")) {
		set("pitchOrX", field.getPrimitive(double.class));
		return true;
	} else if (field.getID().equals("yaw")) {
		set("yawOrY", field.getPrimitive(double.class));
		return true;
	} else if (field.getID().equals("length")) {
		set("lengthOrZ", field.getPrimitive(double.class));
		return true;
	} else {
		return false;
	}
}
 
Example 36
Project: offloading-framework-android   File: Utils.java   Source Code and License 6 votes vote down vote up
public static Object byteArrayToObject(byte[] bytes)
    throws StreamCorruptedException, IOException, ClassNotFoundException {
  Object obj = null;
  ByteArrayInputStream bis = null;
  ObjectInputStream ois = null;
  try {
    bis = new ByteArrayInputStream(bytes);
    ois = new ObjectInputStream(bis);
    obj = ois.readObject();
  } finally {
    if (bis != null) {
      bis.close();
    }
    if (ois != null) {
      ois.close();
    }
  }
  return obj;
}
 
Example 37
Project: Skript   File: Fields.java   Source Code and License 6 votes vote down vote up
public void setField(final Object o, final Field f, final Yggdrasil y) throws StreamCorruptedException {
	if (Modifier.isStatic(f.getModifiers()))
		throw new StreamCorruptedException("The field " + id + " of " + f.getDeclaringClass() + " is static");
	if (Modifier.isTransient(f.getModifiers()))
		throw new StreamCorruptedException("The field " + id + " of " + f.getDeclaringClass() + " is transient");
	if (f.getType().isPrimitive() != isPrimitiveValue)
		throw new StreamCorruptedException("The field " + id + " of " + f.getDeclaringClass() + " is " + (f.getType().isPrimitive() ? "" : "not ") + "primitive");
	try {
		f.setAccessible(true);
		f.set(o, value);
	} catch (final IllegalArgumentException e) {
		if (!(o instanceof YggdrasilRobustSerializable) || !((YggdrasilRobustSerializable) o).incompatibleField(f, this))
			y.incompatibleField(o, f, this);
	} catch (final IllegalAccessException e) {
		assert false;
	}
}
 
Example 38
Project: Skript   File: Fields.java   Source Code and License 6 votes vote down vote up
/**
 * Sets all fields of the given Object to the values stored in this Fields object.
 * 
 * @param o The object whose fields should be set
 * @throws StreamCorruptedException
 * @throws NotSerializableException
 * @throws YggdrasilException If this was called on a Fields object not created by Yggdrasil itself
 */
public void setFields(final Object o) throws StreamCorruptedException, NotSerializableException {
	final Yggdrasil y = yggdrasil;
	if (y == null)
		throw new YggdrasilException("");
	final Set<FieldContext> excessive = new HashSet<FieldContext>(fields.values());
	final Class<?> oc = o.getClass();
	assert oc != null;
	for (final Field f : getFields(oc)) {
		assert f != null;
		final String id = Yggdrasil.getID(f);
		final FieldContext c = fields.get(id);
		if (c == null) {
			if (!(o instanceof YggdrasilRobustSerializable) || !((YggdrasilRobustSerializable) o).missingField(f))
				y.missingField(o, f);
		} else {
			c.setField(o, f, y);
		}
		excessive.remove(c);
	}
	for (final FieldContext f : excessive) {
		assert f != null;
		if (!(o instanceof YggdrasilRobustSerializable) || !((YggdrasilRobustSerializable) o).excessiveField(f))
			y.excessiveField(o, f);
	}
}
 
Example 39
Project: jdk8u_jdk   File: Ser.java   Source Code and License 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 40
Project: Skript   File: YggXMLInputStream.java   Source Code and License 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 41
Project: Skript   File: Yggdrasil.java   Source Code and License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "null", "unused"})
public final static <T extends Enum<T>> Enum<T> getEnumConstant(final Class<T> c, final String id) throws StreamCorruptedException {
	final Field[] fields = c.getDeclaredFields();
	for (final Field f : fields) {
		assert f != null;
		if (getID(f).equals(id))
			return Enum.valueOf(c, f.getName());
	}
	if (YggdrasilRobustEnum.class.isAssignableFrom(c)) {
		final Object[] cs = c.getEnumConstants();
		if (cs.length == 0)
			throw new StreamCorruptedException(c + " does not have any enum constants");
		final Enum<?> e = ((YggdrasilRobustEnum) cs[0]).excessiveConstant(id);
		if (e == null)
			throw new YggdrasilException("YggdrasilRobustEnum " + c + " returned null from excessiveConstant(" + id + ")");
		if (!c.isInstance(e))
			throw new YggdrasilException(c + " returned a foreign enum constant: " + e.getClass() + "." + e);
		return (Enum<T>) e;
	}
	// TODO use field handlers/new enum handlers
	throw new StreamCorruptedException("Enum constant " + id + " does not exist in " + c);
}
 
Example 42
Project: cibet   File: CibetUtilTest.java   Source Code and License 6 votes vote down vote up
@Test
public void encode2ByteDecodeByteError() throws IOException {
   TEntity ent = new TEntity();
   ent.setCounter(12);
   ent.setOwner("me");
   byte[] bytes = CibetUtil.encode(ent);
   Assert.assertNotNull(bytes);
   bytes[0] = 23;

   try {
      CibetUtil.decode(bytes);
      Assert.fail();
   } catch (RuntimeException e) {
      Assert.assertNotNull(e.getCause());
      Assert.assertTrue(e.getCause() instanceof StreamCorruptedException);
      Assert.assertEquals("invalid stream header: 17ED0005", e.getCause().getMessage());
   }
}
 
Example 43
Project: Reer   File: DefaultSerializer.java   Source Code and License 5 votes vote down vote up
public T read(Decoder decoder) throws Exception {
    try {
        return (T) new ClassLoaderObjectInputStream(decoder.getInputStream(), classLoader).readObject();
    } catch (StreamCorruptedException e) {
        return null;
    }
}
 
Example 44
Project: NotifyTools   File: DynaProperty.java   Source Code and License 5 votes vote down vote up
/**
 * Reads a class using safe encoding to workaround java 1.3 serialization bug.
 */
private Class<?> readAnyClass(final ObjectInputStream in) throws IOException, ClassNotFoundException {
    // read back type class safely
    if (in.readBoolean()) {
        // it's a type constant
        switch (in.readInt()) {

            case BOOLEAN_TYPE: return   Boolean.TYPE;
            case BYTE_TYPE:    return      Byte.TYPE;
            case CHAR_TYPE:    return Character.TYPE;
            case DOUBLE_TYPE:  return    Double.TYPE;
            case FLOAT_TYPE:   return     Float.TYPE;
            case INT_TYPE:     return   Integer.TYPE;
            case LONG_TYPE:    return      Long.TYPE;
            case SHORT_TYPE:   return     Short.TYPE;
            default:
                // something's gone wrong
                throw new StreamCorruptedException(
                    "Invalid primitive type. "
                    + "Check version of beanutils used to serialize is compatible.");

        }

    } else {
        // it's another class
        return ((Class<?>) in.readObject());
    }
}
 
Example 45
Project: lazythreetenbp   File: LazyZoneRulesProvider.java   Source Code and License 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 46
Project: hadoop-oss   File: KeyPairSpec.java   Source Code and License 5 votes vote down vote up
public KeyPairSpec(byte[] material, String algorithm)
  throws StreamCorruptedException {
  // TODO move this code to a separate class
  ByteBuffer buffer = ByteBuffer.wrap(material);
  int len = buffer.getInt();
  publicKey = new byte[len];
  len = buffer.getInt();
  secretKey = new byte[len];
  buffer.get(publicKey);
  buffer.get(secretKey);
  this.algorithm = algorithm;
}
 
Example 47
Project: olami-java-client-sdk   File: SpeexDecoder.java   Source Code and License 5 votes vote down vote up
/**
 * This is where the actual decoding takes place
 * @param data - the Speex data (frame) to decode.
 * If it is null, the packet is supposed lost.
 * @param offset - the offset from which to start reading the data.
 * @param len - the length of data to read (Speex frame size).
 * @throws StreamCorruptedException If the input stream is invalid.
 */
public void processData(final byte[] data,
                        final int offset,
                        final int len)
  throws StreamCorruptedException
{
  if (data == null) {
    processData(true);
  }
  else {
    /* read packet bytes into bitstream */
    bits.read_from(data, offset, len);
    processData(false);
  }
}
 
Example 48
Project: olami-java-client-sdk   File: SpeexDecoder.java   Source Code and License 5 votes vote down vote up
/**
 * This is where the actual decoding takes place.
 * @param lost - true if the Speex packet has been lost.
 * @throws StreamCorruptedException If the input stream is invalid.
 */
public void processData(final boolean lost)
  throws StreamCorruptedException
{
  int i;
  /* decode the bitstream */
  if (lost)
    decoder.decode(null, decodedData);
  else
    decoder.decode(bits, decodedData);
  if (channels == 2)
    decoder.decodeStereo(decodedData, frameSize);

  /* PCM saturation */
  for (i=0; i<frameSize*channels; i++) {
    if (decodedData[i]>32767.0f)
      decodedData[i]=32767.0f;
    else if (decodedData[i]<-32768.0f)
      decodedData[i]=-32768.0f;
  }

  /* convert to short and save to buffer */
  for (i=0; i<frameSize*channels; i++, outputSize++) {
    outputData[outputSize] = (decodedData[i]>0) ?
                             (short) (decodedData[i]+.5) :
                             (short) (decodedData[i]-.5);
  } 
}
 
Example 49
Project: olami-java-client-sdk   File: Inband.java   Source Code and License 5 votes vote down vote up
/**
 * User in-band request (submode=13).
 * @param bits - Speex bits buffer.
 * @throws StreamCorruptedException If stream seems corrupted.
 */
public void userInbandRequest(final Bits bits)
  throws StreamCorruptedException
{
  int req_size = bits.unpack(4);
  bits.advance(5+8*req_size);
}
 
Example 50
Project: hekate   File: CodecUtils.java   Source Code and License 5 votes vote down vote up
/**
 * Reads {@link BigInteger} value that was written via {@link #writeBigInteger(BigInteger, DataOutput)}.
 *
 * @param in Data input.
 *
 * @return Value.
 *
 * @throws IOException if failed to read value.
 */
public static BigInteger readBigInteger(DataInput in) throws IOException {
    byte hint = in.readByte();

    switch (hint) {
        case DECIMAL_ZERO: {
            return BigInteger.ZERO;
        }
        case DECIMAL_ONE: {
            return BigInteger.ONE;
        }
        case DECIMAL_TEN: {
            return BigInteger.TEN;
        }
        case DECIMAL_SMALL_UNSCALED: {
            long val = readVarLong(in);

            return BigInteger.valueOf(val);
        }
        case DECIMAL_BIG: {
            int bytesLen = readVarIntUnsigned(in);

            byte[] bytes = new byte[bytesLen];

            in.readFully(bytes);

            return new BigInteger(bytes);
        }
        default: {
            throw new StreamCorruptedException("Unexpected hint for " + BigInteger.class.getName() + " value [hint=" + hint + ']');
        }
    }
}
 
Example 51
Project: lams   File: CustomObjectInputStream.java   Source Code and License 5 votes vote down vote up
@Override
public int read(final byte[] buf, final int off, final int len) throws IOException {
    final byte[] b = (byte[])peekCallback().readFromStream();
    if (b.length != len) {
        throw new StreamCorruptedException("Expected " + len + " bytes from stream, got " + b.length);
    }
    System.arraycopy(b, 0, buf, off, len);
    return len;
}
 
Example 52
Project: OpenJSharp   File: IIOPInputStream.java   Source Code and License 5 votes vote down vote up
void readFields(java.util.Map fieldToValueMap)
    throws InvalidClassException, StreamCorruptedException,
           ClassNotFoundException, IOException {

    if (mustUseRemoteValueMembers()) {
        inputRemoteMembersForReadFields(fieldToValueMap);
    } else
        inputCurrentClassFieldsForReadFields(fieldToValueMap);
}
 
Example 53
Project: OpenJSharp   File: InputStreamHook.java   Source Code and License 5 votes vote down vote up
public void beginUnmarshalCustomValue(InputStreamHook stream,
                                      boolean calledDefaultWriteObject,
                                      boolean hasReadObject)
    throws IOException {

    if (hasReadObject) {
        if (calledDefaultWriteObject)
            stream.setState(IN_READ_OBJECT_DEFAULTS_SENT);
        else {
            try {
                if (stream.getStreamFormatVersion() == 2)
                    ((ValueInputStream)stream.getOrbStream()).start_value();
            } catch( Exception e ) {
                // This will happen for Big Integer which uses
                // writeFields in it's writeObject. We should be past
                // start_value by now.
                // NOTE: If we don't log any exception here we should
                // be fine. If there is an error, it will be caught
                // while reading the optional data.

            }
            stream.setState(IN_READ_OBJECT_OPT_DATA);
        }
    } else {
        if (calledDefaultWriteObject)
            stream.setState(NO_READ_OBJECT_DEFAULTS_SENT);
        else
            // XXX I18N and logging needed.
            throw new StreamCorruptedException("No default data sent");
    }
}
 
Example 54
Project: OpenJSharp   File: Ser.java   Source Code and License 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 55
Project: OpenJSharp   File: Ser.java   Source Code and 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 56
Project: OpenJSharp   File: Beans.java   Source Code and 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;
}
 
Example 57
Project: OpenJSharp   File: MBeanFeatureInfo.java   Source Code and License 5 votes vote down vote up
/**
 * 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 58
Project: OpenJSharp   File: MBeanInfo.java   Source Code and License 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 59
Project: jdk8u-jdk   File: Ser.java   Source Code and License 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 60
Project: jdk8u-jdk   File: Ser.java   Source Code and 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");
    }
}