Deserialize a file to a given object.

@param file
the file to read.
@param adaptee
the class to adapt to.
@return the object.
@throws Exception
421024
public static <T> T deSerializeFromDisk( File file, Class<T> adaptee ) throws Exception {
        try (RandomAccessFile raf = new RandomAccessFile(file, "r")) {
            long length = raf.length();
            // System.out.println(length + "/" + (int) length);
            byte[] bytes = new byte[(int) length];
            int read = raf.read(bytes);
            if (read != length) {
                throw new IOException();
            }
            ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes));
            Object readObject = in.readObject();
            return adaptee.cast(readObject);
        }
    }
1324562
public Value execute(File file) throws Exception
	{
		BufferedReader br = new BufferedReader(new FileReader(file));
		StringBuilder sb = new StringBuilder();

		String line = br.readLine();

		while (line != null)
		{
			sb.append(line);
			line = br.readLine();
		}

		br.close();

		Value result = execute(sb.toString(), null);

		BasicSchedulableThread.terminateAll(); // NB not a session (used for tests)
		return result;
	}
623966
public function parseFile($file)
    {
        $str = @\file_get_contents($file);
        if (false === $str) {
            throw new Exception('Can\'t read file.');
        }

        return $this->parse($str);
    }
42907
public static void serialize(Object object, String file) throws Exception {
        if (object instanceof Serializable) {
            try (FileOutputStream fileOut = new FileOutputStream(file); ObjectOutputStream out =
                    new ObjectOutputStream(fileOut)) {
                out.writeObject(object);
            }
        } else {
            throw new Exception(object.getClass().getName() + " doesn't implements serializable interface");
        }
    }
27009
public static ApplicationConfiguration load(File file) throws Exception {
		try (FileInputStream in = new FileInputStream(file)) {
			return load(in);
		}
	}
550168
public static Object deserialize(String file) throws IOException, ClassNotFoundException {
        Object object;
        try (FileInputStream fileIn = new FileInputStream(file); ObjectInputStream in = new ObjectInputStream(fileIn)) {
            object = in.readObject();
        }
        return object;
    }
718917
public static Reader reader(File file) {
        E.illegalArgumentIfNot(file.canRead(), "file not readable: " + file.getPath());
        try {
            return new FileReader(file);
        } catch (IOException e) {
            throw E.ioException(e);
        }
    }
598138
public static Reader getReader(final File file, String encoding) throws IOException {
        InputStream stream;
        try {
            stream = AccessController.doPrivileged(
                    new PrivilegedExceptionAction<InputStream>() {
                        @Override
                        public InputStream run() throws IOException {
                            return new FileInputStream(file);
                        }
                    }
            );
        } catch (PrivilegedActionException e) {
            throw (IOException)e.getException();
        }

        Reader reader;
        if (encoding != null) {
            reader = new InputStreamReader(stream, encoding);
        } else {
            reader = new InputStreamReader(stream);
        }
        return reader;
    }
1312780
public void serializeToDisk(final File file) throws IOException {
    final DatumWriter datumWriter = new GenericDatumWriter<GenericRecord>();
    final DataFileWriter fileWriter = new DataFileWriter<GenericRecord>(datumWriter);
    final AvroParquetReader<GenericRecord> reader = createAvroReader();
    fileWriter.create(createAvroSchema(), file);

    GenericRecord record = reader.read();
    while (record != null) {
      fileWriter.append(record);
      record = reader.read();
    }

    try {
      reader.close();
    } catch (IOException ex){
      LOG.log(Level.SEVERE, ex.getMessage());
      throw ex;
    }

    try {
      fileWriter.close();
    } catch (IOException ex){
      LOG.log(Level.SEVERE, ex.getMessage());
      throw ex;
    }
  }
328454
AvroMultiRuntimeAppSubmissionParameters fromFile(final File file) throws IOException {
    try (final FileInputStream fileInputStream = new FileInputStream(file)) {
      // This is mainly a test hook.
      return fromInputStream(fileInputStream);
    }
  }
