类com.esotericsoftware.kryo.KryoException源码实例Demo

下面列出了怎么用com.esotericsoftware.kryo.KryoException的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: Bats   文件: FastPublisher.java
@Override
public void writeChar(char value) throws KryoException
{
  switch (writeBuffer.remaining()) {
    case 0:
      advanceWriteBuffer();
      writeBuffer.put((byte)(value >>> 8));
      writeBuffer.put((byte)value);
      break;

    case 1:
      writeBuffer.put((byte)(value >>> 8));
      advanceWriteBuffer();
      writeBuffer.put((byte)value);
      break;

    default:
      writeBuffer.put((byte)(value >>> 8));
      writeBuffer.put((byte)value);
      break;
  }
}
 
源代码2 项目: cuba   文件: KryoSerialization.java
@SuppressWarnings("unchecked")
@Override
public Object read(Kryo kryo, Input input, Class type) {
    try {
        ObjectMap graphContext = kryo.getGraphContext();
        ObjectInputStream objectStream = (ObjectInputStream) graphContext.get(this);
        if (objectStream == null) {
            objectStream = new ObjectInputStream(input) {
                @Override
                protected Class<?> resolveClass(ObjectStreamClass desc) throws ClassNotFoundException {
                    return ClassUtils.getClass(KryoSerialization.class.getClassLoader(), desc.getName());
                }
            };
            graphContext.put(this, objectStream);
        }
        return objectStream.readObject();
    } catch (Exception ex) {
        throw new KryoException("Error during Java deserialization.", ex);
    }
}
 
源代码3 项目: Flink-CEPplus   文件: KryoUtils.java
/**
 * Tries to copy the given record from using the provided Kryo instance. If this fails, then
 * the record from is copied by serializing it into a byte buffer and deserializing it from
 * there.
 *
 * @param from Element to copy
 * @param reuse Reuse element for the deserialization
 * @param kryo Kryo instance to use
 * @param serializer TypeSerializer which is used in case of a Kryo failure
 * @param <T> Type of the element to be copied
 * @return Copied element
 */
public static <T> T copy(T from, T reuse, Kryo kryo, TypeSerializer<T> serializer) {
	try {
		return kryo.copy(from);
	} catch (KryoException ke) {
		// Kryo could not copy the object --> try to serialize/deserialize the object
		try {
			byte[] byteArray = InstantiationUtil.serializeToByteArray(serializer, from);

			return InstantiationUtil.deserializeFromByteArray(serializer, reuse, byteArray);
		} catch (IOException ioe) {
			throw new RuntimeException("Could not copy object by serializing/deserializing" +
				" it.", ioe);
		}
	}
}
 
源代码4 项目: phrasal   文件: IOTools.java
/**
 * Deserialize an object.
 * Only supports BIN and BIN_GZ SerializationMode.
 * 
 * If the specified file does not exist or is empty, then this call returns null.
 * 
 * @param inputStream
 * @param type
 * @param mode
 * @return
 * @throws IOException
 * @throws ClassNotFoundException
 */
public static <T> T deserialize(InputStream inStream, Class<T> type, SerializationMode mode) {
  try {
    T object;
    if (mode == SerializationMode.BIN || mode == SerializationMode.BIN_GZ) {
      Kryo kryo = new Kryo();
      kryo.setReferences(false);
      Input input = new Input(mode == SerializationMode.BIN_GZ ? 
          new GZIPInputStream(inStream) : inStream);
      object = kryo.readObject(input, type);
      
    } else {
      throw new UnsupportedOperationException();
    }

    return object;
    
  } catch (KryoException  | IOException e) {
    logger.error("Unable to deserialize {} (mode: {})", mode);
    logger.error("Deserialization exception", e);
    throw new RuntimeException(e);
  }
}
 
源代码5 项目: flink   文件: JavaSerializer.java
@SuppressWarnings({"unchecked", "rawtypes"})
@Override
public T read(Kryo kryo, Input input, Class aClass) {
	try {
		ObjectMap graphContext = kryo.getGraphContext();
		ObjectInputStream objectStream = (ObjectInputStream)graphContext.get(this);
		if (objectStream == null) {
			// make sure we use Kryo's classloader
			objectStream = new InstantiationUtil.ClassLoaderObjectInputStream(input, kryo.getClassLoader());
			graphContext.put(this, objectStream);
		}
		return (T) objectStream.readObject();
	} catch (Exception ex) {
		throw new KryoException("Error during Java deserialization.", ex);
	}
}
 
