java.io.ObjectStreamException Java Examples

The following examples show how to use java.io.ObjectStreamException. 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: URL.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
  * Replaces the de-serialized object with an URL object.
  *
  * @return a newly created object from the deserialzed state.
  *
  * @throws ObjectStreamException if a new object replacing this
  * object could not be created
  */

private Object readResolve() throws ObjectStreamException {

     URLStreamHandler handler = null;
     // already been checked in readObject
     handler = getURLStreamHandler(tempState.getProtocol());

     URL replacementURL = null;
     if (isBuiltinStreamHandler(handler.getClass().getName())) {
         replacementURL = fabricateNewURL();
     } else {
         replacementURL = setDeserializedFields(handler);
     }
     return replacementURL;
 }
 
Example #2
Source File: AbstractPrototypeBasedTargetSource.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Replaces this object with a SingletonTargetSource on serialization.
 * Protected as otherwise it won't be invoked for subclasses.
 * (The {@code writeReplace()} method must be visible to the class
 * being serialized.)
 * <p>With this implementation of this method, there is no need to mark
 * non-serializable fields in this class or subclasses as transient.
 */
protected Object writeReplace() throws ObjectStreamException {
	if (logger.isDebugEnabled()) {
		logger.debug("Disconnecting TargetSource [" + this + "]");
	}
	try {
		// Create disconnected SingletonTargetSource/EmptyTargetSource.
		Object target = getTarget();
		return (target != null ? new SingletonTargetSource(target) :
				EmptyTargetSource.forClass(getTargetClass()));
	}
	catch (Exception ex) {
		String msg = "Cannot get target for disconnecting TargetSource [" + this + "]";
		logger.error(msg, ex);
		throw new NotSerializableException(msg + ": " + ex);
	}
}
 
Example #3
Source File: DateTickUnitType.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Ensures that serialization returns the unique instances.
 *
 * @return The object.
 *
 * @throws ObjectStreamException if there is a problem.
 */
private Object readResolve() throws ObjectStreamException {
    if (this.equals(DateTickUnitType.YEAR)) {
        return DateTickUnitType.YEAR;
    }
    else if (this.equals(DateTickUnitType.MONTH)) {
        return DateTickUnitType.MONTH;
    }
    else if (this.equals(DateTickUnitType.DAY)) {
        return DateTickUnitType.DAY;
    }
    else if (this.equals(DateTickUnitType.HOUR)) {
        return DateTickUnitType.HOUR;
    }
    else if (this.equals(DateTickUnitType.MINUTE)) {
        return DateTickUnitType.MINUTE;
    }
    else if (this.equals(DateTickUnitType.SECOND)) {
        return DateTickUnitType.SECOND;
    }
    else if (this.equals(DateTickUnitType.MILLISECOND)) {
        return DateTickUnitType.MILLISECOND;
    }
    return null;
}
 
Example #4
Source File: Inet4Address.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Replaces the object to be serialized with an InetAddress object.
 *
 * @return the alternate object to be serialized.
 *
 * @throws ObjectStreamException if a new object replacing this
 * object could not be created
 */
private Object writeReplace() throws ObjectStreamException {
    // will replace the to be serialized 'this' object
    InetAddress inet = new InetAddress();
    inet.holder().hostName = holder().getHostName();
    inet.holder().address = holder().getAddress();

    /**
     * Prior to 1.4 an InetAddress was created with a family
     * based on the platform AF_INET value (usually 2).
     * For compatibility reasons we must therefore write the
     * the InetAddress with this family.
     */
    inet.holder().family = 2;

    return inet;
}
 
Example #5
Source File: AxisLocation.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Ensures that serialization returns the unique instances.
 *
 * @return The object.
 *
 * @throws ObjectStreamException if there is a problem.
 */
private Object readResolve() throws ObjectStreamException {
    if (this.equals(AxisLocation.TOP_OR_RIGHT)) {
        return AxisLocation.TOP_OR_RIGHT;
    }
    else if (this.equals(AxisLocation.BOTTOM_OR_RIGHT)) {
        return AxisLocation.BOTTOM_OR_RIGHT;
    }
    else if (this.equals(AxisLocation.TOP_OR_LEFT)) {
        return AxisLocation.TOP_OR_LEFT;
    }
    else if (this.equals(AxisLocation.BOTTOM_OR_LEFT)) {
        return AxisLocation.BOTTOM_OR_LEFT;
    }
    return null;
}
 
