Read an object from HDFS (or local) using default Java object serialization

@param path    File to read
@param type    Class of the object to read
@param sc      Spark context
@param <T>     Type of the object to read
486585
public static <T> T readObjectFromFile(String path, Class<T> type, JavaSparkContext sc) throws IOException {
        return readObjectFromFile(path, type, sc.sc());
    }
906855
@SuppressWarnings("unchecked")
  public static <E> DatumReader<E> getDatumReaderForType(Class<E> type, Schema writerSchema) {
    Schema readerSchema = getReaderSchema(type, writerSchema);
    GenericData dataModel = getDataModelForType(type);
    if (dataModel instanceof ReflectData) {
      return new ReflectDatumReader<E>(writerSchema, readerSchema, (ReflectData)dataModel);
    } else if (dataModel instanceof SpecificData) {
      return new SpecificDatumReader<E>(writerSchema, readerSchema, (SpecificData)dataModel);
    } else {
      return new GenericDatumReader<E>(writerSchema, readerSchema, dataModel);
    }
  }
469051
def load(cls, sc, path):
        
        model = cls._load_java(sc, path)
        wrapper =\
            sc._jvm.org.apache.spark.mllib.api.python.PowerIterationClusteringModelWrapper(model)
        return PowerIterationClusteringModel(wrapper)
451775
public static <T> CsvWriterDSL<T> from(Class<T> type) {
        return from((Type)type);
    }
577026
public Csv schema(TypeInformation<Row> schemaType) {
		Preconditions.checkNotNull(schemaType);
		internalProperties.putString(FORMAT_SCHEMA, TypeStringUtils.writeTypeInfo(schemaType));
		return this;
	}
185157
public static synchronized Database lookupDatabaseObject(String type,
            String path) {

        // A VoltDB extension to work around ENG-6044
        /* disabled 14 lines ...
        Object  key = path;
        HashMap databaseMap;

        if (type == DatabaseURL.S_FILE) {
            databaseMap = fileDatabaseMap;
            key         = filePathToKey(path);
        } else if (type == DatabaseURL.S_RES) {
            databaseMap = resDatabaseMap;
        } else if (type == DatabaseURL.S_MEM) {
            databaseMap = memDatabaseMap;
        } else {
            throw (Error.runtimeError(
                ErrorCode.U_S0500, "DatabaseManager.lookupDatabaseObject()"));
        }
           ... disabled 14 lines */

        assert (type == DatabaseURL.S_MEM);
        java.util.HashMap<String, Database> databaseMap = memDatabaseMap;
        String key = path;
        // End of VoltDB extension

        return (Database) databaseMap.get(key);
    }
17075
@SuppressWarnings("unchecked")
    public <T> T readBodyAsObject(Class<T> type) {
        Charset charset = readCharset();
        InputStream inputStream = new ByteArrayInputStream(message.getBodyContent());
        InputStreamReader inputReader = new InputStreamReader(inputStream, charset);
        StreamSource streamSource = new StreamSource(inputReader);
        try {
            Unmarshaller unmarshaller = JAXBContext.newInstance(type).createUnmarshaller();
            if (type.isAnnotationPresent(XmlRootElement.class)) {
                return (T)unmarshaller.unmarshal(streamSource);
            } else {
                JAXBElement<T> element = unmarshaller.unmarshal(streamSource, type);
                return element.getValue();
            }
        } catch (JAXBException e) {
            throw new RuntimeException(e);
        }
    }
1207791
public <T> T read (Class<T> type) throws YamlException {
		return read(type, null);
	}
