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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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;
}