Refine search
public void read (Kryo kryo, Input input) { objectID = input.readInt(true); int methodClassID = input.readInt(true); Class methodClass = kryo.getRegistration(methodClassID).getType(); byte methodIndex = input.readByte(); try { cachedMethod = getMethods(kryo, methodClass)[methodIndex]; } catch (IndexOutOfBoundsException ex) { throw new KryoException("Invalid method index " + methodIndex + " for class: " + methodClass.getName()); } Serializer[] serializers = cachedMethod.serializers; Class[] parameterTypes = cachedMethod.method.getParameterTypes(); Object[] args = new Object[serializers.length]; this.args = args; for (int i = 0, n = args.length; i < n; i++) { Serializer serializer = serializers[i]; if (serializer != null) args[i] = kryo.readObjectOrNull(input, parameterTypes[i], serializer); else args[i] = kryo.readClassAndObject(input); } responseData = input.readByte(); } }
output = new Output(outputStream); previousOut = target; if (output.position() != 0) { throw new IllegalStateException("The Kryo Output still contains data from a previous " + "serialize call. It has to be flushed or cleared at the end of the serialize call."); kryo.writeClassAndObject(output, record); output.flush(); output.clear(); Throwable cause = ke.getCause(); if (cause instanceof EOFException) { throw (EOFException) cause;
public void read (Input input, Object object) { try { if (TRACE) trace("kryo", "Read field: " + this + " (" + type.getName() + ")" + " pos=" + input.position()); Object value; Serializer serializer = this.serializer; if (concreteType == null) { Registration registration = kryo.readClass(input); if (registration == null) value = null; else { if (serializer == null) serializer = registration.getSerializer(); value = kryo.readObject(input, registration.getType(), serializer); if (serializer == null) this.serializer = serializer = kryo.getSerializer(valueClass); throw new KryoException("Error accessing field: " + this + " (" + type.getName() + ")", ex); } 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; } finally {
public void write (Kryo kryo, Output output, T object) { Class type = object.getClass(); for (int i = 0, n = properties.length; i < n; i++) { CachedProperty property = properties[i]; try { if (TRACE) trace("kryo", "Write property: " + property + " (" + type.getName() + ")"); Object value = property.get(object); Serializer serializer = property.serializer; if (serializer != null) kryo.writeObjectOrNull(output, value, serializer); else kryo.writeClassAndObject(output, value); } catch (IllegalAccessException ex) { throw new KryoException("Error accessing getter method: " + property + " (" + type.getName() + ")", ex); } catch (InvocationTargetException ex) { throw new KryoException("Error invoking getter method: " + property + " (" + type.getName() + ")", ex); } catch (KryoException ex) { ex.addTrace(property + " (" + type.getName() + ")"); throw ex; } catch (RuntimeException runtimeEx) { KryoException ex = new KryoException(runtimeEx); ex.addTrace(property + " (" + type.getName() + ")"); throw ex; } } }
protected Registration readName (Input input) { int nameId = input.readVarInt(true); if (nameIdToClass == null) nameIdToClass = new IntMap(); Class type = nameIdToClass.get(nameId); if (type == null) { // Only read the class name the first time encountered in object graph. String className = input.readString(); type = getTypeByName(className); if (type == null) { try { type = Class.forName(className, false, kryo.getClassLoader()); } catch (ClassNotFoundException ex) { if (WARN) warn("kryo", "Unable to load class " + className + " with kryo's ClassLoader. Retrying with current.."); try { type = Class.forName(className); } catch (ClassNotFoundException e) { throw new KryoException("Unable to find class: " + className, ex); } } if (nameToClass == null) nameToClass = new ObjectMap(); nameToClass.put(className, type); } nameIdToClass.put(nameId, type); if (TRACE) trace("kryo", "Read class name: " + className); } else { if (TRACE) trace("kryo", "Read class name reference " + nameId + ": " + className(type)); } return kryo.getRegistration(type); }
public T read (Kryo kryo, Input input, Class<T> type) { T object = kryo.newInstance(type); kryo.reference(object); for (int i = 0, n = properties.length; i < n; i++) { CachedProperty property = properties[i]; try { if (TRACE) trace("kryo", "Read property: " + property + " (" + object.getClass() + ")"); Object value; Serializer serializer = property.serializer; if (serializer != null) value = kryo.readObjectOrNull(input, property.setMethodType, serializer); else value = kryo.readClassAndObject(input); property.set(object, value); } catch (IllegalAccessException ex) { throw new KryoException("Error accessing setter method: " + property + " (" + object.getClass().getName() + ")", ex); } catch (InvocationTargetException ex) { throw new KryoException("Error invoking setter method: " + property + " (" + object.getClass().getName() + ")", ex); } catch (KryoException ex) { ex.addTrace(property + " (" + object.getClass().getName() + ")"); throw ex; } catch (RuntimeException runtimeEx) { KryoException ex = new KryoException(runtimeEx); ex.addTrace(property + " (" + object.getClass().getName() + ")"); throw ex; } } return object; }
public void write (Kryo kryo, Output output, EnumSet object) { Serializer serializer; if (object.isEmpty()) { EnumSet tmp = EnumSet.complementOf(object); if (tmp.isEmpty()) throw new KryoException("An EnumSet must have a defined Enum to be serialized."); serializer = kryo.writeClass(output, tmp.iterator().next().getClass()).getSerializer(); } else { serializer = kryo.writeClass(output, object.iterator().next().getClass()).getSerializer(); } output.writeInt(object.size(), true); for (Object element : object) serializer.write(kryo, output, element); }
public Enum read (Kryo kryo, Input input, Class<Enum> type) { String name = kryo.readObject(input, String.class, stringSerializer); try { return Enum.valueOf(enumType, name); } catch (IllegalArgumentException e) { throw new KryoException("Invalid name for enum \"" + enumType.getName() + "\": " + name, e); } } }
@SuppressWarnings("unchecked") @Override public T deserialize(DataInputView source) throws IOException { if (CONCURRENT_ACCESS_CHECK) { enterExclusiveThread(); } try { checkKryoInitialized(); if (source != previousIn) { DataInputViewStream inputStream = new DataInputViewStream(source); input = new NoFetchingInput(inputStream); previousIn = source; } try { return (T) kryo.readClassAndObject(input); } catch (KryoException ke) { Throwable cause = ke.getCause(); if (cause instanceof EOFException) { throw (EOFException) cause; } else { throw ke; } } } finally { if (CONCURRENT_ACCESS_CHECK) { exitExclusiveThread(); } } }
public PyObject read(Kryo kryo, Input input, Class<PyObject> type) { int len = input.readInt(); byte[] serPo = input.readBytes(len); try { return (PyObject) SerializationUtils.deserializeObject(serPo); } catch (IOException e) { throw new KryoException("Failed to deserialize object.", e); } catch (ClassNotFoundException e) { // this should only be possible if jython isn't on the class-path throw new KryoException("Failed to deserialize object.", e); } } }
public boolean serialize(MonitoringData monitoringData) { try { try { kryo.writeClassAndObject(output, monitoringData); output.flush(); return true; } catch (KryoException ky) { // The BufferOverflowException might get wrapped, so we have to handle both. // The exception indicates that we have tried to write beyond the buffer's capacity if (ky.getCause() != null && ky.getCause() instanceof BufferOverflowException) { throw (BufferOverflowException) ky.getCause(); } throw ky; } } catch (BufferOverflowException be) { return false; } }
public void write(Kryo kryo, Output output, PyObject po) { try { byte[] serPo = SerializationUtils.serializeObject(po); output.writeInt(serPo.length); output.write(serPo); } catch (IOException e) { throw new KryoException("Failed to serialize object.", e); } }
@Override public ByteBuffer serialize(V v) { KryoContext kryoContext = kryoContextHolder.get(); Kryo kryo = kryoContext.getKryo(); Output out = kryoContext.getOut(); out.clear(); while (true) { try { kryo.writeClassAndObject(out, v); break; } catch (KryoException ex) { if (ex.getMessage() != null && ex.getMessage().startsWith("Buffer overflow.")) { out = kryoContext.expandOut(); } else { throw ex; } } } return ByteBuffer.wrap(out.toBytes()); }
@Override public void write(Kryo kryo, Output output, StructuredRecord record) { // First write out the schema kryo.writeObject(output, record.getSchema()); // Then write out the data try { DATUM_WRITER.encode(record, new KryoEncoder(output)); } catch (IOException e) { throw new KryoException("Failed to encode StructuredRecord " + record.getSchema().getRecordName(), e); } }
public void write (Output output, Object object) { try { if (varIntsEnabled) output.writeInt(field.getInt(object), false); else output.writeInt(field.getInt(object)); } catch (Exception e) { KryoException ex = new KryoException(e); ex.addTrace(this + " (" + type.getName() + ")"); throw ex; } }
public void read (Input input, Object object) { try { if (varIntsEnabled) field.setInt(object, input.readInt(false)); else field.setInt(object, input.readInt()); } catch (Exception e) { KryoException ex = new KryoException(e); ex.addTrace(this + " (" + type.getName() + ")"); throw ex; } }
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; }
private void readData(Input i, Kryo kryo, long fromTime, long toTime, final boolean reverse) { monitoringDataList = new ArrayList<MonitoringData>(); try { while (i.available() > 0) { try { Object data = kryo.readClassAndObject(i); if (data instanceof MonitoringData){ MonitoringData monitoringData = (MonitoringData) data; if (monitoringData.getTimeStamp().getTime() <= toTime && monitoringData.getTimeStamp().getTime() >= fromTime) { monitoringDataList.add(monitoringData); } } } catch (KryoException e){ logger.error("cant load old monitoringdata: "+e.getMessage()+" , skip file:"+file.getAbsolutePath()); break; } } } catch (IOException e) { throw new RuntimeException(e); } Collections.sort(monitoringDataList, new Comparator<MonitoringData>() { @Override public int compare(MonitoringData o1, MonitoringData o2) { return o1.getTimeStamp().compareTo(o2.getTimeStamp()); } }); if (!reverse) Collections.reverse(monitoringDataList); }
public void flush () throws KryoException { if (position() > 0) { try { writeChunkSize(); super.flush(); } catch (IOException ex) { throw new KryoException(ex); } } super.flush(); }
public void readFully (byte[] b, int off, int len) throws IOException { try { input.readBytes(b, off, len); } catch (KryoException e) { throw new EOFException(e.getMessage()); } }