Example #6
Source File: Inet4Address.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Replaces the object to be serialized with an InetAddress object.
 *
 * @return the alternate object to be serialized.
 *
 * @throws ObjectStreamException if a new object replacing this
 * object could not be created
 */
private Object writeReplace() throws ObjectStreamException {
    // will replace the to be serialized 'this' object
    InetAddress inet = new InetAddress();
    inet.holder().hostName = holder().getHostName();
    inet.holder().address = holder().getAddress();

    /**
     * Prior to 1.4 an InetAddress was created with a family
     * based on the platform AF_INET value (usually 2).
     * For compatibility reasons we must therefore write the
     * the InetAddress with this family.
     */
    inet.holder().family = 2;

    return inet;
}
 
Example #7
Source File: URL.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
  * Replaces the de-serialized object with an URL object.
  *
  * @return a newly created object from the deserialzed state.
  *
  * @throws ObjectStreamException if a new object replacing this
  * object could not be created
  */

private Object readResolve() throws ObjectStreamException {

     URLStreamHandler handler = null;
     // already been checked in readObject
     handler = getURLStreamHandler(tempState.getProtocol());

     URL replacementURL = null;
     if (isBuiltinStreamHandler(handler.getClass().getName())) {
         replacementURL = fabricateNewURL();
     } else {
         replacementURL = setDeserializedFields(handler);
     }
     return replacementURL;
 }
 
Example #8
Source File: URL.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
  * Replaces the de-serialized object with an URL object.
  *
  * @return a newly created object from the deserialzed state.
  *
  * @throws ObjectStreamException if a new object replacing this
  * object could not be created
  */

private Object readResolve() throws ObjectStreamException {

     URLStreamHandler handler = null;
     // already been checked in readObject
     handler = getURLStreamHandler(tempState.getProtocol());

     URL replacementURL = null;
     if (isBuiltinStreamHandler(handler.getClass().getName())) {
         replacementURL = fabricateNewURL();
     } else {
         replacementURL = setDeserializedFields(handler);
     }
     return replacementURL;
 }
 
Example #9
Source File: Inet4Address.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Replaces the object to be serialized with an InetAddress object.
 *
 * @return the alternate object to be serialized.
 *
 * @throws ObjectStreamException if a new object replacing this
 * object could not be created
 */
private Object writeReplace() throws ObjectStreamException {
    // will replace the to be serialized 'this' object
    InetAddress inet = new InetAddress();
    inet.holder().hostName = holder().getHostName();
    inet.holder().address = holder().getAddress();

    /**
     * Prior to 1.4 an InetAddress was created with a family
     * based on the platform AF_INET value (usually 2).
     * For compatibility reasons we must therefore write the
     * the InetAddress with this family.
     */
    inet.holder().family = 2;

    return inet;
}
 
Example #10
Source File: PolarAxisLocation.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Ensures that serialization returns the unique instances.
 *
 * @return The object.
 *
 * @throws ObjectStreamException if there is a problem.
 */
private Object readResolve() throws ObjectStreamException {
    if (this.equals(PolarAxisLocation.NORTH_RIGHT)) {
        return PolarAxisLocation.NORTH_RIGHT;
    }
    else if (this.equals(PolarAxisLocation.NORTH_LEFT)) {
        return PolarAxisLocation.NORTH_LEFT;
    }
    else if (this.equals(PolarAxisLocation.SOUTH_RIGHT)) {
        return PolarAxisLocation.SOUTH_RIGHT;
    }
    else if (this.equals(PolarAxisLocation.SOUTH_LEFT)) {
        return PolarAxisLocation.SOUTH_LEFT;
    }
    else if (this.equals(PolarAxisLocation.EAST_ABOVE)) {
        return PolarAxisLocation.EAST_ABOVE;
    }
    else if (this.equals(PolarAxisLocation.EAST_BELOW)) {
        return PolarAxisLocation.EAST_BELOW;
    }
    else if (this.equals(PolarAxisLocation.WEST_ABOVE)) {
        return PolarAxisLocation.WEST_ABOVE;
    }
    else if (this.equals(PolarAxisLocation.WEST_BELOW)) {
        return PolarAxisLocation.WEST_BELOW;
    }
    return null;
}
 
Example #11
Source File: DatasetRenderingOrder.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Ensures that serialization returns the unique instances.
 *
 * @return The object.
 *
 * @throws ObjectStreamException if there is a problem.
 */
