当前位置: 首页>>代码示例>>Java>>正文


Java NotSerializableException类代码示例

本文整理汇总了Java中java.io.NotSerializableException的典型用法代码示例。如果您正苦于以下问题:Java NotSerializableException类的具体用法?Java NotSerializableException怎么用?Java NotSerializableException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


NotSerializableException类属于java.io包,在下文中一共展示了NotSerializableException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: rethrowDeserializationException

import java.io.NotSerializableException; //导入依赖的package包/类
private void rethrowDeserializationException(IOException ioe)
        throws ClassNotFoundException, IOException {
    // specially treating for an UnmarshalException
    if (ioe instanceof UnmarshalException) {
        throw ioe; // the fix of 6937053 made ClientNotifForwarder.fetchNotifs
                   // fetch one by one with UnmarshalException
    } else if (ioe instanceof MarshalException) {
        // IIOP will throw MarshalException wrapping a NotSerializableException
        // when a server fails to serialize a response.
        MarshalException me = (MarshalException)ioe;
        if (me.detail instanceof NotSerializableException) {
            throw (NotSerializableException)me.detail;
        }
    }

    // Not serialization problem, return.
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:RMIConnector.java

示例2: encodeMessage

import java.io.NotSerializableException; //导入依赖的package包/类
@Override
public DataMessage encodeMessage ( final Object message ) throws Exception
{
    if ( ! ( message instanceof Serializable ) )
    {
        if ( message != null )
        {
            throw new NotSerializableException ( message.getClass ().getName () );
        }
        else
        {
            throw new NotSerializableException ();
        }
    }

    final IoBuffer data = IoBuffer.allocate ( 64 );
    data.setAutoExpand ( true );
    data.putObject ( message );
    data.flip ();
    return new DataMessage ( data );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:22,代码来源:ObjectSerializationProtocol.java

示例3: encode

import java.io.NotSerializableException; //导入依赖的package包/类
public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception {
    if (!(message instanceof Serializable)) {
        throw new NotSerializableException();
    }

    IoBuffer buf = IoBuffer.allocate(64);
    buf.setAutoExpand(true);
    buf.putObject(message);

    int objectSize = buf.position() - 4;
    if (objectSize > maxObjectSize) {
        throw new IllegalArgumentException("The encoded object is too big: " + objectSize + " (> " + maxObjectSize
                + ')');
    }

    buf.flip();
    out.write(buf);
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:19,代码来源:ObjectSerializationEncoder.java

示例4: doSerializationTest

import java.io.NotSerializableException; //导入依赖的package包/类
private void doSerializationTest(Map<Object,Object> table) {
	byte[] bytes = null;
	Object in = null;

	// write out object
	try {
		bytes = writeOutObject(table);
	} catch (NotSerializableException e) {
		fail("Expected object " + table + " to be serializable");
	}
	
	// read object back in
	in = bytesToObject(bytes);
	
	// compare object
	assertEquals("Comparison failed for test " + table,
			table, in);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-systemtest,代码行数:19,代码来源:HashtableTest.java

示例5: encode

import java.io.NotSerializableException; //导入依赖的package包/类
@Override
public void encode(Object obj, DataWriter out) throws IOException {
    try {
        FSTObjectOutput objOut = fst.getObjectOutput(out.asStream());

        objOut.writeObject(obj);
        objOut.flush();
    } catch (RuntimeException e) {
        // Workaround for FST throwing RuntimeException instead of NotSerializableException.
        if (e.getMessage() != null && e.getMessage().indexOf("does not implement Serializable") > 0) {
            NotSerializableException converted = new NotSerializableException(e.getMessage());

            converted.setStackTrace(e.getStackTrace());

            throw converted;
        } else {
            throw e;
        }
    }
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:21,代码来源:FstCodec.java

示例6: testNonSerializableArg

import java.io.NotSerializableException; //导入依赖的package包/类
@Test
public void testNonSerializableArg() throws Exception {
    TestRpcC rpc = mock(TestRpcC.class);

    HekateTestNode client = prepareClientAndServer(rpc).client();

    TestRpcC proxy = client.rpc().clientFor(TestRpcC.class).build();

    repeat(3, i -> {
        RpcException err = expect(RpcException.class, () -> proxy.callC(1, new NonSerializable()));

        String stackTrace = ErrorUtils.stackTrace(err);

        assertTrue(stackTrace, ErrorUtils.isCausedBy(CodecException.class, err));
        assertTrue(stackTrace, stackTrace.contains(NotSerializableException.class.getName()));
        assertTrue(stackTrace, stackTrace.contains(Socket.class.getName()));

        verifyNoMoreInteractions(rpc);
        reset(rpc);
    });
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:22,代码来源:RpcUnicastTest.java

示例7: testNonSerializableResult

import java.io.NotSerializableException; //导入依赖的package包/类
@Test
public void testNonSerializableResult() throws Exception {
    TestRpcB rpc = mock(TestRpcB.class);

    HekateTestNode client = prepareClientAndServer(rpc).client();

    TestRpcB proxy = client.rpc().clientFor(TestRpcB.class).build();

    repeat(3, i -> {
        when(rpc.callB()).thenReturn(new NonSerializable());

        RpcException err = expect(RpcException.class, proxy::callB);

        String stackTrace = ErrorUtils.stackTrace(err);

        assertTrue(stackTrace, ErrorUtils.isCausedBy(MessagingRemoteException.class, err));
        assertTrue(stackTrace, stackTrace.contains(NotSerializableException.class.getName()));
        assertTrue(stackTrace, stackTrace.contains(Socket.class.getName()));

        verify(rpc).callB();
        verifyNoMoreInteractions(rpc);
        reset(rpc);
    });
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:25,代码来源:RpcUnicastTest.java

示例8: testNonSerializableRequest

import java.io.NotSerializableException; //导入依赖的package包/类
@Test
public void testNonSerializableRequest() throws Exception {
    HekateTestNode sender = prepareObjectSenderAndReceiver(msg ->
        msg.reply("OK")
    );

    repeat(5, i -> {
        MessagingFutureException err = expect(MessagingFutureException.class, () ->
            get(sender.messaging().channel("test").forRemotes().request(new NonSerializable()))
        );

        assertSame(err.toString(), MessagingException.class, err.getCause().getClass());
        assertTrue(err.isCausedBy(CodecException.class));
        assertTrue(err.isCausedBy(NotSerializableException.class));
    });
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:17,代码来源:MessagingChannelRequestTest.java

示例9: sendMessage

import java.io.NotSerializableException; //导入依赖的package包/类
/**
 * Using a new or pooled message instance, create and send the request for object value to the
 * specified node.
 */
public static void sendMessage(SearchLoadAndWriteProcessor processor, String regionName,
    Object key, Object aCallbackArgument, InternalDistributedMember recipient, int timeoutMs,
    int ttl, int idleTime) {

  // create a message
  NetLoadRequestMessage msg = new NetLoadRequestMessage();
  msg.initialize(processor, regionName, key, aCallbackArgument, timeoutMs, ttl, idleTime);
  msg.setRecipient(recipient);

  try {
    processor.distributionManager.putOutgoingUserData(msg);
  } catch (NotSerializableException e) {
    throw new IllegalArgumentException(
        LocalizedStrings.SearchLoadAndWriteProcessor_MESSAGE_NOT_SERIALIZABLE
            .toLocalizedString());
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:22,代码来源:SearchLoadAndWriteProcessor.java

示例10: fromData

import java.io.NotSerializableException; //导入依赖的package包/类
@Override
public void fromData(DataInput in) throws IOException, ClassNotFoundException {
  super.fromData(in);
  this.msgNum = in.readInt();
  this.lastMsg = in.readBoolean();
  this.processorId = in.readInt();
  try {
    this.result = DataSerializer.readObject(in);
  } catch (Exception e) { // bug fix 40670
    // Seems odd to throw a NonSerializableEx when it has already been
    // serialized and we are failing because we can't deserialize.
    NotSerializableException ioEx = new NotSerializableException();
    ioEx.initCause(e);
    throw ioEx;
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:17,代码来源:FunctionStreamingReplyMessage.java

示例11: assertPreconditions

import java.io.NotSerializableException; //导入依赖的package包/类
private void assertPreconditions() {
  catchException(this).clone(this.nonSerializableNamingException);
  assertThat((Throwable) caughtException()).isNotNull();
  assertThat((Throwable) caughtException().getCause())
      .isInstanceOf(NotSerializableException.class);

  catchException(this).clone(this.serializableNamingException);
  assertThat((Throwable) caughtException()).isNull();

  assertThat(this.nonSerializableResolvedObj).isNotInstanceOf(Serializable.class);

  catchException(this).clone(this.serializableResolvedObj);
  assertThat((Throwable) caughtException()).isNull();

  assertThat(this.nonSerializablePrincipal).isNotInstanceOf(Serializable.class);

  catchException(this).clone(this.serializablePrincipal);
  assertThat((Throwable) caughtException()).isNull();
}
 
开发者ID:ampool,项目名称:monarch,代码行数:20,代码来源:NotAuthorizedExceptionTest.java

示例12: testBasicAll

import java.io.NotSerializableException; //导入依赖的package包/类
@Test
public void testBasicAll() throws IOException, ClassNotFoundException {
  BasicAllFieldTypes v1 = new BasicAllFieldTypes(0x1020304050607080L, false);
  try {
    serializeAndDeserialize(v1);
    throw new RuntimeException("expected NotSerializableException");
  } catch (NotSerializableException expected) {

  }
  this.c.setPdxSerializer(new BasicAllFieldTypesPdxSerializer());
  try {
    BasicAllFieldTypes v2 = (BasicAllFieldTypes) serializeAndDeserialize(v1);
    assertEquals(v1, v2);
  } finally {
    this.c.setPdxSerializer(null);
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:18,代码来源:PdxSerializableJUnitTest.java

示例13: testBasicAllWithNulls

import java.io.NotSerializableException; //导入依赖的package包/类
@Test
public void testBasicAllWithNulls() throws IOException, ClassNotFoundException {
  BasicAllFieldTypes v1 = new BasicAllFieldTypes(0x1020304050607080L, true);
  try {
    serializeAndDeserialize(v1);
    throw new RuntimeException("expected NotSerializableException");
  } catch (NotSerializableException expected) {

  }
  this.c.setPdxSerializer(new BasicAllFieldTypesPdxSerializer());
  try {
    BasicAllFieldTypes v2 = (BasicAllFieldTypes) serializeAndDeserialize(v1);
    assertEquals(v1, v2);
  } finally {
    this.c.setPdxSerializer(null);
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:18,代码来源:PdxSerializableJUnitTest.java

示例14: Client

import java.io.NotSerializableException; //导入依赖的package包/类
public Client(final String ip, int port) throws UnknownHostException,
		IOException, ClassNotFoundException {
	Socket socket = new Socket(ip, port);
	ObjectOutputStream outToClient = new ObjectOutputStream(
			socket.getOutputStream());
	ObjectInputStream inFromClient = new ObjectInputStream(
			socket.getInputStream());

	long startTime = System.currentTimeMillis();
	long currentTime = System.currentTimeMillis();
	while (socket.isConnected() && jobs < MAX_JOBS
			&& (currentTime - startTime) < MAX_RUNTIME) {
		jobs++;
		ResultRunnable job = (ResultRunnable) inFromClient.readObject();
		job.setIPAdress(ip);
		job.run();
		Object result = job.getResult();
		try {
			outToClient.writeObject(result);
		} catch (NotSerializableException e) {
			outToClient.writeObject(e);
		}
		currentTime = System.currentTimeMillis();
	}

	if (!socket.isClosed()) {
		restart = true;
	}

	socket.close();
}
 
开发者ID:NeoRoy,项目名称:KeYExperienceReport,代码行数:32,代码来源:Client.java

示例15: testFastFailWhenArgumentsCannotBeSerialized

import java.io.NotSerializableException; //导入依赖的package包/类
public void testFastFailWhenArgumentsCannotBeSerialized() throws Exception
{
    this.setupServerWithHandler(null);
    Echo echo = this.buildEchoProxy();
    try
    {
        echo.echoObject(new Object());
        Assert.fail();
    }
    catch (JrpipRuntimeException e)
    {
        assertTrue(e.getCause() instanceof NotSerializableException);
    }
}
 
开发者ID:goldmansachs,项目名称:jrpip,代码行数:15,代码来源:ErrorConditionsTest.java


注:本文中的java.io.NotSerializableException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。