源代码6 项目: flink   文件: KryoUtils.java
/**
 * Tries to copy the given record from using the provided Kryo instance. If this fails, then
 * the record from is copied by serializing it into a byte buffer and deserializing it from
 * there.
 *
 * @param from Element to copy
 * @param reuse Reuse element for the deserialization
 * @param kryo Kryo instance to use
 * @param serializer TypeSerializer which is used in case of a Kryo failure
 * @param <T> Type of the element to be copied
 * @return Copied element
 */
public static <T> T copy(T from, T reuse, Kryo kryo, TypeSerializer<T> serializer) {
	try {
		return kryo.copy(from);
	} catch (KryoException ke) {
		// Kryo could not copy the object --> try to serialize/deserialize the object
		try {
			byte[] byteArray = InstantiationUtil.serializeToByteArray(serializer, from);

			return InstantiationUtil.deserializeFromByteArray(serializer, reuse, byteArray);
		} catch (IOException ioe) {
			throw new RuntimeException("Could not copy object by serializing/deserializing" +
				" it.", ioe);
		}
	}
}
 
源代码7 项目: flink   文件: NoFetchingInput.java
/**
 * Require makes sure that at least required number of bytes are kept in the buffer. If not, then
 * it will load exactly the difference between required and currently available number of bytes.
 * Thus, it will only load the data which is required and never prefetch data.
 *
 * @param required the number of bytes being available in the buffer
 * @return the number of bytes remaining, which is equal to required
 * @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(new EOFException("No more bytes left."));
		}

		bytesRead += count;
		if(bytesRead == required){
			break;
		}
	}
	limit = required;
	return required;
}
 
源代码8 项目: flink   文件: KryoUtils.java
/**
 * Tries to copy the given record from using the provided Kryo instance. If this fails, then
 * the record from is copied by serializing it into a byte buffer and deserializing it from
 * there.
 *
 * @param from Element to copy
 * @param kryo Kryo instance to use
 * @param serializer TypeSerializer which is used in case of a Kryo failure
 * @param <T> Type of the element to be copied
 * @return Copied element
 */
public static <T> T copy(T from, Kryo kryo, TypeSerializer<T> serializer) {
	try {
		return kryo.copy(from);
	} catch (KryoException ke) {
		// Kryo could not copy the object --> try to serialize/deserialize the object
		try {
			byte[] byteArray = InstantiationUtil.serializeToByteArray(serializer, from);

			return InstantiationUtil.deserializeFromByteArray(serializer, byteArray);
		} catch (IOException ioe) {
			throw new RuntimeException("Could not copy object by serializing/deserializing" +
				" it.", ioe);
		}
	}
}
 
