Package com.esotericsoftware.kryo

Examples of com.esotericsoftware.kryo.KryoException


   * @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


   * @throws KryoException
   */
  @Override
  protected int require(int required) throws KryoException {
    if(required > capacity) {
      throw new KryoException("Buffer too small: capacity: " + capacity + ", " +
          "required: " + required);
    }

    position = 0;
    int bytesRead = 0;
    int count;
    while(true){
      count = fill(buffer, bytesRead, required - bytesRead);

      if(count == -1){
        throw new KryoException("Buffer underflow");
      }

      bytesRead += count;
      if(bytesRead == required){
        break;
View Full Code Here

    }

    try {
      return inputStream.read(bytes, offset, count);
    }catch(IOException ex){
      throw new KryoException(ex);
    }
  }
View Full Code Here

  @Override
  public void skip(int count) throws KryoException {
    try{
      inputStream.skip(count);
    }catch(IOException ex){
      throw new KryoException(ex);
    }
  }
View Full Code Here

      while(true){
        c = inputStream.read(bytes, offset+bytesRead, count-bytesRead);

        if(c == -1){
          throw new KryoException("Buffer underflow");
        }

        bytesRead += c;

        if(bytesRead == count){
          break;
        }
      }
    }catch(IOException ex){
      throw new KryoException(ex);
    }
  }
View Full Code Here

    public Enum create (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 (serializer == null) cachedField.serializer = serializer = kryo.getSerializer(cachedField.fieldClass);
          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 = null;

        Class concreteType = cachedField.fieldClass;
        Serializer serializer = cachedField.serializer;
        if (concreteType == null) {
          Registration registration = kryo.readClass(input);
          if (registration != null) { // Else value is null.
            if (serializer == null) serializer = registration.getSerializer();
            value = kryo.readObject(input, registration.getType(), serializer);
          }
        } else {
          if (serializer == null) cachedField.serializer = serializer = kryo.getSerializer(concreteType);
          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;
      }
    }
  }
View Full Code Here

    kryo.writeObject(deflaterOutput, object, serializer);
    deflaterOutput.flush();
    try {
      deflaterStream.finish();
    } catch (IOException ex) {
      throw new KryoException(ex);
    }
  }
View Full Code Here

  /** @return true if the buffer has been resized. */
  private 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.
      capacity = Math.min(capacity * 2, maxCapacity);
      if (capacity < 0) capacity = maxCapacity;
      byte[] newBuffer = new byte[capacity];
      System.arraycopy(buffer, 0, newBuffer, 0, position);
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.