Read object by reflection.

@param <T>   the type parameter
@param kryo  the kryo
@param input the input
@param clazz the clazz
@return the t
349717
@SneakyThrows
    private static <T> T readObjectByReflection(final Kryo kryo, final Input input, final Class<T> clazz) {
        val className = kryo.readObject(input, String.class);
        val foundClass = (Class<T>) Class.forName(className);
        val result = kryo.readObject(input, foundClass);

        if (!clazz.isAssignableFrom(result.getClass())) {
            throw new ClassCastException("Result [" + result
                + " is of type " + result.getClass()
                + " when we were expecting " + clazz);
        }
        return result;
    }
86579
@SuppressWarnings("unchecked")
  <T> T parse(Class<T> clazz) throws JsonParserException {
    advanceToken();
    Object parsed = currentValue();
    if (advanceToken() != Token.EOF)
      throw createParseException(null, "Expected end of input, got " + token, true);
    if (clazz != Object.class && (parsed == null || clazz != parsed.getClass()))
      throw createParseException(null, "JSON did not contain the correct type, expected " + clazz.getName()
          + ".", true);
    return (T)(parsed);
  }
636152
@SuppressWarnings({ "unchecked", "rawtypes" })
    public static <T> T deserialize(Input in, Type target) {
        if (BLACK_LIST == null) {
            //log.info("Black list is not yet initialized");
            try {
                loadBlackList();
            } catch (IOException e) {
                throw new RuntimeException("Failed to init black-list");
            }
        }
        byte type = in.readDataType();
        if (log.isTraceEnabled()) {
            log.trace("Type: {} target: {}", type, (target != null ? target.toString() : "Target not specified"));
        } else if (log.isDebugEnabled()) {
            log.debug("Datatype: {}", DataTypes.toStringValue(type));
        }
        Object result = null;
        switch (type) {
            case DataTypes.CORE_NULL:
                result = in.readNull();
                break;
            case DataTypes.CORE_BOOLEAN:
                result = in.readBoolean();
                break;
            case DataTypes.CORE_NUMBER:
                result = in.readNumber();
                break;
            case DataTypes.CORE_STRING:
                try {
                    if (target != null && ((Class) target).isEnum()) {
                        log.warn("Enum target specified");
                        String name = in.readString();
                        result = Enum.valueOf((Class) target, name);
                    } else {
                        result = in.readString();
                    }
                } catch (RuntimeException e) {
                    log.error("failed to deserialize {}", target, e);
                    throw e;
                }
                break;
            case DataTypes.CORE_DATE:
                result = in.readDate();
                break;
            case DataTypes.CORE_ARRAY:
                result = in.readArray(target);
                break;
            case DataTypes.CORE_MAP:
                result = in.readMap();
                break;
            case DataTypes.CORE_XML:
                result = in.readXML();
                break;
            case DataTypes.CORE_OBJECT:
                result = in.readObject();
                break;
            case DataTypes.CORE_BYTEARRAY:
                result = in.readByteArray();
                break;
            case DataTypes.CORE_VECTOR_INT:
                result = in.readVectorInt();
                break;
            case DataTypes.CORE_VECTOR_UINT:
                result = in.readVectorUInt();
                break;
            case DataTypes.CORE_VECTOR_NUMBER:
                result = in.readVectorNumber();
                break;
            case DataTypes.CORE_VECTOR_OBJECT:
                result = in.readVectorObject();
                break;
            case DataTypes.OPT_REFERENCE:
                result = in.readReference();
                break;
            case DataTypes.CORE_END_OBJECT:
                // end-of-object returned, not sure that we should ever get here
                log.debug("End-of-object detected");
                break;
            default:
                result = in.readCustom();
                break;
        }
        return (T) result;
    }
211221
public static Object readPrimitive(Class<?> clazz, String value) throws Exception {
        if (clazz == String.class) {
            return value;
        } else if (clazz == Long.class) {
            return Long.parseLong(value);
        } else if (clazz == Integer.class) {
            return Integer.parseInt(value);
        } else if (clazz == Double.class) {
            return Double.parseDouble(value);
        } else if (clazz == Boolean.class) {
            return Boolean.parseBoolean(value);
        } else if (clazz == Byte.class) {
            return Byte.parseByte(value);
        } else if (clazz == Short.class) {
            return Short.parseShort(value);
        } else if (clazz == Float.class) {
            return Float.parseFloat(value);
        } else {
            throw new Exception("Unsupported primitive: " + clazz); //$NON-NLS-1$
        }
    }
