java.io.StreamCorruptedException Java Examples

The following examples show how to use java.io.StreamCorruptedException. 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 check out the related API usage on the sidebar.
Example #1
Source File: StreamRemoteCall.java    From jdk8u-jdk with 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 File: StreamRemoteCall.java    From jdk8u-jdk with 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 #3
Source File: Ser.java    From openjdk-jdk8u-backup with 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 #4
Source File: StreamRemoteCall.java    From hottub with 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 #5
Source File: CompactedObjectInputStream.java    From dubbox-hystrix with 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 #6
Source File: Ser.java    From jdk1.8-source-analysis with 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 #7
Source File: StreamRemoteCall.java    From jdk8u_jdk with 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 #8
Source File: StreamRemoteCall.java    From openjdk-jdk9 with 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 #9
Source File: Ser.java    From jdk8u-jdk with 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 #10
Source File: Ser.java    From openjdk-jdk9 with 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 #11
Source File: StreamRemoteCall.java    From TencentKona-8 with 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 #12
Source File: MoveToWrongIndexThenToEndTest.java    From Chronicle-Queue with Apache License 2.0 6 votes vote down vote up
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 #13
Source File: InputStreamHook.java    From JDKSourceCode1.8 with 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 #14
Source File: InputStreamHook.java    From openjdk-jdk8u with GNU General Public License v2.0 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 #15
Source File: YggXMLInputStream.java    From Skript with 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 #16
Source File: Serial.java    From jpx with 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 BOUNDS: ((Bounds)_object).write(out); break;
		case COPYRIGHT: ((Copyright)_object).write(out); break;
		case DEGREES: ((Degrees)_object).write(out); break;
		case DGPS_STATION: ((DGPSStation)_object).write(out); break;
		case EMAIL: ((Email)_object).write(out); break;
		case GPX_TYPE: ((GPX)_object).write(out); break;
		case LATITUDE: ((Latitude)_object).write(out); break;
		case LENGTH: ((Length)_object).write(out); break;
		case LINK: ((Link)_object).write(out); break;
		case LONGITUDE: ((Longitude)_object).write(out); break;
		case METADATA: ((Metadata)_object).write(out); break;
		case PERSON: ((Person)_object).write(out); break;
		case ROUTE: ((Route)_object).write(out); break;
		case SPEED: ((Speed)_object).write(out); break;
		case TRACK: ((Track)_object).write(out); break;
		case TRACK_SEGMENT: ((TrackSegment)_object).write(out); break;
		case UINT: ((UInt)_object).write(out); break;
		case WAY_POINT: ((WayPoint)_object).write(out); break;
		default:
			throw new StreamCorruptedException(
				"Unknown serialized type: " + _type
			);
	}
}
 
Example #17
Source File: Inband.java    From mdict-java with GNU General Public License v3.0 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 #18
Source File: MBeanFeatureInfo.java    From openjdk-jdk8u with GNU General Public License v2.0 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 #19
Source File: MBeanFeatureInfo.java    From jdk8u-dev-jdk with GNU General Public License v2.0 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 #20
Source File: ObjectInputStreamWithLoader.java    From krpc with MIT License 5 votes vote down vote up
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 File: Vector.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Loads a {@code Vector} instance from a stream
 * (that is, deserializes it).
 * This method performs checks to ensure the consistency
 * of the fields.
 *
 * @param in the stream
 * @throws java.io.IOException if an I/O error occurs
 * @throws ClassNotFoundException if the stream contains data
 *         of a non-existing class
 */
@java.io.Serial
private void readObject(ObjectInputStream in)
        throws IOException, ClassNotFoundException {
    ObjectInputStream.GetField gfields = in.readFields();
    int count = gfields.get("elementCount", 0);
    Object[] data = (Object[])gfields.get("elementData", null);
    if (count < 0 || data == null || count > data.length) {
        throw new StreamCorruptedException("Inconsistent vector internals");
    }
    elementCount = count;
    elementData = data.clone();
}
 
Example #22
Source File: StoreAppender.java    From Chronicle-Queue with Apache License 2.0 5 votes vote down vote up
@Override
public void writeBytes(@NotNull final BytesStore bytes) throws UnrecoverableTimeoutException {
    throwExceptionIfClosed();

    writeLock.lock();
    try {
        int cycle = queue.cycle();
        if (wire == null)
            setWireIfNull(cycle);

        if (this.cycle != cycle)
            rollCycleTo(cycle);

        this.positionOfHeader = writeHeader(wire, (int) queue.overlapSize()); // writeHeader sets wire.byte().writePosition

        assert ((AbstractWire) wire).isInsideHeader();
        beforeAppend(wire, wire.headerNumber() + 1);
        Bytes<?> wireBytes = wire.bytes();
        wireBytes.write(bytes);
        wire.updateHeader(positionOfHeader, false, 0);
        lastIndex(wire.headerNumber());
        lastPosition = positionOfHeader;
        lastCycle = cycle;
        store.writePosition(positionOfHeader);
        writeIndexForPosition(lastIndex, positionOfHeader);
    } catch (StreamCorruptedException e) {
        throw new AssertionError(e);
    } finally {
        writeLock.unlock();
    }
}
 
Example #23
Source File: Beans.java    From jdk-1.7-annotated with 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 #24
Source File: QueueWireHandler.java    From Chronicle-Queue with Apache License 2.0 5 votes vote down vote up
@Override
public void process(Wire in, Wire out) throws StreamCorruptedException {
    try {
        this.inWire = in;
        this.outWire = out;
        onEvent();
    } catch (Exception e) {
        LOG.error("", e);
    }
}
 
Example #25
Source File: Serial.java    From jenetics with 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 TREE_PATTERN: ((TreePattern)_object).write(out); break;
		case TREE_PATTERN_VAR: ((Var)_object).write(out); break;
		case TREE_PATTERN_VAL: ((Val)_object).write(out); break;
		case TREE_REWRITE_RULE: ((TreeRewriteRule)_object).write(out); break;
		case TRS_KEY: ((TRS)_object).write(out); break;
		default:
			throw new StreamCorruptedException("Unknown serialized type.");
	}
}
 
Example #26
Source File: Beans.java    From jdk8u-dev-jdk with 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 #27
Source File: DefaultYggdrasilInputStream.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
private String readShortString() throws IOException {
	final int length = read();
	if (length == (T_REFERENCE.tag & 0xFF)) {
		final int i = version <= 1 ? readInt() : readUnsignedInt();
		if (i < 0 || i > readShortStrings.size())
			throw new StreamCorruptedException("Invalid short string reference " + i);
		return "" + readShortStrings.get(i);
	}
	final byte[] d = new byte[length];
	readFully(d);
	final String s = new String(d, UTF_8);
	if (length > 4)
		readShortStrings.add(s);
	return s;
}
 
Example #28
Source File: Ser.java    From openjdk-8 with 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 #29
Source File: ObjectDecoderInputStream.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
public Object readObject() throws ClassNotFoundException, IOException {
    int dataLen = readInt();
    if (dataLen <= 0) {
        throw new StreamCorruptedException("invalid data length: " + dataLen);
    }
    if (dataLen > maxObjectSize) {
        throw new StreamCorruptedException(
                "data length too big: " + dataLen + " (max: " + maxObjectSize + ')');
    }

    return new CompactObjectInputStream(in, classResolver).readObject();
}
 
Example #30
Source File: MBeanInfo.java    From jdk8u60 with 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.");
    }
}