private Object readResolve() throws ObjectStreamException {
    if (this.equals(DatasetRenderingOrder.FORWARD)) {
        return DatasetRenderingOrder.FORWARD;
    }
    else if (this.equals(DatasetRenderingOrder.REVERSE)) {
        return DatasetRenderingOrder.REVERSE;
    }
    return null;
}
 
Example #12
Source File: DialShape.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Ensures that serialization returns the unique instances.
 *
 * @return The object.
 *
 * @throws ObjectStreamException if there is a problem.
 */
private Object readResolve() throws ObjectStreamException {
    if (this.equals(DialShape.CIRCLE)) {
        return DialShape.CIRCLE;
    }
    else if (this.equals(DialShape.CHORD)) {
        return DialShape.CHORD;
    }
    else if (this.equals(DialShape.PIE)) {
        return DialShape.PIE;
    }
    return null;
}
 
Example #13
Source File: CertPath.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Replaces the {@code CertPath} to be serialized with a
 * {@code CertPathRep} object.
 *
 * @return the {@code CertPathRep} to be serialized
 *
 * @throws ObjectStreamException if a {@code CertPathRep} object
 * representing this certification path could not be created
 */
protected Object writeReplace() throws ObjectStreamException {
    try {
        return new CertPathRep(type, getEncoded());
    } catch (CertificateException ce) {
        NotSerializableException nse =
            new NotSerializableException
                ("java.security.cert.CertPath: " + type);
        nse.initCause(ce);
        throw nse;
    }
}
 
Example #14
Source File: ChartChangeEventType.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Ensures that serialization returns the unique instances.
 *
 * @return The object.
 *
 * @throws ObjectStreamException if there is a problem.
 */
private Object readResolve() throws ObjectStreamException {
    if (this.equals(ChartChangeEventType.GENERAL)) {
        return ChartChangeEventType.GENERAL;
    }
    else if (this.equals(ChartChangeEventType.NEW_DATASET)) {
        return ChartChangeEventType.NEW_DATASET;
    }
    else if (this.equals(ChartChangeEventType.DATASET_UPDATED)) {
        return ChartChangeEventType.DATASET_UPDATED;
    }
    return null;
}
 
Example #15
Source File: SeriesRenderingOrder.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Ensures that serialization returns the unique instances.
 *
 * @return The object.
 *
 * @throws ObjectStreamException if there is a problem.
 */
private Object readResolve() throws ObjectStreamException {
    if (this.equals(SeriesRenderingOrder.FORWARD)) {
        return SeriesRenderingOrder.FORWARD;
    }
    else if (this.equals(SeriesRenderingOrder.REVERSE)) {
        return SeriesRenderingOrder.REVERSE;
    }
    return null;
}
 
Example #16
Source File: PieLabelLinkStyle.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Ensures that serialization returns the unique instances.
 *
 * @return The object.
 *
 * @throws ObjectStreamException if there is a problem.
 */
private Object readResolve() throws ObjectStreamException {
    Object result = null;
    if (this.equals(PieLabelLinkStyle.STANDARD)) {
        result = PieLabelLinkStyle.STANDARD;
    }
    else if (this.equals(PieLabelLinkStyle.QUAD_CURVE)) {
        result = PieLabelLinkStyle.QUAD_CURVE;
    }
    else if (this.equals(PieLabelLinkStyle.CUBIC_CURVE)) {
        result = PieLabelLinkStyle.CUBIC_CURVE;
    }
    return result;
}
 
Example #17
Source File: HistogramType.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Ensures that serialization returns the unique instances.
 *
 * @return The object.
 *
 * @throws ObjectStreamException if there is a problem.
 */
private Object readResolve() throws ObjectStreamException {
    if (this.equals(HistogramType.FREQUENCY)) {
        return HistogramType.FREQUENCY;
    }
    else if (this.equals(HistogramType.RELATIVE_FREQUENCY)) {
        return HistogramType.RELATIVE_FREQUENCY;
    }
    else if (this.equals(HistogramType.SCALE_AREA_TO_1)) {
        return HistogramType.SCALE_AREA_TO_1;
    }
    return null;
}
 
Example #18
Source File: DomainOrder.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Ensures that serialization returns the unique instances.
 *
 * @return The object.
 *
 * @throws ObjectStreamException if there is a problem.
 */