48911
public void parse (InputStream input) {
		try {
			parse(new InputStreamReader(input, "UTF-8"));
		} catch (IOException ex) {
			throw new SerializationException(ex);
		} finally {
			StreamUtils.closeQuietly(input);
		}
	}
754675
public <T> T read(final InputStream input, Class<T> rootType) {
        try {
            try {
                reader = factory().createXMLEventReader(input);
                return read(rootType);
            } finally {
                if (reader != null) {
                    reader.close();
                }
            }
        } catch (RuntimeException ex) {
            throw ex;
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }
45533
static Set<String> readServiceFile(InputStream input) throws IOException {
    HashSet<String> serviceClasses = new HashSet<String>();
    Closer closer = Closer.create();
    try {
      // TODO(gak): use CharStreams
      BufferedReader r = closer.register(new BufferedReader(new InputStreamReader(input, UTF_8)));
      String line;
      while ((line = r.readLine()) != null) {
        int commentStart = line.indexOf('#');
        if (commentStart >= 0) {
          line = line.substring(0, commentStart);
        }
        line = line.trim();
        if (!line.isEmpty()) {
          serviceClasses.add(line);
        }
      }
      return serviceClasses;
    } catch (Throwable t) {
      throw closer.rethrow(t);
    } finally {
      closer.close();
    }
  }
469097
public static <T> T convertToObject(Class<T> clazz, InputStream inputStream) {
		return convertToObject(clazz, new InputStreamReader(inputStream));
	}
1035962
public static <T> InputReader getInstance(T input, String cs, Set<ParserFeature> features) throws IOException
    {
        return getInstance(input, -1, Charset.forName(cs), features);
    }
1349168
public final <T> T nextValue(@NonNull Class<T> clazz) throws IOException {
      if (JsonSerializable.class.isAssignableFrom(clazz)) {
         return readReadable(clazz);
      } else if (peek() == JsonTokenType.BEGIN_OBJECT) {
         Reflect reflected = Reflect.onClass(clazz);
         Optional<Method> staticRead = reflected.getMethods("read", 1).stream()
                                                .filter(m -> JsonReader.class.isAssignableFrom(
                                                   m.getParameterTypes()[0]))
                                                .filter(m -> Modifier.isStatic(m.getModifiers()))
                                                .findFirst();

         if (staticRead.isPresent()) {
            try {
               beginObject();
               T result = Cast.as(staticRead.get().invoke(null, this));
               endObject();
               return result;
            } catch (IllegalAccessException | InvocationTargetException e) {
               throw new IOException(e);
            }
         }

         try {
            T object = Reflect.onClass(clazz).create().get();
            beginObject();
            new BeanMap(object).putAll(nextMap());
            endObject();
            return object;
         } catch (ReflectionException e) {
            throw new IOException(e);
         }
      }
      return nextValue().as(clazz);
   }
25032
public <T> T toObject(String jsonString, Class<T> clazz) {
		if (StringUtils.isEmpty(jsonString)) {
			return null;
		}

		try {
			return mapper.readValue(jsonString, clazz);
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
229817
@SuppressWarnings("StatementWithEmptyBody")
    public static byte[] decode(final String input) {
        ByteArrayInputStream in = new ByteArrayInputStream(input.getBytes());
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try {
            while (decodeChunk(out, in)) {
                // do nothing
            }
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }

        return out.toByteArray();
    }
623372
public static <T> T read(Class<T> clazz, Object id) {
		return execute(new ReadEntityTransaction<T>(clazz, id));
	}
1119137
public static String readResourceToStringChecked(Class<?> clazz, String fn) throws IOException {
		try (InputStream stream = getResourceAsStream(clazz, fn)) {
			return IOUtils.toString(asReaderUTF8Lenient(stream));
		}
	}
930068
public <T> T read(Class<T> clazz) {
        try {
            return readInternal(clazz);
        } catch (Exception e) {
            if (e instanceof RuntimeException) {
                throw (RuntimeException) e;
            }
            if (e instanceof IOException) {
                throw new UncheckedIOException((IOException) e);
            }
            throw new RuntimeException(e);
        }
    }
1137354
public static String readLine(final InputStream input) throws IOException {
		return new BufferedReader(new InputStreamReader(input, Charsets.UTF_8)).readLine();
	}
1374631
public <T> T deserialize(final InputStream stream, final int bufferSize) {
    ByteBufferInput in = new ByteBufferInput(stream, bufferSize);
    Kryo kryo = borrow();
    try {
      @SuppressWarnings("unchecked")
      T obj = (T) kryo.readClassAndObject(in);
      return obj;
    } finally {
      release(kryo);
    }
  }