/** * @param file file, possibly compressed, to open * @return {@link Reader} on uncompressed contents * @throws IOException if the stream can't be opened or is invalid or can't be read * @see #openMaybeDecompressing(File) */ public static Reader openReaderMaybeDecompressing(File file) throws IOException { return new InputStreamReader(openMaybeDecompressing(file), Charsets.UTF_8); }
/** * @return object of type T that was serialized into the given file */ public static <T extends Serializable> T readObjectFromFile(File f, Class<T> clazz) throws IOException { ObjectInputStream in = new ObjectInputStream(openMaybeDecompressing(f)); try { @SuppressWarnings("unchecked") T result = (T) in.readObject(); return result; } catch (ClassNotFoundException cnfe) { throw new IllegalStateException(cnfe); } finally { in.close(); } }