-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
63 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/cz/tomasdvorak/eet/client/utils/IOUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package cz.tomasdvorak.eet.client.utils; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
public class IOUtils { | ||
public static void closeQuietly(final InputStream stream) { | ||
try { | ||
if (stream != null) { | ||
stream.close(); | ||
} | ||
} catch (final IOException ignored) { | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/test/java/cz/tomasdvorak/eet/client/utils/IOUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package cz.tomasdvorak.eet.client.utils; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
public class IOUtilsTest { | ||
|
||
@Test | ||
public void closeQuietly() { | ||
final InputStream is = this.getClass().getResourceAsStream("/keys/README.md"); | ||
IOUtils.closeQuietly(is); | ||
try { | ||
is.read(); | ||
Assert.fail("Should throw an exception"); | ||
} catch (final IOException e) { | ||
Assert.assertEquals("Stream closed", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void closeQuietlyWithNull() { | ||
IOUtils.closeQuietly(null); // should not throw any exceptions! | ||
} | ||
|
||
} |