private Object readResolve() throws ObjectStreamException {
    if (this.equals(DomainOrder.ASCENDING)) {
        return DomainOrder.ASCENDING;
    }
    else if (this.equals(DomainOrder.DESCENDING)) {
        return DomainOrder.DESCENDING;
    }
    else if (this.equals(DomainOrder.NONE)) {
        return DomainOrder.NONE;
    }
    return null;
}
 
Example #19
Source File: LegendRenderingOrder.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Ensures that serialization returns the unique instances.
 *
 * @return The object.
 *
 * @throws ObjectStreamException if there is a problem.
 */
private Object readResolve() throws ObjectStreamException {
    if (this.equals(LegendRenderingOrder.STANDARD)) {
        return LegendRenderingOrder.STANDARD;
    }
    else if (this.equals(LegendRenderingOrder.REVERSE)) {
        return LegendRenderingOrder.REVERSE;
    }
    return null;
}
 
Example #20
Source File: AreaRendererEndType.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Ensures that serialization returns the unique instances.
 *
 * @return The object.
 *
 * @throws ObjectStreamException if there is a problem.
 */
private Object readResolve() throws ObjectStreamException {
    Object result = null;
    if (this.equals(AreaRendererEndType.LEVEL)) {
        result = AreaRendererEndType.LEVEL;
    }
    else if (this.equals(AreaRendererEndType.TAPER)) {
        result = AreaRendererEndType.TAPER;
    }
    else if (this.equals(AreaRendererEndType.TRUNCATE)) {
        result = AreaRendererEndType.TRUNCATE;
    }
    return result;
}
 
Example #21
Source File: AbstractEntityManagerFactoryBean.java    From spring-analysis-note with MIT License 5 votes vote down vote up
protected Object writeReplace() throws ObjectStreamException {
	if (this.beanFactory != null && this.beanName != null) {
		return new SerializedEntityManagerFactoryBeanReference(this.beanFactory, this.beanName);
	}
	else {
		throw new NotSerializableException("EntityManagerFactoryBean does not run within a BeanFactory");
	}
}
 
Example #22
Source File: AsyncFSStorageAgent.java    From Bats with Apache License 2.0 5 votes vote down vote up
@Override
public Object readResolve() throws ObjectStreamException
{
  AsyncFSStorageAgent asyncFSStorageAgent = new AsyncFSStorageAgent(this.path, null);
  asyncFSStorageAgent.setSyncCheckpoint(syncCheckpoint);
  return asyncFSStorageAgent;
}
 
