本文整理汇总了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.
}
示例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 );
}
示例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);
}
示例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);
}
示例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;
}
}
}
示例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);
});
}
示例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);
});
}
示例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));
});
}
示例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());
}
}
示例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;
}
}
示例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();
}
示例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);
}
}
示例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);
}
}
示例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();
}
示例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);
}
}