package de.thedevstack.conversationsplus.utils; import android.net.Uri; import java.io.Closeable; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.net.Socket; import de.thedevstack.conversationsplus.ConversationsPlusApplication; /** * Util to handle streams. */ public final class StreamUtil { /** * Opens an InputStream from Uri using the ContentResolver from application. * @see android.content.ContentResolver#openInputStream(Uri) * @param uri the uri to open * @return the InputStream for given uri * @throws FileNotFoundException if the provided URI could not be opened. */ public static InputStream openInputStreamFromContentResolver(Uri uri) throws FileNotFoundException { return ConversationsPlusApplication.getInstance().getContentResolver().openInputStream(uri); } /** * Closes a stream. * IOException is silently ignored. * @param stream the stream to close */ public static void close(Closeable stream) { if (stream != null) { try { stream.close(); } catch (IOException e) { } } } /** * Closes a socket. * IOException is silently ignored. * @param socket the socket to close */ public static void close(Socket socket) { if (socket != null) { try { socket.close(); } catch (IOException e) { } } } /** * Avoid instantiation of util class. */ private StreamUtil() { // Static helper class } }