Package com.esotericsoftware.kryo

Examples of com.esotericsoftware.kryo.SerializationException


      byte methodIndex = buffer.get();
      CachedMethod cachedMethod;
      try {
        cachedMethod = getMethods(kryo, methodClass)[methodIndex];
      } catch (IndexOutOfBoundsException ex) {
        throw new SerializationException("Invalid method index " + methodIndex + " for class: " + methodClass.getName());
      }
      method = cachedMethod.method;

      args = new Object[cachedMethod.serializers.length];
      for (int i = 0, n = args.length; i < n; i++) {
View Full Code Here


        if (!IntSerializer.canRead(readBuffer, true)) return null;
      }
      currentObjectLength = IntSerializer.get(readBuffer, true);

      if (currentObjectLength <= 0) throw new SerializationException("Invalid object length: " + currentObjectLength);
      if (currentObjectLength > readBuffer.capacity())
        throw new SerializationException("Unable to read object larger than read buffer: " + currentObjectLength);
    }

    int length = currentObjectLength;
    if (readBuffer.remaining() < length) {
      // Read the bytes for the next object from the socket.
      readBuffer.compact();
      int bytesRead = socketChannel.read(readBuffer);
      readBuffer.flip();
      if (bytesRead == -1) throw new SocketException("Connection is closed.");
      lastReadTime = System.currentTimeMillis();

      if (readBuffer.remaining() < length) return null;
    }
    currentObjectLength = 0;

    int startPosition = readBuffer.position();
    int oldLimit = readBuffer.limit();
    readBuffer.limit(startPosition + length);

    Context context = Kryo.getContext();
    context.put("connection", connection);
    context.setRemoteEntityID(connection.id);
    Object object = kryo.readClassAndObject(readBuffer);

    readBuffer.limit(oldLimit);
    if (readBuffer.position() - startPosition != length)
      throw new SerializationException("Incorrect number of bytes (" + (startPosition + length - readBuffer.position())
        + " remaining) used to deserialize object: " + object);

    return object;
  }
View Full Code Here

      context.put("connection", connection);
      context.setRemoteEntityID(connection.id);
      try {
        kryo.writeClassAndObject(tempWriteBuffer, object);
      } catch (SerializationException ex) {
        throw new SerializationException("Unable to serialize object of type: " + object.getClass().getName(), ex);
      }
      tempWriteBuffer.flip();

      // Write data length.
      int dataLength = tempWriteBuffer.limit() - 5;
      int lengthLength = IntSerializer.length(dataLength, true);
      int start = 5 - lengthLength;
      tempWriteBuffer.position(start);
      IntSerializer.put(tempWriteBuffer, dataLength, true);
      tempWriteBuffer.position(start);

      try {
        if (writeBuffer.position() > 0) {
          // Other data is already queued, append this data to be written later.
          writeBuffer.put(tempWriteBuffer);
        } else if (!writeToSocket(tempWriteBuffer)) {
          // A partial write occurred, queue the remaining data to be written later.
          writeBuffer.put(tempWriteBuffer);
          // Set OP_WRITE to be notified when more writing can occur.
          selectionKey.interestOps(SelectionKey.OP_READ | SelectionKey.OP_WRITE);
        }
      } catch (BufferOverflowException ex) {
        throw new SerializationException(
          "Write buffer limit exceeded writing object of type: " + object.getClass().getName(), ex);
      }

      if (DEBUG || TRACE) {
        float percentage = writeBuffer.position() / (float)writeBuffer.capacity();
View Full Code Here

      Context context = Kryo.getContext();
      context.put("connection", connection);
      if (connection != null) context.setRemoteEntityID(connection.id);
      Object object = kryo.readClassAndObject(readBuffer);
      if (readBuffer.hasRemaining())
        throw new SerializationException("Incorrect number of bytes (" + readBuffer.remaining()
          + " remaining) used to deserialize object: " + object);
      return object;
    } finally {
      readBuffer.clear();
    }
View Full Code Here

    protected static final Object[] INITARGS = new Object[0];
    protected static final Map<Class<?>, Constructor<?>> CONSTRUCTOR_CACHE = new ConcurrentHashMap<Class<?>, Constructor<?>>();
   
    @Override
    public <T> T newInstance(Class<T> type) {
        SerializationException ex = null;
        try {
            return super.newInstance(type);
        } catch (SerializationException se) {
            ex = se;
        }
View Full Code Here

            serializer.writeObjectData(buffer, value);
          else
            serializer.writeObject(buffer, value);
        }
      } catch (IllegalAccessException ex) {
        throw new SerializationException("Error accessing field: " + cachedField + " (" + object.getClass().getName() + ")",
          ex);
      } catch (SerializationException ex) {
        ex.addTrace(cachedField + " (" + object.getClass().getName() + ")");
        throw ex;
      } catch (RuntimeException runtimeEx) {
        SerializationException ex = new SerializationException(runtimeEx);
        ex.addTrace(cachedField + " (" + object.getClass().getName() + ")");
        throw ex;
      }
    }
    if (TRACE) trace("kryo", "Wrote object: " + object);
  }
View Full Code Here

            value = serializer.readObject(buffer, concreteType);
        }

        cachedField.set(object, value);
      } catch (IllegalAccessException ex) {
        throw new SerializationException("Error accessing field: " + cachedField + " (" + type.getName() + ")", ex);
      } catch (SerializationException ex) {
        ex.addTrace(cachedField + " (" + type.getName() + ")");
        throw ex;
      } catch (RuntimeException runtimeEx) {
        SerializationException ex = new SerializationException(runtimeEx);
        ex.addTrace(cachedField + " (" + type.getName() + ")");
        throw ex;
      }
    }
    if (TRACE) trace("kryo", "Read object: " + object);
    return object;
View Full Code Here

      if ((b & 0x80) == 0) {
        if (!optimizePositive) result = (result >>> 1) ^ -(result & 1);
        return result;
      }
    }
    throw new SerializationException("Malformed integer.");
  }
View Full Code Here

      } finally {
        output.close();
      }
      outputBuffer.position(outputBufferStream.size());
    } catch (IOException ex) {
      throw new SerializationException(ex);
    }
  }
View Full Code Here

        outputBuffer.position(input.read(outputBuffer.array(), 0, outputBuffer.capacity()));
      } finally {
        input.close();
      }
    } catch (IOException ex) {
      throw new SerializationException(ex);
    }
  }
View Full Code Here

TOP

Related Classes of com.esotericsoftware.kryo.SerializationException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.