I wrapped the 3 lines in a try/catch/finally:
```
                try {
                    writer = new OutputStreamWriter(conn.getOutputStream());
                    writer.write(buf.toString());
                    writer.flush();
                }
                catch (IOException ioe) {
                    Log.e(TAG, "Cannot create OutputStreamWriter with this connection object.");
                    throw ioe;
                }
                finally {
                    IOUtils.closeQuietly(writer);
                }
```