Package com.esotericsoftware.kryo

Examples of com.esotericsoftware.kryo.KryoException


    public Enum read (Kryo kryo, Input input, Class<Enum> type) {
      int ordinal = input.readInt(true);
      if (ordinal == NULL) return null;
      ordinal--;
      if (ordinal < 0 || ordinal > enumConstants.length - 1)
        throw new KryoException("Invalid ordinal for enum \"" + type.getName() + "\": " + ordinal);
      Object constant = enumConstants[ordinal];
      return (Enum)constant;
    }
View Full Code Here


          if (cachedField.generics != null) serializer.setGenerics(kryo, cachedField.generics);
          if (cachedField.canBeNull)
            kryo.writeObjectOrNull(output, value, serializer);
          else {
            if (value == null) {
              throw new KryoException("Field value is null but canBeNull is false: " + cachedField + " ("
                + object.getClass().getName() + ")");
            }
            kryo.writeObject(output, value, serializer);
          }
        }
      } catch (IllegalAccessException ex) {
        throw new KryoException("Error accessing field: " + cachedField + " (" + object.getClass().getName() + ")", ex);
      } catch (KryoException ex) {
        ex.addTrace(cachedField + " (" + object.getClass().getName() + ")");
        throw ex;
      } catch (RuntimeException runtimeEx) {
        KryoException ex = new KryoException(runtimeEx);
        ex.addTrace(cachedField + " (" + object.getClass().getName() + ")");
        throw ex;
      }
    }
  }
View Full Code Here

        if (f.tag == tag) {
          cachedField = f;
          break;
        }
      }
      if (cachedField == null) throw new KryoException("Unknown field tag: " + tag + " (" + getType().getName() + ")");

      try {
        if (TRACE) trace("kryo", "Read field: " + cachedField + " (" + getType().getName() + ")");

        Object value;

        Class concreteType = cachedField.valueClass;
        Serializer serializer = cachedField.serializer;
        if (concreteType == null) {
          Registration registration = kryo.readClass(input);
          if (registration == null)
            value = null;
          else {
            if (serializer == null) serializer = registration.getSerializer();
            if (cachedField.generics != null) serializer.setGenerics(kryo, cachedField.generics);
            value = kryo.readObject(input, registration.getType(), serializer);
          }
        } else {
          if (serializer == null) cachedField.serializer = serializer = kryo.getSerializer(concreteType);
          if (cachedField.generics != null) serializer.setGenerics(kryo, cachedField.generics);
          if (cachedField.canBeNull)
            value = kryo.readObjectOrNull(input, concreteType, serializer);
          else
            value = kryo.readObject(input, concreteType, serializer);
        }

        cachedField.set(object, value);
      } catch (IllegalAccessException ex) {
        throw new KryoException("Error accessing field: " + cachedField + " (" + getType().getName() + ")", ex);
      } catch (KryoException ex) {
        ex.addTrace(cachedField + " (" + getType().getName() + ")");
        throw ex;
      } catch (RuntimeException runtimeEx) {
        KryoException ex = new KryoException(runtimeEx);
        ex.addTrace(cachedField + " (" + getType().getName() + ")");
        throw ex;
      }
    }
    return object;
  }
View Full Code Here

  protected int fill (byte[] buffer, int offset, int count) throws KryoException {
    if (inputStream == null) return -1;
    try {
      return inputStream.read(buffer, offset, count);
    } catch (IOException ex) {
      throw new KryoException(ex);
    }
  }
View Full Code Here

   * @return the number of bytes remaining.
   * @throws KryoException if EOS is reached before required bytes are read (buffer underflow). */
  private int require (int required) throws KryoException {
    int remaining = limit - position;
    if (remaining >= required) return remaining;
    if (required > capacity) throw new KryoException("Buffer too small: capacity: " + capacity + ", required: " + required);

    // Compact.
    System.arraycopy(buffer, position, buffer, 0, remaining);
    total += position;
    position = 0;

    while (true) {
      int count = fill(buffer, remaining, capacity - remaining);
      if (count == -1) {
        if (remaining >= required) break;
        throw new KryoException("Buffer underflow.");
      }
      remaining += count;
      if (remaining >= required) break; // Enough has been read.
    }
    limit = remaining;
View Full Code Here

  protected int fill (byte[] buffer, int offset, int count) throws KryoException {
    if (inputStream == null) return -1;
    try {
      return inputStream.read(buffer, offset, count);
    } catch (IOException ex) {
      throw new KryoException(ex);
    }
  }
View Full Code Here

   * @return the number of bytes remaining.
   * @throws KryoException if EOS is reached before required bytes are read (buffer underflow). */
  protected int require (int required) throws KryoException {
    int remaining = limit - position;
    if (remaining >= required) return remaining;
    if (required > capacity) throw new KryoException("Buffer too small: capacity: " + capacity + ", required: " + required);

    int count;
    // Try to fill the buffer.
    if (remaining > 0) {
      count = fill(buffer, limit, capacity - limit);
      if (count == -1) throw new KryoException("Buffer underflow.");
      remaining += count;
      if (remaining >= required) {
        limit += count;
        return remaining;
      }
    }

    // Was not enough, compact and try again.
    System.arraycopy(buffer, position, buffer, 0, remaining);
    total += position;
    position = 0;

    while (true) {
      count = fill(buffer, remaining, capacity - remaining);
      if (count == -1) {
        if (remaining >= required) break;
        throw new KryoException("Buffer underflow.");
      }
      remaining += count;
      if (remaining >= required) break; // Enough has been read.
    }

View Full Code Here

  /** @return true if the buffer has been resized. */
  protected boolean require (int required) throws KryoException {
    if (capacity - position >= required) return false;
    if (required > maxCapacity)
      throw new KryoException("Buffer overflow. Max capacity: " + maxCapacity + ", required: " + required);
    flush();
    while (capacity - position < required) {
      if (capacity == maxCapacity)
        throw new KryoException("Buffer overflow. Available: " + (capacity - position) + ", required: " + required);
      // Grow buffer.
      if (capacity == 0) capacity = 1;
      capacity = Math.min(capacity * 2, maxCapacity);
      if (capacity < 0) capacity = maxCapacity;
      byte[] newBuffer = new byte[capacity];
View Full Code Here

  public void flush () throws KryoException {
    if (outputStream == null) return;
    try {
      outputStream.write(buffer, 0, position);
    } catch (IOException ex) {
      throw new KryoException(ex);
    }
    total += position;
    position = 0;
  }
View Full Code Here

  /** @return true if the buffer has been resized. */
  protected boolean require (int required) throws KryoException {
    if (capacity - position >= required) return false;
    if (required > maxCapacity)
      throw new KryoException("Buffer overflow. Max capacity: " + maxCapacity + ", required: " + required);
    flush();
    while (capacity - position < required) {
      if (capacity == maxCapacity)
        throw new KryoException("Buffer overflow. Available: " + (capacity - position) + ", required: " + required);
      // Grow buffer.
      if (capacity == 0) capacity = 1;
      capacity = Math.min(capacity * 2, maxCapacity);
      if (capacity < 0) capacity = maxCapacity;
      ByteBuffer newBuffer = (niobuffer != null && !niobuffer.isDirect()) ? ByteBuffer.allocate(capacity) : ByteBuffer
View Full Code Here

TOP

Related Classes of com.esotericsoftware.kryo.KryoException

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.