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). */
  final 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(niobuffer, limit, capacity - limit);
      if (count == -1) throw new KryoException("Buffer underflow.");
      remaining += count;
      if (remaining >= required) {
        limit += count;
        return remaining;
      }
    }

    // Compact. Position after compaction can be non-zero
    niobuffer.position(position);
    niobuffer.compact();
    total += position;
    position = 0;

    while (true) {
      count = fill(niobuffer, 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


    case NAME + 2: // Offset for NAME and NULL.
      return readName(input);
    }
    if (classID == memoizedClassId) return memoizedClassIdValue;
    Registration registration = idToRegistration.get(classID - 2);
    if (registration == null) throw new KryoException("Encountered unregistered class ID: " + (classID - 2));
    if (TRACE) trace("kryo", "Read class " + (classID - 2) + ": " + className(registration.getType()));
    memoizedClassId = classID;
    memoizedClassIdValue = registration;
    return registration;
  }
View Full Code Here

      if (nameToClass != null) type = nameToClass.get(className);
      if (type == null) {
        try {
          type = Class.forName(className, false, kryo.getClassLoader());
        } catch (ClassNotFoundException ex) {
          throw new KryoException("Unable to find class: " + className, ex);
        }
        if (nameToClass == null) nameToClass = new ObjectMap();
        nameToClass.put(className, type);
      }
      nameIdToClass.put(nameId, type);
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.
      capacity = Math.min(capacity * 2, maxCapacity);
      if (capacity < 0) capacity = maxCapacity;
      ByteBuffer newBuffer = ByteBuffer.allocateDirect(capacity);
      // Copy the whole buffer
View Full Code Here

      niobuffer.position(0);
      niobuffer.get(tmp);
      niobuffer.position(0);
      outputStream.write(tmp, 0, position);
    } catch (IOException ex) {
      throw new KryoException(ex);
    }
    total += position;
    position = 0;
  }
View Full Code Here

      super(fieldSerializer);
    }

    public Object getField (Object object) throws IllegalArgumentException, IllegalAccessException {
      if (accessIndex != -1) return ((FieldAccess)access).get(object, accessIndex);
      throw new KryoException("Unknown acess index");
    }
View Full Code Here

    public void setField (Object object, Object value) throws IllegalArgumentException, IllegalAccessException {
      if (accessIndex != -1)
        ((FieldAccess)access).set(object, accessIndex, value);
      else
        throw new KryoException("Unknown acess index");
    }
View Full Code Here

    public void copy (Object original, Object copy) {
      try {
        if (accessIndex != -1) {
          access.set(copy, accessIndex, kryo.copy(access.get(original, accessIndex)));
        } else
          throw new KryoException("Unknown acess index");
      } catch (KryoException ex) {
        ex.addTrace(this + " (" + type.getName() + ")");
        throw ex;
      } catch (RuntimeException runtimeEx) {
        KryoException ex = new KryoException(runtimeEx);
        ex.addTrace(this + " (" + type.getName() + ")");
        throw ex;
      }
    }
View Full Code Here

  final public void readBytes (Object dstObj, long offset, long count) throws KryoException {
    /* Unsafe supports efficient bulk reading into arrays of primitives only because of JVM limitations due to GC */
    if (dstObj.getClass().isArray())
      readBytes(dstObj, 0, offset, (int)count);
    else {
      throw new KryoException("Only bulk reads of arrays is supported");
    }
  }
View Full Code Here

      } else
        objectStream.reset();
      objectStream.writeObject(object);
      objectStream.flush();
    } catch (Exception ex) {
      throw new KryoException("Error during Java serialization.", ex);
    }
  }
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.