源代码9 项目: turbo-rpc   文件: FastClassResolver.java
public Registration readClass(Input input) {
	int classID = input.readVarInt(true);
	switch (classID) {
	case Kryo.NULL:
		if (TRACE || (DEBUG && kryo.getDepth() == 1))
			log("Read", null);
		return null;
	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;
}
 
源代码10 项目: flink   文件: JavaSerializer.java
@SuppressWarnings({"unchecked", "rawtypes"})
@Override
public T read(Kryo kryo, Input input, Class aClass) {
	try {
		ObjectMap graphContext = kryo.getGraphContext();
		ObjectInputStream objectStream = (ObjectInputStream)graphContext.get(this);
		if (objectStream == null) {
			// make sure we use Kryo's classloader
			objectStream = new InstantiationUtil.ClassLoaderObjectInputStream(input, kryo.getClassLoader());
			graphContext.put(this, objectStream);
		}
		return (T) objectStream.readObject();
	} catch (Exception ex) {
		throw new KryoException("Error during Java deserialization.", ex);
	}
}
 
源代码11 项目: Bats   文件: FastPublisher.java
@Override
public void write(int value) throws KryoException
{
  if (!writeBuffer.hasRemaining()) {
    advanceWriteBuffer();
  }
  writeBuffer.put((byte)value);
}
 
源代码12 项目: Bats   文件: FastPublisher.java
@Override
public void write(byte[] bytes) throws KryoException
{
  int remaining = writeBuffer.remaining();
  if (bytes.length > remaining) {
    writeBuffer.put(bytes, 0, remaining);
    advanceWriteBuffer();
    write(bytes, remaining, bytes.length - remaining);
  } else {
    writeBuffer.put(bytes);
  }
}
 
源代码13 项目: pushfish-android   文件: KryoBackedDecoder.java
public boolean readBoolean() throws EOFException {
    try {
        return input.readBoolean();
    } catch (KryoException e) {
        throw maybeEndOfStream(e);
    }
}
 
源代码14 项目: Bats   文件: FastPublisher.java
@Override
public void writeByte(int value) throws KryoException
{
  if (!writeBuffer.hasRemaining()) {
    advanceWriteBuffer();
  }
  writeBuffer.put((byte)value);
}
 
源代码15 项目: dubbox   文件: KryoObjectInput.java
public short readShort() throws IOException {
    try {
        return input.readShort();
    } catch (KryoException e) {
        throw new IOException(e);
    }
}
 
源代码16 项目: pushfish-android   文件: KryoBackedDecoder.java
public int readInt() throws EOFException {
    try {
        return input.readInt();
    } catch (KryoException e) {
        throw maybeEndOfStream(e);
    }
}
 
源代码17 项目: dubbox   文件: KryoObjectInput.java
public String readUTF() throws IOException {
        // TODO
        try {
//            return kryo.readObject(input, String.class);
            return input.readString();
        } catch (KryoException e) {
            throw new IOException(e);
        }
    }
 
源代码18 项目: pushfish-android   文件: KryoBackedDecoder.java
public void readBytes(byte[] buffer, int offset, int count) throws EOFException {
    try {
        input.readBytes(buffer, offset, count);
    } catch (KryoException e) {
        throw maybeEndOfStream(e);
    }
}
 
源代码19 项目: dubbox   文件: KryoObjectInput.java
public int readInt() throws IOException {
    try {
        return input.readInt();
    } catch (KryoException e) {
        throw new IOException(e);
    }
}
 
源代码20 项目: dubbox   文件: KryoObjectInput.java
public String readUTF() throws IOException {
        // TODO
        try {
//            return kryo.readObject(input, String.class);
            return input.readString();
        } catch (KryoException e) {
            throw new IOException(e);
        }
    }
 
源代码21 项目: pushfish-android   文件: KryoBackedDecoder.java
public byte readByte() throws EOFException {
    try {
        return input.readByte();
    } catch (KryoException e) {
        throw maybeEndOfStream(e);
    }
}
 
源代码22 项目: dubbox-hystrix   文件: KryoObjectInput.java
public short readShort() throws IOException {
    try {
        return input.readShort();
    } catch (KryoException e) {
        throw new IOException(e);
    }
}
 
源代码23 项目: attic-apex-core   文件: FastPublisher.java
@Override
public void write(int value) throws KryoException
{
  if (!writeBuffer.hasRemaining()) {
    advanceWriteBuffer();
  }
  writeBuffer.put((byte)value);
}
 
源代码24 项目: dubbox   文件: KryoObjectInput.java
public Object readObject() throws IOException, ClassNotFoundException {
        // TODO
//        throw new UnsupportedOperationException();
        try {
            return kryo.readClassAndObject(input);
        } catch (KryoException e) {
            throw new IOException(e);
        }
    }
 
源代码25 项目: dubbox   文件: KryoObjectInput.java
public byte[] readBytes() throws IOException {
    try {
        int len = input.readInt();
        if (len < 0) {
            return null;
        } else if (len == 0) {
            return new byte[]{};
        } else {
            return input.readBytes(len);
        }
    } catch (KryoException e) {
        throw new IOException(e);
    }
}
 
源代码26 项目: dubbo-2.6.5   文件: KryoObjectInput.java
@Override
public boolean readBool() throws IOException {
    try {
        return input.readBoolean();
    } catch (KryoException e) {
        throw new IOException(e);
    }
}
 
源代码27 项目: pushfish-android   文件: KryoBackedDecoder.java
public String readNullableString() throws EOFException {
    try {
        return input.readString();
    } catch (KryoException e) {
        throw maybeEndOfStream(e);
    }
}
 
源代码28 项目: dubbo-2.6.5   文件: KryoObjectInput.java
@Override
public float readFloat() throws IOException {
    try {
        return input.readFloat();
    } catch (KryoException e) {
        throw new IOException(e);
    }
}
 
源代码29 项目: dubbox-hystrix   文件: KryoObjectInput.java
public double readDouble() throws IOException {
    try {
        return input.readDouble();
    } catch (KryoException e) {
        throw new IOException(e);
    }
}
 
源代码30 项目: dubbox   文件: KryoObjectInput.java
public float readFloat() throws IOException {
    try {
        return input.readFloat();
    } catch (KryoException e) {
        throw new IOException(e);
    }
}