353486
@Override
    <T> T read(Class<T> rootType) {
        try {
            try {
                return parseRemaining(rootType);
            } finally {
                input.close();
            }
        } catch (RuntimeException ex) {
            throw ex;
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }
287443
public <T> T readObject (Input input, Class<T> type) {
		if (input == null) throw new IllegalArgumentException("input cannot be null.");
		if (type == null) throw new IllegalArgumentException("type cannot be null.");
		beginObject();
		try {
			T object;
			if (references) {
				int stackSize = readReferenceOrNull(input, type, false);
				if (stackSize == REF) return (T)readObject;
				object = (T)getRegistration(type).getSerializer().read(this, input, type);
				if (stackSize == readReferenceIds.size) reference(object);
			} else
				object = (T)getRegistration(type).getSerializer().read(this, input, type);
			if (TRACE || (DEBUG && depth == 1)) log("Read", object, input.position());
			return object;
		} finally {
			if (--depth == 0 && autoReset) reset();
		}
	}
165284
@Override
    public Map<MetadataType, MetadataComponent> deserialize(Descriptor descriptor, EnumSet<MetadataType> types) throws IOException
    {
        Map<MetadataType, MetadataComponent> components = Maps.newHashMap();

        File statsFile = new File(descriptor.filenameFor(Component.STATS));
        if (!statsFile.exists() && types.contains(MetadataType.STATS))
        {
            components.put(MetadataType.STATS, MetadataCollector.defaultStatsMetadata());
        }
        else
        {
            try (DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(statsFile))))
            {
                EstimatedHistogram rowSizes = EstimatedHistogram.serializer.deserialize(in);
                EstimatedHistogram columnCounts = EstimatedHistogram.serializer.deserialize(in);
                ReplayPosition replayPosition = ReplayPosition.serializer.deserialize(in);
                long minTimestamp = in.readLong();
                long maxTimestamp = in.readLong();
                int maxLocalDeletionTime = in.readInt();
                double bloomFilterFPChance = in.readDouble();
                double compressionRatio = in.readDouble();
                String partitioner = in.readUTF();
                int nbAncestors = in.readInt();
                Set<Integer> ancestors = new HashSet<>(nbAncestors);
                for (int i = 0; i < nbAncestors; i++)
                    ancestors.add(in.readInt());
                StreamingHistogram tombstoneHistogram = StreamingHistogram.serializer.deserialize(in);
                int sstableLevel = 0;
                if (in.available() > 0)
                    sstableLevel = in.readInt();

                int colCount = in.readInt();
                List<ByteBuffer> minColumnNames = new ArrayList<>(colCount);
                for (int i = 0; i < colCount; i++)
                    minColumnNames.add(ByteBufferUtil.readWithShortLength(in));

                colCount = in.readInt();
                List<ByteBuffer> maxColumnNames = new ArrayList<>(colCount);
                for (int i = 0; i < colCount; i++)
                    maxColumnNames.add(ByteBufferUtil.readWithShortLength(in));

                if (types.contains(MetadataType.VALIDATION))
                    components.put(MetadataType.VALIDATION,
                                   new ValidationMetadata(partitioner, bloomFilterFPChance));
                if (types.contains(MetadataType.STATS))
                    components.put(MetadataType.STATS,
                                   new StatsMetadata(rowSizes,
                                                     columnCounts,
                                                     replayPosition,
                                                     minTimestamp,
                                                     maxTimestamp,
                                                     maxLocalDeletionTime,
                                                     compressionRatio,
                                                     tombstoneHistogram,
                                                     sstableLevel,
                                                     minColumnNames,
                                                     maxColumnNames,
                                                     true,
                                                     ActiveRepairService.UNREPAIRED_SSTABLE));
                if (types.contains(MetadataType.COMPACTION))
                    components.put(MetadataType.COMPACTION,
                                   new CompactionMetadata(ancestors, null));
            }
        }
        return components;
    }
316009
public static void writeStringToFile(String path, String toWrite, SparkContext sc) throws IOException {
        writeStringToFile(path, toWrite, sc.hadoopConfiguration());
    }
1325853
public static PrototypeMeasurementFilterSpecification loadFromPath(String path)
      throws IOException {
    byte[] jsonData = Files.readAllBytes(Paths.get(path));
    ObjectMapper objectMapper = new ObjectMapper();
    return objectMapper.readValue(
        jsonData, PrototypeMeasurementFilterSpecification.class);
  }