464844
public static FileObject toFileObject(File file) {
        if (file == null) {
            return null;
        }
        try {
            return getFileSystemManager().toFileObject(file);
        } catch (FileSystemException e) {
            throw new IllegalStateException(e);
        }
    }
953937
public void write(File file) throws Exception {
        try {
            FileOutputStream fos = new FileOutputStream(file);
            write(fos);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }
919765
public Engine fromFile(File file) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                new FileInputStream(file), FuzzyLite.UTF_8));
        String line;
        StringBuilder textEngine = new StringBuilder();
        try {
            while ((line = reader.readLine()) != null) {
                textEngine.append(line).append("\n");
            }
        } catch (IOException ex) {
            throw ex;
        } finally {
            reader.close();
        }
        return fromString(textEngine.toString());
    }
765352
public void parse (FileHandle file) {
		try {
			parse(file.reader("UTF-8"));
		} catch (Exception ex) {
			throw new SerializationException("Error parsing file: " + file, ex);
		}
	}
14860
public static <T extends SerializableObject> T deserialize(File file, Class<T> cls) throws IOException {
		FileInputStream stream = null;
		try {
			stream = new FileInputStream(file);
			DataInputStream in = new DataInputStream(stream);

			try {
				Constructor<T> constructor = cls.getDeclaredConstructor(DataInput.class);
				constructor.setAccessible(true);
				return constructor.newInstance(in);
			} catch (Exception e) {
				throw new IOException("Unable to instantiate class: " + cls, e);
			}
		} finally {
			Util.ensureClosed(stream);
		}
	}
60622
@SuppressWarnings("unchecked")
    public <T> T getAttribute( String attrName, Class<T> adaptee ) {
        if (attrName == null) {
            return null;
        }
        if (adaptee == null) {
            adaptee = (Class<T>) String.class;
        }

        Object attribute = feature.getAttribute(attrName);
        if (attribute == null) {
            return null;
        }
        if (attribute instanceof Number) {
            Number num = (Number) attribute;
            if (adaptee.isAssignableFrom(Double.class)) {
                return adaptee.cast(num.doubleValue());
            } else if (adaptee.isAssignableFrom(Float.class)) {
                return adaptee.cast(num.floatValue());
            } else if (adaptee.isAssignableFrom(Integer.class)) {
                return adaptee.cast(num.intValue());
            } else if (adaptee.isAssignableFrom(Long.class)) {
                return adaptee.cast(num.longValue());
            } else if (adaptee.isAssignableFrom(String.class)) {
                return adaptee.cast(num.toString());
            } else {
                throw new IllegalArgumentException();
            }
        } else if (attribute instanceof String) {
            if (adaptee.isAssignableFrom(Double.class)) {
                try {
                    Double parsed = Double.parseDouble((String) attribute);
                    return adaptee.cast(parsed);
                } catch (Exception e) {
                    return null;
                }
            } else if (adaptee.isAssignableFrom(Float.class)) {
                try {
                    Float parsed = Float.parseFloat((String) attribute);
                    return adaptee.cast(parsed);
                } catch (Exception e) {
                    return null;
                }
            } else if (adaptee.isAssignableFrom(Integer.class)) {
                try {
                    Integer parsed = Integer.parseInt((String) attribute);
                    return adaptee.cast(parsed);
                } catch (Exception e) {
                    return null;
                }
            } else if (adaptee.isAssignableFrom(String.class)) {
                return adaptee.cast(attribute);
            } else {
                throw new IllegalArgumentException();
            }
        } else if (attribute instanceof Geometry) {
            return null;
        } else {
            throw new IllegalArgumentException("Can't adapt attribute of type: " + attribute.getClass().getCanonicalName());
        }
    }
169015
@Deprecated
    public static <T> T load(File file, Class<T> configClass) throws Exception {
        Preconditions.checkNotNull(file, "file");
        Preconditions.checkNotNull(configClass, "clazz");
        return new ConfigurationLoader(file.getParentFile()).load(configClass, file.getName());
    }