Example #23
Source File: EnumSyntax.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * During object input, convert this deserialized enumeration instance to
 * the proper enumeration value defined in the enumeration attribute class.
 *
 * @return  The enumeration singleton value stored at index
 *          <I>i</I>-<I>L</I> in the enumeration value table returned by
 *          {@link #getEnumValueTable() getEnumValueTable()},
 *          where <I>i</I> is this enumeration value's integer value and
 *          <I>L</I> is the value returned by {@link #getOffset()
 *          getOffset()}.
 *
 * @throws ObjectStreamException if the stream can't be deserialised
 * @throws  InvalidObjectException
 *     Thrown if the enumeration value table is null, this enumeration
 *     value's integer value does not correspond to an element in the
 *     enumeration value table, or the corresponding element in the
 *     enumeration value table is null. (Note: {@link
 *     java.io.InvalidObjectException InvalidObjectException} is a subclass
 *     of {@link java.io.ObjectStreamException ObjectStreamException}, which
 *     <CODE>readResolve()</CODE> is declared to throw.)
 */
protected Object readResolve() throws ObjectStreamException {

    EnumSyntax[] theTable = getEnumValueTable();

    if (theTable == null) {
        throw new InvalidObjectException(
                            "Null enumeration value table for class " +
                            getClass());
    }

    int theOffset = getOffset();
    int theIndex = value - theOffset;

    if (0 > theIndex || theIndex >= theTable.length) {
        throw new InvalidObjectException
            ("Integer value = " +  value + " not in valid range " +
             theOffset + ".." + (theOffset + theTable.length - 1) +
             "for class " + getClass());
    }

    EnumSyntax result = theTable[theIndex];
    if (result == null) {
        throw new InvalidObjectException
            ("No enumeration value for integer value = " +
             value + "for class " + getClass());
    }
    return result;
}
 
Example #24
Source File: CertPath.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a {@code CertPath} constructed from the type and data.
 *
 * @return the resolved {@code CertPath} object
 *
 * @throws ObjectStreamException if a {@code CertPath} could not
 * be constructed
 */
protected Object readResolve() throws ObjectStreamException {
    try {
        CertificateFactory cf = CertificateFactory.getInstance(type);
        return cf.generateCertPath(new ByteArrayInputStream(data));
    } catch (CertificateException ce) {
        NotSerializableException nse =
            new NotSerializableException
                ("java.security.cert.CertPath: " + type);
        nse.initCause(ce);
        throw nse;
    }
}
 
Example #25
Source File: Cheesery.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
private Object readResolve() throws ObjectStreamException {
    if ( "young".equals( this.age) ) {
        return Maturity.YOUNG;
    } else {
        return Maturity.OLD;
    }
}
 
Example #26
Source File: DurationImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private Object readResolve() throws ObjectStreamException {
    //            try {
    return new DurationImpl(lexical);
    //            } catch( ParseException e ) {
    //                throw new StreamCorruptedException("unable to parse "+lexical+" as duration");
    //            }
}
 
Example #27
Source File: CertPath.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a {@code CertPath} constructed from the type and data.
 *
 * @return the resolved {@code CertPath} object
 *
 * @throws ObjectStreamException if a {@code CertPath} could not
 * be constructed
 */
protected Object readResolve() throws ObjectStreamException {
    try {
        CertificateFactory cf = CertificateFactory.getInstance(type);
        return cf.generateCertPath(new ByteArrayInputStream(data));
    } catch (CertificateException ce) {
        NotSerializableException nse =
            new NotSerializableException
                ("java.security.cert.CertPath: " + type);
        nse.initCause(ce);
        throw nse;
    }
}
 
Example #28
Source File: CertPath.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Replaces the {@code CertPath} to be serialized with a
 * {@code CertPathRep} object.
 *
 * @return the {@code CertPathRep} to be serialized
 *
 * @throws ObjectStreamException if a {@code CertPathRep} object
 * representing this certification path could not be created
 */
protected Object writeReplace() throws ObjectStreamException {
    try {
        return new CertPathRep(type, getEncoded());
    } catch (CertificateException ce) {
        NotSerializableException nse =
            new NotSerializableException
                ("java.security.cert.CertPath: " + type);
        nse.initCause(ce);
        throw nse;
    }
}
 
Example #29
Source File: DurationImpl.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
private Object readResolve() throws ObjectStreamException {
    //            try {
    return new DurationImpl(lexical);
    //            } catch( ParseException e ) {
    //                throw new StreamCorruptedException("unable to parse "+lexical+" as duration");
    //            }
}
 
Example #30
Source File: EnumSyntax.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * During object input, convert this deserialized enumeration instance to
 * the proper enumeration value defined in the enumeration attribute class.
 *
 * @return  The enumeration singleton value stored at index
 *          <I>i</I>-<I>L</I> in the enumeration value table returned by
 *          {@link #getEnumValueTable() getEnumValueTable()},
 *          where <I>i</I> is this enumeration value's integer value and
 *          <I>L</I> is the value returned by {@link #getOffset()
 *          getOffset()}.
 *
 * @throws ObjectStreamException if the stream can't be deserialised
 * @throws  InvalidObjectException
 *     Thrown if the enumeration value table is null, this enumeration
 *     value's integer value does not correspond to an element in the
 *     enumeration value table, or the corresponding element in the
 *     enumeration value table is null. (Note: {@link
 *     java.io.InvalidObjectException InvalidObjectException} is a subclass
 *     of {@link java.io.ObjectStreamException ObjectStreamException}, which
 *     <CODE>readResolve()</CODE> is declared to throw.)
 */
protected Object readResolve() throws ObjectStreamException {

    EnumSyntax[] theTable = getEnumValueTable();

    if (theTable == null) {
        throw new InvalidObjectException(
                            "Null enumeration value table for class " +
                            getClass());
    }

    int theOffset = getOffset();
    int theIndex = value - theOffset;

    if (0 > theIndex || theIndex >= theTable.length) {
        throw new InvalidObjectException
            ("Integer value = " +  value + " not in valid range " +
             theOffset + ".." + (theOffset + theTable.length - 1) +
             "for class " + getClass());
    }

    EnumSyntax result = theTable[theIndex];
    if (result == null) {
        throw new InvalidObjectException
            ("No enumeration value for integer value = " +
             value + "for class " + getClass());
    }
    return result;
}