847147
@Override
    public Object readFrom(Class<Object> c, Type t, Annotation[] anns, MediaType mt,
                           MultivaluedMap<String, String> headers, InputStream is) throws IOException, WebApplicationException {
        // TODO Auto-generated method stub
        //if Type t contains IAttachment, IMutibody, convert to Attachment, Mutibody to adapt CXF MultipartProvider.readFrom
        multipartProvider.setMessageContext(mc);
        ParameterizedType origType = null;
        Type[] actualType = null;
        if (ParameterizedType.class.isAssignableFrom(t.getClass())) {
            origType = (ParameterizedType) t;
            actualType = origType.getActualTypeArguments();
            for (int i = 0; i < actualType.length; i++) {
                if (actualType[i].equals(IAttachment.class)) {
                    actualType[i] = Attachment.class;
                } else if (actualType[i].equals(IMultipartBody.class)) {
                    actualType[i] = MultipartBody.class;
                }
            }

            if (actualType != null && origType != null) {
                t = IBMParameterizedTypeImpl.make(origType.getRawType().getClass(), actualType, origType.getOwnerType());
            }
        } else if (IMultipartBody.class.isAssignableFrom(getActualType(t, 0))) {
            t = MultipartBody.class;
        }
        if (IAttachment.class.equals(c)) {
            c = (Class<Object>) (Object) Attachment.class;
        } else if (IMultipartBody.class.equals(c)) {
            c = (Class<Object>) (Object) MultipartBody.class;
        }
        //add additional converting logic since the above converting doesn't work in personal build server.
        if ("com.ibm.websphere.jaxrs20.multipart.IAttachment".equals(c.getName())) {
            c = (Class<Object>) (Object) Attachment.class;
        } else if ("com.ibm.websphere.jaxrs20.multipart.IMultipartBody".equals(c.getName())) {
            c = (Class<Object>) (Object) MultipartBody.class;
        }
        Object object = multipartProvider.readFrom(c, t, anns, mt, headers, is);
        //if object contains Attachment/MultiBoday for CXF, convert to AttachmentImpl, MultipartBodyImpl for IBM
        //List Value type: DataHandler, DataSource, Attachment, only converty Attachment
        if (object instanceof List<?>) {
            List attList = (List) object;
            List<AttachmentImpl> attImplList;
            if (!attList.isEmpty()) {
                attImplList = new LinkedList<AttachmentImpl>();
                AttachmentImpl attImpl;
                for (Object obj : attList) {
                    if (obj != null && obj instanceof Attachment) {
                        attImpl = new AttachmentImpl((Attachment) obj);
                        attImplList.add(attImpl);
                    }
                }
                return attImplList;
            }
            return object;
        }
        //convert Map if contains Attachment, e.g. LinkedHashMap <a.getContentType().toString(),fromAttachment>, fromAttachment== List<>: DataHandler, DataSource, Attachment
        else if (object != null && Map.class.isAssignableFrom(object.getClass())) {
            Map<Object, Object> attMap = (Map) object;
            if (!attMap.isEmpty()) {
                for (Iterator it = attMap.entrySet().iterator(); it.hasNext();) {
                    Entry entrySet = (Entry) it.next();
                    if (entrySet.getValue() != null && List.class.isAssignableFrom(entrySet.getValue().getClass())) {
                        List attList = (List) entrySet.getValue();
                        List<AttachmentImpl> attImplList;
                        if (!attList.isEmpty()) {
                            attImplList = new LinkedList<AttachmentImpl>();
                            AttachmentImpl attImpl;
                            for (Object obj : attList) {
                                if (obj != null && Attachment.class.isAssignableFrom(obj.getClass())) {
                                    attImpl = new AttachmentImpl((Attachment) obj);
                                    attImplList.add(attImpl);
                                }
                            }
                            entrySet.setValue(attImplList);
                        }
                    }
                }
            }
            return attMap;
        }
        //if object is MultipartBody, convert to MultipartBodayImpl
        else if (object instanceof MultipartBody) {
            IMultipartBody imbody = new MultipartBodyImpl((MultipartBody) object);
            return imbody;
        }
        return object;
    }
13719
protected Spec readSpecFromFile(Path path) throws IOException {
    Spec spec;

    try (FSDataInputStream fis = fs.open(path)) {
      spec = this.specSerDe.deserialize(ByteStreams.toByteArray(fis));
    }

    return spec;
  }
1001323
public static JavaRDD<String> listPaths(JavaSparkContext sc, String path) throws IOException {
        return listPaths(sc, path, false);
    }
548086
public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders,
			InputStream entityStream) throws IOException, WebApplicationException {
		String input = null;
		try {
			input = IOUtils.inputStreamToString(entityStream);
		} catch (Exception e) {
			
		}
		if (input == null) {
            return null;
        }
		if (fastJsonConfig.features == null)
			return JSON.parseObject(input, type, fastJsonConfig.parserConfig, JSON.DEFAULT_PARSER_FEATURE);
		else
			return JSON.parseObject(input, type, fastJsonConfig.parserConfig, JSON.DEFAULT_PARSER_FEATURE, fastJsonConfig.features);
	}